Merge pull request #130 from strongloop/fix/mail-transports

Fix/mail transports
This commit is contained in:
Ritchie Martori 2014-01-13 18:36:42 -08:00
commit 45e5641055
1 changed files with 16 additions and 5 deletions

View File

@ -3,7 +3,8 @@
*/
var mailer = require('nodemailer')
, assert = require('assert');
, assert = require('assert')
, debug = require('debug');
/**
* Export the MailConnector class.
@ -18,7 +19,9 @@ module.exports = MailConnector;
function MailConnector(settings) {
assert(typeof settings === 'object', 'cannot initiaze MailConnector without a settings object');
var transports = settings.transports || [];
this.transportsIndex = {};
this.transports = transports;
transports.forEach(this.setupTransport.bind(this));
}
@ -86,9 +89,8 @@ Mailer.send = function (options, fn) {
var connector = dataSource.connector;
var transportsIndex = connector.transportsIndex;
var transport = transportsIndex[options.transport || 'SMTP'] || connector.transports[0];
assert(transport, 'You must supply an Email.settings.transports array containing at least one transport');
if(settings && settings.debug) {
if(debug.enabled || settings && settings.debug) {
console.log('Sending Mail:');
if(options.transport) {
console.log('\t TRANSPORT:', options.transport);
@ -100,7 +102,16 @@ Mailer.send = function (options, fn) {
console.log('\t HTML:', options.html);
}
transport.sendMail(options, fn);
if(transport) {
assert(transport.sendMail, 'You must supply an Email.settings.transports containing a valid transport');
transport.sendMail(options, fn);
} else {
console.warn('Warning: No email transport specified for sending email.'
+ ' Setup a transport to send mail messages.');
process.nextTick(function() {
fn(null, options);
});
}
}
/**