Skip to content

Commit

Permalink
fix: πŸ› ses verify, add support for v3 API
Browse files Browse the repository at this point in the history
Add support for the AWS SES v3 API for verying the connection (SES
configuration).

βœ… Closes: #1254
  • Loading branch information
Ognjen Jevremovic authored and andris9 committed Mar 22, 2021
1 parent bf57cf5 commit 6107585
Showing 1 changed file with 24 additions and 16 deletions.
40 changes: 24 additions & 16 deletions lib/ses-transport/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -309,29 +309,37 @@ class SESTransport extends EventEmitter {
*/
verify(callback) {
let promise;
let ses = (this.ses.aws ? this.ses.ses : this.ses) || {};
let aws = this.ses.aws || {};

const sesMessage = {
RawMessage: {
// required
Data: 'From: invalid@invalid\r\nTo: invalid@invalid\r\n Subject: Invalid\r\n\r\nInvalid'
},
Source: 'invalid@invalid',
Destinations: ['invalid@invalid']
};
const cb = err => {
if (err && err.code !== 'InvalidParameterValue') {
return callback(err);
}
return callback(null, true);
};

if (!callback) {
promise = new Promise((resolve, reject) => {
callback = shared.callbackPromise(resolve, reject);
});
}

this.ses.sendRawEmail(
{
RawMessage: {
// required
Data: 'From: invalid@invalid\r\nTo: invalid@invalid\r\n Subject: Invalid\r\n\r\nInvalid'
},
Source: 'invalid@invalid',
Destinations: ['invalid@invalid']
},
err => {
if (err && err.code !== 'InvalidParameterValue') {
return callback(err);
}
return callback(null, true);
}
);
if (typeof ses.send === 'function' && aws.SendRawEmailCommand) {
// v3 API
ses.send(new aws.SendRawEmailCommand(sesMessage), cb);
} else {
// v2 API
ses.sendRawEmail(sesMessage, cb).promise();
}

return promise;
}
Expand Down

0 comments on commit 6107585

Please sign in to comment.