From 8bed218a74e4e0e4200cdbe1864de80d26ed7f80 Mon Sep 17 00:00:00 2001 From: Samuel Reed Date: Tue, 5 Jul 2016 10:47:30 -0500 Subject: [PATCH] Support 'alias' in mail transport config. Useful if you need to set up multiple transports of the same type. --- lib/connectors/mail.js | 8 +++++--- test/email.test.js | 8 ++++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/connectors/mail.js b/lib/connectors/mail.js index 3271c145..8f98f4e7 100644 --- a/lib/connectors/mail.js +++ b/lib/connectors/mail.js @@ -59,10 +59,11 @@ MailConnector.prototype.DataAccessObject = Mailer; * Example: * * Email.setupTransport({ - * type: 'SMTP', + * type: "SMTP", * host: "smtp.gmail.com", // hostname * secureConnection: true, // use SSL * port: 465, // port for secure SMTP + * alias: "gmail", // optional alias for use with 'transport' option when sending * auth: { * user: "gmail.user@gmail.com", * pass: "userpass" @@ -88,7 +89,7 @@ MailConnector.prototype.setupTransport = function(setting) { transport = mailer.createTransport(transportModule(setting)); } - connector.transportsIndex[setting.type] = transport; + connector.transportsIndex[setting.alias || setting.type] = transport; connector.transports.push(transport); }; @@ -127,7 +128,8 @@ MailConnector.prototype.defaultTransport = function() { * to: "bar@blurdybloop.com, baz@blurdybloop.com", // list of receivers * subject: "Hello ✔", // Subject line * text: "Hello world ✔", // plaintext body - * html: "Hello world ✔" // html body + * html: "Hello world ✔", // html body + * transport: "gmail", // See 'alias' option above in setupTransport * } * * See https://github.com/andris9/Nodemailer for other supported options. diff --git a/test/email.test.js b/test/email.test.js index be12a3a6..c1303d8d 100644 --- a/test/email.test.js +++ b/test/email.test.js @@ -38,6 +38,14 @@ describe('Email connector', function() { assert(connector.transportForName('smtp')); }); + it('should set up a aliased transport for SMTP' , function() { + var connector = new MailConnector({transport: + {type: 'smtp', service: 'ses-us-east-1', alias: 'ses-smtp'} + }); + + assert(connector.transportForName('ses-smtp')); + }); + }); describe('Email and SMTP', function() {