Fix incorrect transports
This commit is contained in:
parent
80b4482c31
commit
92eaa383f3
|
@ -4,7 +4,8 @@
|
||||||
|
|
||||||
var mailer = require('nodemailer')
|
var mailer = require('nodemailer')
|
||||||
, assert = require('assert')
|
, assert = require('assert')
|
||||||
, debug = require('debug');
|
, debug = require('debug')
|
||||||
|
, STUB = 'STUB';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Export the MailConnector class.
|
* Export the MailConnector class.
|
||||||
|
@ -20,7 +21,7 @@ function MailConnector(settings) {
|
||||||
assert(typeof settings === 'object', 'cannot initiaze MailConnector without a settings object');
|
assert(typeof settings === 'object', 'cannot initiaze MailConnector without a settings object');
|
||||||
var transports = settings.transports || [];
|
var transports = settings.transports || [];
|
||||||
this.transportsIndex = {};
|
this.transportsIndex = {};
|
||||||
this.transports = transports;
|
this.transports = [];
|
||||||
|
|
||||||
transports.forEach(this.setupTransport.bind(this));
|
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`.
|
* Send an email with the given `options`.
|
||||||
*
|
*
|
||||||
|
@ -87,8 +110,11 @@ Mailer.send = function (options, fn) {
|
||||||
var dataSource = this.dataSource;
|
var dataSource = this.dataSource;
|
||||||
var settings = dataSource && dataSource.settings;
|
var settings = dataSource && dataSource.settings;
|
||||||
var connector = dataSource.connector;
|
var connector = dataSource.connector;
|
||||||
var transportsIndex = connector.transportsIndex;
|
var transport = connector.transportForName(options.transport);
|
||||||
var transport = transportsIndex[options.transport || 'SMTP'] || connector.transports[0];
|
|
||||||
|
if(!transport) {
|
||||||
|
transport = connector.defaultTransport();
|
||||||
|
}
|
||||||
|
|
||||||
if(debug.enabled || settings && settings.debug) {
|
if(debug.enabled || settings && settings.debug) {
|
||||||
console.log('Sending Mail:');
|
console.log('Sending Mail:');
|
||||||
|
|
Loading…
Reference in New Issue