Josh Johnston b7fd5f28fd Fix the order of settings in ses provider
Why:

- because there is a default hardcoded value in options.from, the
custom value would never be used.

Signed-off-by: Josh Johnston <josh@x-team.com>
2020-03-24 19:43:13 +11:00

77 lines
1.8 KiB
JavaScript

'use strict';
/**
* Module dependencies
*/
/* eslint-disable prefer-template */
// Public node modules.
const _ = require('lodash');
const nodeSES = require('node-ses');
/* eslint-disable no-unused-vars */
module.exports = {
provider: 'amazon-ses',
name: 'Amazon SES',
auth: {
amazon_ses_default_from: {
label: 'Default From',
type: 'text',
},
amazon_ses_default_replyto: {
label: 'Default Reply-To',
type: 'text',
},
amazon_ses_api_key: {
label: 'Amazon Access key ID',
type: 'text',
},
amazon_ses_secret: {
label: 'Amazon Secret access key',
type: 'text',
},
amazon_ses_endpoint: {
label: 'Amazon end-point uri',
type: 'text',
},
},
init: config => {
var client = nodeSES.createClient({
key: config.amazon_ses_api_key,
secret: config.amazon_ses_secret,
amazon: config.amazon_ses_endpoint,
});
return {
send: options => {
return new Promise((resolve, reject) => {
// Default values.
options = _.isObject(options) ? options : {};
options.from = config.amazon_ses_default_from || options.from;
options.replyTo = config.amazon_ses_default_replyto || options.replyTo;
options.text = options.text || options.html;
options.html = options.html || options.text;
let msg = {
from: options.from,
to: options.to,
replyTo: options.replyTo,
subject: options.subject,
altText: options.text,
message: options.html,
};
client.sendEmail(msg, function(err) {
if (err) {
reject([{ messages: [{ id: 'Auth.form.error.email.invalid' }] }]);
} else {
resolve();
}
});
});
},
};
},
};