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 : {};
|
2017-12-05 12:10:08 +01:00
|
|
|
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
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|