2017-02-27 04:28:05 +00:00
|
|
|
/* jslint node: true */
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
// ENiGMA½
|
2018-06-21 01:57:06 +00:00
|
|
|
const Config = require('./config.js').get;
|
2017-02-27 04:28:05 +00:00
|
|
|
const Errors = require('./enig_error.js').Errors;
|
|
|
|
const Log = require('./logger.js').log;
|
|
|
|
|
|
|
|
// deps
|
|
|
|
const _ = require('lodash');
|
|
|
|
const nodeMailer = require('nodemailer');
|
|
|
|
|
|
|
|
exports.sendMail = sendMail;
|
|
|
|
|
|
|
|
function sendMail(message, cb) {
|
2018-06-22 05:15:04 +00:00
|
|
|
const config = Config();
|
|
|
|
if(!_.has(config, 'email.transport')) {
|
|
|
|
return cb(Errors.MissingConfig('Email "email::transport" configuration missing'));
|
|
|
|
}
|
2017-02-27 04:28:05 +00:00
|
|
|
|
2018-06-22 05:15:04 +00:00
|
|
|
message.from = message.from || config.email.defaultFrom;
|
2017-02-27 04:28:05 +00:00
|
|
|
|
2018-06-22 05:15:04 +00:00
|
|
|
const transportOptions = Object.assign( {}, config.email.transport, {
|
|
|
|
logger : Log,
|
|
|
|
});
|
2017-02-27 04:28:05 +00:00
|
|
|
|
2018-06-22 05:15:04 +00:00
|
|
|
const transport = nodeMailer.createTransport(transportOptions);
|
2017-02-27 04:28:05 +00:00
|
|
|
|
2018-06-22 05:15:04 +00:00
|
|
|
transport.sendMail(message, (err, info) => {
|
|
|
|
return cb(err, info);
|
|
|
|
});
|
2017-02-27 04:28:05 +00:00
|
|
|
}
|