mirror of
https://github.com/wassname/talk.git
synced 2026-07-10 04:51:33 +08:00
37 lines
1.1 KiB
JavaScript
37 lines
1.1 KiB
JavaScript
const nodemailer = require('nodemailer');
|
|
|
|
if (!process.env.TALK_SMTP_CONNECTION_URL) {
|
|
throw new Error('\n///////////////////////////////////////////////////////////////\n' +
|
|
'/// TALK_SMTP_CONNECTION_URL should be defined if you would ///\n' +
|
|
'/// like to send password reset emails from Talk ///\n' +
|
|
'///////////////////////////////////////////////////////////////');
|
|
}
|
|
|
|
const transporter = nodemailer.createTransport(process.env.TALK_SMTP_CONNECTION_URL);
|
|
|
|
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;
|