Fix for email transports

This commit is contained in:
Raymond Feng 2014-07-23 22:09:24 -07:00
parent b503ad3f33
commit ac1428eff5
2 changed files with 35 additions and 4 deletions

View File

@ -59,10 +59,17 @@ MailConnector.prototype.setupTransport = function(setting) {
connector.transports = connector.transports || [];
connector.transportsIndex = connector.transportsIndex || {};
var transportModuleName = 'nodemailer-' + (setting.type || 'STUB').toLowerCase() + '-transport';
var transportModule = require(transportModuleName);
var transport = mailer.createTransport(transportModule(setting));
var transport;
var transportType = (setting.type || 'STUB').toLowerCase();
if (transportType === 'direct') {
transport = mailer.createTransport();
} else if (transportType === 'smtp') {
transport = mailer.createTransport(setting);
} else {
var transportModuleName = 'nodemailer-' + transportType + '-transport';
var transportModule = require(transportModuleName);
transport = mailer.createTransport(transportModule(setting));
}
connector.transportsIndex[setting.type] = transport;
connector.transports.push(transport);

View File

@ -1,6 +1,30 @@
var loopback = require('../');
var MyEmail;
var assert = require('assert');
var MailConnector = require('../lib/connectors/mail');
describe('Email connector', function () {
it('should set up SMTP', function () {
var connector = new MailConnector({transports: [
{type: 'smtp', service: 'gmail'}
]});
assert(connector.transportForName('smtp'));
});
it('should set up DIRECT', function () {
var connector = new MailConnector({transports: [
{type: 'direct', name: 'localhost'}
]});
assert(connector.transportForName('direct'));
});
it('should set up STUB', function () {
var connector = new MailConnector({transports: [
{type: 'stub', service: 'gmail'}
]});
assert(connector.transportForName('stub'));
});
});
describe('Email and SMTP', function () {
beforeEach(function() {