salix/print/lib/smtp.js

23 lines
578 B
JavaScript

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}>`;
if (process.env.NODE_ENV !== 'production') {
if (!config.smtp.user)
return Promise.resolve(true);
options.to = config.app.senderMail;
}
return this.transporter.sendMail(options);
}
};