2018-05-02 12:28:27 +02:00

42 lines
1.1 KiB
JavaScript

'use strict';
/**
* Email.js service
*
* @description: A set of functions similar to controller's actions to avoid code duplication.
*/
const _ = require('lodash');
const sendmail = require('sendmail')({
silent: true
});
module.exports = {
send: (options, cb) => { // eslint-disable-line no-unused-vars
return new Promise((resolve, reject) => {
// Default values.
options = _.isObject(options) ? options : {};
options.from = options.from || '"Administration Panel" <no-reply@strapi.io>';
options.replyTo = options.replyTo || '"Administration Panel" <no-reply@strapi.io>';
options.text = options.text || options.html;
options.html = options.html || options.text;
// Send the email.
sendmail({
from: options.from,
to: options.to,
replyTo: options.replyTo,
subject: options.subject,
text: options.text,
html: options.html
}, function (err) {
if (err) {
reject([{ messages: [{ id: 'Auth.form.error.email.invalid' }] }]);
} else {
resolve();
}
});
});
}
};