Merge pull request #396 from strongloop/feature/fix-issue-375

Fix for email transports
This commit is contained in:
Raymond Feng 2014-07-24 08:09:18 -07:00
commit 405d04f4ad
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.transports = connector.transports || [];
connector.transportsIndex = connector.transportsIndex || {}; connector.transportsIndex = connector.transportsIndex || {};
var transportModuleName = 'nodemailer-' + (setting.type || 'STUB').toLowerCase() + '-transport'; 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); var transportModule = require(transportModuleName);
transport = mailer.createTransport(transportModule(setting));
var transport = mailer.createTransport(transportModule(setting)); }
connector.transportsIndex[setting.type] = transport; connector.transportsIndex[setting.type] = transport;
connector.transports.push(transport); connector.transports.push(transport);

View File

@ -1,6 +1,30 @@
var loopback = require('../'); var loopback = require('../');
var MyEmail; var MyEmail;
var assert = require('assert'); 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 () { describe('Email and SMTP', function () {
beforeEach(function() { beforeEach(function() {