23 lines
580 B
JavaScript
23 lines
580 B
JavaScript
const nodemailer = require('nodemailer');
|
|
const config = require('./config');
|
|
|
|
module.exports = {
|
|
init() {
|
|
if (!this.transporter)
|
|
this.transporter = nodemailer.createTransport(config.smtp);
|
|
},
|
|
|
|
send(options) {
|
|
options.from = `${config.app.senderName} <${config.app.senderMail}>`;
|
|
|
|
if (process.env.NODE_ENV !== 'production') {
|
|
if (!config.smtp.auth.user)
|
|
return Promise.resolve(true);
|
|
|
|
options.to = config.app.senderMail;
|
|
}
|
|
|
|
return this.transporter.sendMail(options);
|
|
}
|
|
};
|