UNPKG

ab-helpers

Version:

A collection of helper functions for various tasks

31 lines (26 loc) 642 B
const nodemailer = require("nodemailer"); async function send( { host, port, user, pass }, from, to, subject, html, attachments ) { try { const transporter = nodemailer.createTransport({ host: host, port: port, secure: true, auth: { user, pass }, }); const mailOptions = { from, to, subject, html }; if (attachments) mailOptions.attachments = attachments; const info = await transporter.sendMail(mailOptions); return { result: info }; } catch (error) { console.log("Error occurred:", error.message); return { error: error.message }; } } module.exports = { send };