2018-07-24 10:28:44 +03:00
|
|
|
'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 = {
|
2019-07-02 15:09:59 +02:00
|
|
|
init: config => {
|
2018-07-24 10:28:44 +03:00
|
|
|
var client = nodeSES.createClient({
|
2020-05-14 11:26:19 +02:00
|
|
|
key: config.apiKey,
|
|
|
|
secret: config.secret,
|
|
|
|
amazon: config.endpoint,
|
2018-07-24 10:28:44 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
return {
|
2020-03-21 02:02:47 +13:00
|
|
|
send: options => {
|
2018-07-24 10:28:44 +03:00
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
// Default values.
|
|
|
|
options = _.isObject(options) ? options : {};
|
2020-05-14 11:26:19 +02:00
|
|
|
options.from = options.from || config.defaultFrom;
|
|
|
|
options.replyTo = options.replyTo || config.defaultReplyTo;
|
2018-07-24 10:28:44 +03:00
|
|
|
options.text = options.text || options.html;
|
|
|
|
options.html = options.html || options.text;
|
|
|
|
|
|
|
|
let msg = {
|
|
|
|
from: options.from,
|
|
|
|
to: options.to,
|
2020-05-14 11:26:19 +02:00
|
|
|
cc: options.cc,
|
|
|
|
bcc: options.bcc,
|
2018-07-24 10:28:44 +03:00
|
|
|
replyTo: options.replyTo,
|
|
|
|
subject: options.subject,
|
|
|
|
altText: options.text,
|
2019-07-02 15:09:59 +02:00
|
|
|
message: options.html,
|
2018-07-24 10:28:44 +03:00
|
|
|
};
|
|
|
|
|
2019-07-02 15:09:59 +02:00
|
|
|
client.sendEmail(msg, function(err) {
|
2018-07-24 10:28:44 +03:00
|
|
|
if (err) {
|
|
|
|
reject([{ messages: [{ id: 'Auth.form.error.email.invalid' }] }]);
|
|
|
|
} else {
|
|
|
|
resolve();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2019-07-02 15:09:59 +02:00
|
|
|
},
|
2018-07-24 10:28:44 +03:00
|
|
|
};
|
2019-07-02 15:09:59 +02:00
|
|
|
},
|
2018-07-24 10:28:44 +03:00
|
|
|
};
|