Skip to content

Commit

Permalink
v6.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
andris9 committed Feb 26, 2021
1 parent 87d9b25 commit 91108d7
Show file tree
Hide file tree
Showing 6 changed files with 202 additions and 86 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,11 @@
# CHANGELOG

## 6.5.0 2021-02-26

- Pass through textEncoding to subnodes
- Added support for AWS SES v3 SDK
- Fixed tests

## 6.4.18 2021-02-11

- Updated README
Expand Down
39 changes: 39 additions & 0 deletions examples/ses.js
@@ -0,0 +1,39 @@
'use strict';

let nodemailer = require('nodemailer');
let aws = require('@aws-sdk/client-ses');

process.env.AWS_ACCESS_KEY_ID = '....';
process.env.AWS_SECRET_ACCESS_KEY = '....';

const ses = new aws.SES({
apiVersion: '2010-12-01',
region: 'us-east-1'
});

// create Nodemailer SES transporter
let transporter = nodemailer.createTransport({
SES: { ses, aws }
});

// send some mail
transporter.sendMail(
{
from: 'andris.reinman@gmail.com',
to: 'andris@kreata.ee',
subject: 'Message',
text: 'I hope this message gets sent!',
ses: {
// optional extra arguments for SendRawEmail
Tags: [
{
Name: 'tag_name',
Value: 'tag_value'
}
]
}
},
(err, info) => {
console.log(err || info);
}
);
80 changes: 54 additions & 26 deletions lib/ses-transport/index.js
Expand Up @@ -239,36 +239,64 @@ class SESTransport extends EventEmitter {
sesMessage[key] = mail.data.ses[key];
});

this.ses.sendRawEmail(sesMessage, (err, data) => {
if (err) {
this.logger.error(
{
err,
tnx: 'send'
},
'Send error for %s: %s',
messageId,
err.message
);
statObject.pending = false;
return callback(err);
let ses = (this.ses.aws ? this.ses.ses : this.ses) || {};
let aws = this.ses.aws || {};

let getRegion = cb => {
if (ses.config && typeof ses.config.region === 'function') {
// promise
return ses.config
.region()
.then(region => cb(null, region))
.catch(err => cb(err));
}
return cb(null, (ses.config && ses.config.region) || 'us-east-1');
};

let region = (this.ses.config && this.ses.config.region) || 'us-east-1';
if (region === 'us-east-1') {
region = 'email';
getRegion((err, region) => {
if (err || !region) {
region = 'us-east-1';
}

statObject.pending = false;
callback(null, {
envelope: {
from: envelope.from,
to: envelope.to
},
messageId: '<' + data.MessageId + (!/@/.test(data.MessageId) ? '@' + region + '.amazonses.com' : '') + '>',
response: data.MessageId,
raw
});
let sendPromise;
if (typeof ses.send === 'function' && aws.SendRawEmailCommand) {
// v3 API
sendPromise = ses.send(new aws.SendRawEmailCommand(sesMessage));
} else {
// v2 API
sendPromise = ses.sendRawEmail(sesMessage).promise();
}

sendPromise
.then(data => {
if (region === 'us-east-1') {
region = 'email';
}

statObject.pending = false;
callback(null, {
envelope: {
from: envelope.from,
to: envelope.to
},
messageId: '<' + data.MessageId + (!/@/.test(data.MessageId) ? '@' + region + '.amazonses.com' : '') + '>',
response: data.MessageId,
raw
});
})
.catch(err => {
this.logger.error(
{
err,
tnx: 'send'
},
'Send error for %s: %s',
messageId,
err.message
);
statObject.pending = false;
callback(err);
});
});
})
);
Expand Down
9 changes: 4 additions & 5 deletions package.json
@@ -1,6 +1,6 @@
{
"name": "nodemailer",
"version": "6.4.18",
"version": "6.5.0",
"description": "Easy as cake e-mail sending from your Node.js applications",
"main": "lib/nodemailer.js",
"scripts": {
Expand All @@ -23,15 +23,15 @@
"bunyan": "1.8.15",
"chai": "4.3.0",
"eslint-config-nodemailer": "1.2.0",
"eslint-config-prettier": "7.2.0",
"eslint-config-prettier": "8.1.0",
"grunt": "1.3.0",
"grunt-cli": "1.3.2",
"grunt-eslint": "23.0.0",
"grunt-mocha-test": "0.13.3",
"libbase64": "1.2.1",
"libmime": "5.0.0",
"libqp": "1.1.0",
"mocha": "8.2.1",
"mocha": "8.3.0",
"nodemailer-ntlm-auth": "1.0.1",
"proxy": "1.0.2",
"proxy-test-server": "1.0.0",
Expand All @@ -40,6 +40,5 @@
},
"engines": {
"node": ">=6.0.0"
},
"dependencies": {}
}
}
24 changes: 12 additions & 12 deletions test/fetch/cookies-test.js
Expand Up @@ -251,22 +251,22 @@ describe('Cookie Tests', function () {
value: 'plain'
});

