@hemia/email-sender
v0.0.3
Published
Librería de envío de correos compatible con plantillas EJS y MJML, basada en Nodemailer.
Maintainers
Readme
@hemia/email-sender
Una librería ligera y extensible para el envío de correos electrónicos usando Nodemailer, compatible con plantillas EJS y MJML. Soporta múltiples destinatarios, CC, BCC, adjuntos y renderizado dinámico de contenido.
Características
- ✅ Basado en
nodemailer - ✅ Soporte para plantillas HTML (EJS, MJML)
- ✅ Múltiples destinatarios (
to,cc,bcc) - ✅ Adjuntos (
attachments) - ✅ Configuración SMTP flexible
- ✅ Ideal para sistemas de notificación
- ✅ Separación de lógica de renderizado con
TemplateManager
Instalación
npm install @hemia/email-senderUso básico
import { EmailSender } from '@hemia/email-sender';
const emailSender = new EmailSender({
host: 'smtp.example.com',
port: 465,
secure: true,
auth: {
user: '[email protected]',
pass: 'password123'
}
});
await emailSender.sendEmail({
to: '[email protected]',
subject: 'Asunto del correo',
template: 'welcome-template.ejs',
data: { nombre: 'Juan', link: 'https://ejemplo.com' },
app: 'MiApp'
});Uso avanzado con CC, BCC y adjuntos
await emailSender.sendEmail({
to: ['[email protected]', '[email protected]'],
cc: '[email protected]',
bcc: ['[email protected]'],
subject: 'Con adjuntos',
template: 'invoice.ejs',
data: { total: '$99.00' },
attachments: [
{
filename: 'factura.pdf',
path: '/ruta/factura.pdf'
}
]
});Uso con NestJS
Instalación adicional
npm install @hemia/email-sender @nestjs/commonRegistro síncrono
import { EmailModule } from '@hemia/email-sender';
@Module({
imports: [
EmailModule.forRoot({
host: 'smtp.example.com',
port: 587,
secure: false,
auth: {
user: '[email protected]',
pass: 'password123',
},
}),
],
})
export class AppModule {}Registro asíncrono con ConfigService
import { EmailModule } from '@hemia/email-sender';
@Module({
imports: [
EmailModule.forRootAsync({
imports: [ConfigModule],
inject: [ConfigService],
useFactory: (config: ConfigService) => ({
host: config.get('SMTP_HOST'),
port: config.get('SMTP_PORT'),
secure: config.get('SMTP_SECURE'),
auth: {
user: config.get('SMTP_USER'),
pass: config.get('SMTP_PASS'),
},
}),
}),
],
})
export class AppModule {}Envío de correo desde un servicio
import { Injectable } from '@nestjs/common';
import { EmailSenderService } from '@hemia/email-sender';
@Injectable()
export class NotificationsService {
constructor(private readonly emailSender: EmailSenderService) {}
async sendWelcomeEmail(user: User) {
await this.emailSender.sendEmail({
to: user.email,
subject: 'Bienvenido',
template: welcomeTemplate,
data: { name: user.name, link: 'https://ejemplo.com' },
app: 'MiApp',
});
}
}Interfaces disponibles
interface EmailSenderConfig {
host: string;
port: number;
secure: boolean;
auth: {
user: string;
pass: string;
};
}
interface EmailOptions {
to: string | string[];
subject: string;
template: string;
data?: Record<string, any>;
app?: string;
cc?: string | string[];
bcc?: string | string[];
attachments?: {
filename: string;
path?: string;
content?: string | Buffer;
}[];
}Estructura de plantillas
templates/
welcome-template.ejs
reset-password.ejsPuedes personalizar el TemplateManager para soportar MJML, EJS u otros motores de renderizado.
Licencia
MIT — © Hemia Technologies
Desarrollado por Hemia Technologies
