mirror of
https://github.com/wassname/talk.git
synced 2026-07-04 14:15:23 +08:00
36 lines
889 B
JavaScript
36 lines
889 B
JavaScript
const nodemailer = require('nodemailer');
|
|
const sgTransport = require('nodemailer-sendgrid-transport');
|
|
const options = {
|
|
auth: {
|
|
api_key: process.env.TALK_SENDGRID_APIKEY
|
|
}
|
|
};
|
|
|
|
const transporter = nodemailer.createTransport(sgTransport(options));
|
|
|
|
const mailer = {
|
|
/**
|
|
* sendSimple
|
|
*
|
|
* @param {Object} {from, to, subject, text = '', html = ''}
|
|
* @returns
|
|
*/
|
|
sendSimple ({from, to, subject, text = '', html = ''}) {
|
|
return new Promise((resolve, reject) => {
|
|
if (!from) {
|
|
reject('sendSimple requires a from address');
|
|
}
|
|
if (!to) {
|
|
reject('sendSimple requires a comma-separated list of "to" addresses');
|
|
}
|
|
if (!subject) {
|
|
reject('sendSimple requires a subject for the email');
|
|
}
|
|
|
|
return resolve(transporter.sendMail({from, to, subject, text, html}));
|
|
});
|
|
}
|
|
};
|
|
|
|
module.exports = mailer;
|