54 lines
1.3 KiB
JavaScript
Raw Normal View History

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 = {
init: config => {
2018-07-24 10:28:44 +03:00
var client = nodeSES.createClient({
key: config.apiKey,
secret: config.secret,
amazon: config.endpoint,
2018-07-24 10:28:44 +03:00
});
return {
send: options => {
2018-07-24 10:28:44 +03:00
return new Promise((resolve, reject) => {
// Default values.
options = _.isObject(options) ? options : {};
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,
cc: options.cc,
bcc: options.bcc,
2018-07-24 10:28:44 +03:00
replyTo: options.replyTo,
subject: options.subject,
altText: options.text,
message: options.html,
2018-07-24 10:28:44 +03: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();
}
});
});
},
2018-07-24 10:28:44 +03:00
};
},
2018-07-24 10:28:44 +03:00
};