multiple-email-service
Version:
It's helps developer to use multiple email service from this package.
32 lines (26 loc) • 1.03 kB
JavaScript
const nodemailer = require("nodemailer");
exports.sendEmail = async (emailParams) => {
// let testAccount = await nodemailer.createTestAccount(); // create reusable transporter object using the default SMTP transport
let transporter = nodemailer.createTransport({
host: emailParams.transporterHost,
port: emailParams.transporterPort,
auth: {
user: emailParams.transporterEmail,
pass: emailParams.transporterPassword
}
}); // send mail with defined transport object
let info = await transporter.sendMail({
from: emailParams.from,
// sender address
to: emailParams.to,
// list of receivers
subject: emailParams.subject,
// Subject line
text: emailParams.body,
// plain text body
html: emailParams.htmlContent // html body
});
console.log("Message sent: %s", info.messageId, info.from); // Message sent: <b658f8ca-6296-ccf4-8306-87d57a0b4321@example.com>
// console.log("Preview URL: %s", nodemailer.getTestMessageUrl(info));
return info
}