Skip to content

Commit 22345cf

Browse files
STRMLbajtos
authored andcommitted
Support 'alias' in mail transport config.
Useful if you need to set up multiple transports of the same type. [forward-port of #2489]
1 parent 21ce174 commit 22345cf

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

lib/connectors/mail.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,11 @@ MailConnector.prototype.DataAccessObject = Mailer;
6060
* Example:
6161
*
6262
* Email.setupTransport({
63-
* type: 'SMTP',
63+
* type: "SMTP",
6464
* host: "smtp.gmail.com", // hostname
6565
* secureConnection: true, // use SSL
6666
* port: 465, // port for secure SMTP
67+
* alias: "gmail", // optional alias for use with 'transport' option when sending
6768
* auth: {
6869
* user: "gmail.user@gmail.com",
6970
* pass: "userpass"
@@ -89,7 +90,7 @@ MailConnector.prototype.setupTransport = function(setting) {
8990
transport = mailer.createTransport(transportModule(setting));
9091
}
9192

92-
connector.transportsIndex[setting.type] = transport;
93+
connector.transportsIndex[setting.alias || setting.type] = transport;
9394
connector.transports.push(transport);
9495
};
9596

@@ -128,7 +129,8 @@ MailConnector.prototype.defaultTransport = function() {
128129
* to: "[email protected], [email protected]", // list of receivers
129130
* subject: "Hello ✔", // Subject line
130131
* text: "Hello world ✔", // plaintext body
131-
* html: "<b>Hello world ✔</b>" // html body
132+
* html: "<b>Hello world ✔</b>", // html body
133+
* transport: "gmail", // See 'alias' option above in setupTransport
132134
* }
133135
*
134136
* See https://github.com/andris9/Nodemailer for other supported options.

test/email.test.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@ describe('Email connector', function() {
3737

3838
assert(connector.transportForName('smtp'));
3939
});
40+
41+
it('should set up a aliased transport for SMTP', function() {
42+
var connector = new MailConnector({ transport:
43+
{ type: 'smtp', service: 'ses-us-east-1', alias: 'ses-smtp' },
44+
});
45+
46+
assert(connector.transportForName('ses-smtp'));
47+
});
4048
});
4149

4250
describe('Email and SMTP', function() {

0 commit comments

Comments
 (0)