UNPKG

@trap_stevo/legendarybuilderpronodejs-utilities

Version:

The legendary computational utility API that makes your application a legendary application. ~ Created by Steven Compton

87 lines (55 loc) 1.56 kB
/* Created by Hassan Steven Compton. March 2, 2024. */ const bodyParser = require("body-parser"); function sendEmailWithPDF(transporter, subject, message, senderEmail, recipientEmail, contentHTML, contentName, pdfContent) { var pdfFileData = null; if (pdfContent) { pdfFileData = Buffer.from(pdfContent, 'base64'); } const mailOptions = { from : senderEmail, to : recipientEmail, subject : subject, text : message, html : contentHTML ? contentHTML : null, attachments : pdfFileData ? [ { filename : contentName, content : pdfFileData, contentType : "application/pdf", } ] : null }; transporter.sendMail(mailOptions, (error, info) => { if (error) { return console.error(error); } console.log("Email sent: ", info.response); }); } function sendEmails(transporter, subject, senderEmail, recipientEmails, contentHTML) { const mailOptions = { from : senderEmail, to : "", bcc : recipientEmails.join(", "), subject : subject, html : contentHTML ? contentHTML : null, }; transporter.sendMail(mailOptions, (error, info) => { if (error) { return console.error(error); } console.log("Email sent: ", info.response); }); } module.exports = { sendEmailWithPDF, sendEmails };