Skip to content

Commit

Permalink
Support 'alias' in mail transport config.
Browse files Browse the repository at this point in the history
Useful if you need to set up multiple transports of the same type.

[forward-port of strongloop#2489]
  • Loading branch information
STRML authored and bajtos committed Aug 16, 2016
1 parent 21ce174 commit 22345cf
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/connectors/mail.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,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"
Expand All @@ -89,7 +90,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);
};

Expand Down Expand Up @@ -128,7 +129,8 @@ MailConnector.prototype.defaultTransport = function() {
* to: "[email protected], [email protected]", // list of receivers
* subject: "Hello ✔", // Subject line
* text: "Hello world ✔", // plaintext body
* html: "<b>Hello world ✔</b>" // html body
* html: "<b>Hello world ✔</b>", // html body
* transport: "gmail", // See 'alias' option above in setupTransport
* }
*
* See https://github.com/andris9/Nodemailer for other supported options.
Expand Down
8 changes: 8 additions & 0 deletions test/email.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,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() {
Expand Down

0 comments on commit 22345cf

Please sign in to comment.