You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
940 B
JavaScript
37 lines
940 B
JavaScript
const nodemailer = require('nodemailer');
|
|
|
|
const mailerConfig = {
|
|
host: sails.config.custom.mailConnectorHost,
|
|
port: sails.config.custom.mailConnectorPort,
|
|
};
|
|
if (sails.config.custom.mailConnectorUser) {
|
|
Object.assign(mailerConfig, {
|
|
auth: {
|
|
user: sails.config.custom.mailConnectorUser,
|
|
pass: sails.config.custom.mailConnectorPass,
|
|
},
|
|
});
|
|
}
|
|
const transport = nodemailer.createTransport(mailerConfig);
|
|
|
|
const sendEmail = async ({ to, subject, text, cc }) => {
|
|
try {
|
|
await transport.sendMail({
|
|
from: sails.config.custom.mailConnectorEmail,
|
|
to,
|
|
cc,
|
|
subject,
|
|
html: text,
|
|
});
|
|
} catch (e) {
|
|
sails.log(e);
|
|
}
|
|
};
|
|
|
|
const sendUserEmails = async ({ to, subject, text, cc }) => {
|
|
const users = await sails.helpers.users.getMany({ id: { in: to } });
|
|
return sendEmail({ to: users.map((u) => u.email), subject, text, cc });
|
|
};
|
|
|
|
module.exports = { sendEmail, sendUserEmails };
|