40 lines
964 B
JavaScript
Raw Normal View History

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