UNPKG

@hemia/email-sender

Version:

Librería de envío de correos compatible con plantillas EJS y MJML, basada en Nodemailer.

2 lines (1 loc) 731 B
"use strict";var t=require("nodemailer"),e=require("mjml"),r=require("ejs");class s{static async render(t,s){const a=r.render(t,s);return e(a).html}}exports.EmailSender=class{constructor(e,r=s){this.config=e,this.templateManager=r,this.transporter=t.createTransport({host:e.host,port:e.port,secure:e.secure,auth:{user:e.auth.user,pass:e.auth.pass}})}async sendEmail(t){const{to:e,subject:r,template:s,data:a,app:c,cc:n,bcc:o,attachments:i}=t;if(!e||!r||!s)throw new Error("to, subject y template son obligatorios.");const u=await this.templateManager.render(s,a||{}),h={from:`${c||"Hemia"} <${this.config.auth.user}>`,to:e,cc:n,bcc:o,subject:r,html:u,attachments:i};return this.transporter.sendMail(h)}},exports.TemplateManager=s;