salix/print/lib/smtp.js

23 lines
578 B
JavaScript
Raw Normal View History

2019-01-22 08:55:35 +00:00
const nodemailer = require('nodemailer');
const config = require('./config.js');
module.exports = {
init() {
if (!this.transporter)
this.transporter = nodemailer.createTransport(config.smtp);
},
send(options) {
options.from = `${config.app.senderName} <${config.app.senderMail}>`;
2019-09-30 11:02:11 +00:00
if (process.env.NODE_ENV !== 'production') {
if (!config.smtp.user)
return Promise.resolve(true);
2019-01-22 08:55:35 +00:00
options.to = config.app.senderMail;
2019-09-30 11:02:11 +00:00
}
2019-01-22 08:55:35 +00:00
return this.transporter.sendMail(options);
2019-09-30 11:02:11 +00:00
}
2019-01-22 08:55:35 +00:00
};