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

Fix incorrect transports
This commit is contained in:
Ritchie Martori 2014-01-13 20:03:25 -08:00
commit 9668692406
1 changed files with 31 additions and 5 deletions

View File

@ -4,7 +4,8 @@
var mailer = require('nodemailer')
, assert = require('assert')
, debug = require('debug');
, debug = require('debug')
, STUB = 'STUB';
/**
* Export the MailConnector class.
@ -20,7 +21,7 @@ function MailConnector(settings) {
assert(typeof settings === 'object', 'cannot initiaze MailConnector without a settings object');
var transports = settings.transports || [];
this.transportsIndex = {};
this.transports = transports;
this.transports = [];
transports.forEach(this.setupTransport.bind(this));
}
@ -64,6 +65,28 @@ function Mailer() {
}
/**
* Get a transport by name.
*
* @param {String} name
* @return {Transport} transport
*/
MailConnector.prototype.transportForName = function(name) {
return this.transportsIndex[name];
}
/**
* Get the default transport.
*
* @return {Transport} transport
*/
MailConnector.prototype.transportForName = function(name) {
return this.transports[0];
}
/**
* Send an email with the given `options`.
*
@ -87,8 +110,11 @@ Mailer.send = function (options, fn) {
var dataSource = this.dataSource;
var settings = dataSource && dataSource.settings;
var connector = dataSource.connector;
var transportsIndex = connector.transportsIndex;
var transport = transportsIndex[options.transport || 'SMTP'] || connector.transports[0];
var transport = connector.transportForName(options.transport);
if(!transport) {
transport = connector.defaultTransport();
}
if(debug.enabled || settings && settings.debug) {
console.log('Sending Mail:');