diff --git a/lib/connectors/mail.js b/lib/connectors/mail.js index 1e9b346a..3e6e0d39 100644 --- a/lib/connectors/mail.js +++ b/lib/connectors/mail.js @@ -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); diff --git a/test/email.test.js b/test/email.test.js index 325330a0..690ed1c2 100644 --- a/test/email.test.js +++ b/test/email.test.js @@ -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() {