diff --git a/lib/connectors/mail.js b/lib/connectors/mail.js index f6ee201f..4d3dccf3 100644 --- a/lib/connectors/mail.js +++ b/lib/connectors/mail.js @@ -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,9 +110,12 @@ 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:'); if(options.transport) {