Merge pull request #136 from strongloop/fix/mail-transports
Fix incorrect transports
This commit is contained in:
commit
9668692406
|
@ -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:');
|
||||
|
|
Loading…
Reference in New Issue