Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
/**
* Mailer service to handle email sending
* @module service/mailer
*/
import nodemailer from "nodemailer";
/**
* Sends an email
* @param {Array} recipients email addresses of recipients
* @param {String} subject email subject
* @param {String} bodyHtml email body
* @returns {Object} status of the email
*/
const mailTo = async (recipients, { subject, bodyHtml }) => {
const transporter = nodemailer.createTransport({
host: "mail.privateemail.com",
port: 465,
auth: {
user: process.env.MAILER_USER,
pass: process.env.MAILER_PASSWORD,
},
});
const data = {
from: process.env.MAILER_USER,
to: recipients,
subject: subject,
html: bodyHtml,
};
return await sendEmail(transporter, data);
};
/**
* Wrapper for sending emails that returns a promise
* @param {Object} transporter Nodemailer transporter object
* @param {Object} data data to be send
*/
const sendEmail = async (transporter, data) =>
new Promise((resolve, reject) => {
transporter.sendMail(data, (err, info) => {
if (err) reject(err);
console.log('Sending email: ', info)
resolve(info);
});
});
export default mailTo;