diff --git a/lib/connectors/mail.js b/lib/connectors/mail.js index 1cdec0e5..cb260c72 100644 --- a/lib/connectors/mail.js +++ b/lib/connectors/mail.js @@ -22,7 +22,7 @@ function MailConnector(settings) { var transports = settings.transports || []; this.transportsIndex = {}; this.transports = []; - + transports.forEach(this.setupTransport.bind(this)); } @@ -83,10 +83,9 @@ MailConnector.prototype.transportForName = function(name) { */ MailConnector.prototype.defaultTransport = function() { - return this.transports[0]; + return this.transports[0] || this.stubTransport; } - /** * Send an email with the given `options`. * @@ -110,6 +109,8 @@ Mailer.send = function (options, fn) { var dataSource = this.dataSource; var settings = dataSource && dataSource.settings; var connector = dataSource.connector; + assert(connector, 'Cannot send mail without a connector!'); + var transport = connector.transportForName(options.transport); if(!transport) { diff --git a/test/email.test.js b/test/email.test.js index 91ff7650..9a23ecb8 100644 --- a/test/email.test.js +++ b/test/email.test.js @@ -1,9 +1,13 @@ var loopback = require('../'); -var MyEmail = loopback.Email.extend('my-email'); +var MyEmail; var assert = require('assert'); describe('Email and SMTP', function () { - + beforeEach(function() { + MyEmail = loopback.Email.extend('my-email'); + loopback.autoAttach(); + }); + it('should have a send method', function () { assert(typeof MyEmail.send === 'function'); assert(typeof MyEmail.prototype.send === 'function');