@hemia/email-sender
Version:
Librería de envío de correos compatible con plantillas EJS y MJML, basada en Nodemailer.
2 lines (1 loc) • 724 B
JavaScript
import t from"nodemailer";import r from"mjml";import{render as s}from"ejs";class e{static async render(t,e){const a=s(t,e);return r(a).html}}class a{constructor(r,s=e){this.config=r,this.templateManager=s,this.transporter=t.createTransport({host:r.host,port:r.port,secure:r.secure,auth:{user:r.auth.user,pass:r.auth.pass}})}async sendEmail(t){const{to:r,subject:s,template:e,data:a,app:o,cc:c,bcc:n,attachments:i}=t;if(!r||!s||!e)throw new Error("to, subject y template son obligatorios.");const m=await this.templateManager.render(e,a||{}),h={from:`${o||"Hemia"} <${this.config.auth.user}>`,to:r,cc:c,bcc:n,subject:s,html:m,attachments:i};return this.transporter.sendMail(h)}}export{a as EmailSender,e as TemplateManager};