expect(biskviit.parse('SSID=Ap4P….GTEq; Domain=foo.com; Path=/; Expires=Wed, 13 Jan 2021 22:23:01 GMT; Secure; HttpOnly')).to.deep.equal({
expect(biskviit.parse('SSID=Ap4P….GTEq; Domain=foo.com; Path=/; Expires=Wed, 13 Jan 2031 22:23:01 GMT; Secure; HttpOnly')).to.deep.equal({
name: 'ssid',
value: 'Ap4P….GTEq',
domain: '.foo.com',
path: '/',
httponly: true,
secure: true,
expires: new Date('Wed, 13 Jan 2021 22:23:01 GMT')
expires: new Date('Wed, 13 Jan 2031 22:23:01 GMT')
});
});

it('should ignore invalid expire header', function () {
expect(biskviit.parse('theme=plain; Expires=Wed, 13 Jan 2021 22:23:01 GMT')).to.deep.equal({
expect(biskviit.parse('theme=plain; Expires=Wed, 13 Jan 2031 22:23:01 GMT')).to.deep.equal({
name: 'theme',
value: 'plain',
expires: new Date('Wed, 13 Jan 2021 22:23:01 GMT')
expires: new Date('Wed, 13 Jan 2031 22:23:01 GMT')
});

expect(biskviit.parse('theme=plain; Expires=ZZZZZZZZ GMT')).to.deep.equal({
Expand All @@ -286,7 +286,7 @@ describe('Cookie Tests', function () {
path: '/',
httponly: true,
secure: true,
expires: new Date('Wed, 13 Jan 2021 22:23:01 GMT')
expires: new Date('Wed, 13 Jan 2031 22:23:01 GMT')
},
{
name: 'ssid2',
Expand All @@ -304,7 +304,7 @@ describe('Cookie Tests', function () {
path: '/',
httponly: true,
secure: true,
expires: new Date('Wed, 13 Jan 2021 22:23:01 GMT')
expires: new Date('Wed, 13 Jan 2031 22:23:01 GMT')
},
{
name: 'ssid4',
Expand All @@ -313,7 +313,7 @@ describe('Cookie Tests', function () {
path: '/',
httponly: true,
secure: true,
expires: new Date('Wed, 13 Jan 2021 22:23:01 GMT')
expires: new Date('Wed, 13 Jan 2031 22:23:01 GMT')
},
{
name: 'ssid5',
Expand All @@ -322,7 +322,7 @@ describe('Cookie Tests', function () {
path: '/',
httponly: true,
secure: true,
expires: new Date('Wed, 13 Jan 2021 22:23:01 GMT')
expires: new Date('Wed, 13 Jan 2031 22:23:01 GMT')
}
];
});
Expand All @@ -337,7 +337,7 @@ describe('Cookie Tests', function () {
path: '/',
httponly: true,
secure: true,
expires: new Date('Wed, 13 Jan 2021 22:23:01 GMT')
expires: new Date('Wed, 13 Jan 2031 22:23:01 GMT')
},
{
name: 'ssid4',
Expand All @@ -346,7 +346,7 @@ describe('Cookie Tests', function () {
path: '/',
httponly: true,
secure: true,
expires: new Date('Wed, 13 Jan 2021 22:23:01 GMT')
expires: new Date('Wed, 13 Jan 2031 22:23:01 GMT')
}
]);
});
Expand All @@ -364,9 +364,9 @@ describe('Cookie Tests', function () {
// short
biskviit.set('theme=plain', 'https://foo.com/');
// long
biskviit.set('SSID=Ap4P….GTEq; Domain=foo.com; Path=/test; Expires=Wed, 13 Jan 2021 22:23:01 GMT; Secure; HttpOnly', 'https://foo.com/');
biskviit.set('SSID=Ap4P….GTEq; Domain=foo.com; Path=/test; Expires=Wed, 13 Jan 2031 22:23:01 GMT; Secure; HttpOnly', 'https://foo.com/');
// subdomains
biskviit.set('SSID=Ap4P….GTEq; Domain=.foo.com; Path=/; Expires=Wed, 13 Jan 2021 22:23:01 GMT; Secure; HttpOnly', 'https://www.foo.com/');
biskviit.set('SSID=Ap4P….GTEq; Domain=.foo.com; Path=/; Expires=Wed, 13 Jan 2031 22:23:01 GMT; Secure; HttpOnly', 'https://www.foo.com/');
// invalid cors
biskviit.set('invalid_1=cors; domain=example.com', 'https://foo.com/');
biskviit.set('invalid_2=cors; domain=www.foo.com', 'https://foo.com/');
Expand Down

0 comments on commit 91108d7

Please sign in to comment.