2018-05-31 14:29:00 -05:00
|
|
|
'use strict';
|
|
|
|
|
2020-05-15 15:05:35 +02:00
|
|
|
const sendmailFactory = require('sendmail');
|
2020-05-15 17:15:24 +02:00
|
|
|
const { removeUndefined } = require('strapi-utils');
|
2018-05-31 14:29:00 -05:00
|
|
|
|
|
|
|
module.exports = {
|
2020-05-15 15:05:35 +02:00
|
|
|
init: (providerOptions = {}, settings = {}) => {
|
|
|
|
const sendmail = sendmailFactory({
|
|
|
|
silent: true,
|
|
|
|
...providerOptions,
|
|
|
|
});
|
2018-05-31 14:29:00 -05:00
|
|
|
return {
|
2020-03-21 02:02:47 +13:00
|
|
|
send: options => {
|
2018-05-31 14:29:00 -05:00
|
|
|
return new Promise((resolve, reject) => {
|
2020-05-15 15:05:35 +02:00
|
|
|
const { from, to, cc, bcc, replyTo, subject, text, html, ...rest } = options;
|
|
|
|
|
2020-05-15 16:22:05 +02:00
|
|
|
let msg = {
|
|
|
|
from: from || settings.defaultFrom,
|
|
|
|
to,
|
|
|
|
cc,
|
|
|
|
bcc,
|
|
|
|
replyTo: replyTo || settings.defaultReplyTo,
|
|
|
|
subject,
|
|
|
|
text,
|
|
|
|
html,
|
|
|
|
...rest,
|
|
|
|
};
|
|
|
|
|
2020-05-15 17:15:24 +02:00
|
|
|
sendmail(removeUndefined(msg), err => {
|
2020-05-15 16:22:05 +02:00
|
|
|
if (err) {
|
|
|
|
reject([{ messages: [{ id: 'Auth.form.error.email.invalid' }] }]);
|
|
|
|
} else {
|
|
|
|
resolve();
|
2018-05-31 14:29:00 -05:00
|
|
|
}
|
2020-05-15 16:22:05 +02:00
|
|
|
});
|
2018-05-31 14:29:00 -05:00
|
|
|
});
|
2019-10-16 00:17:54 +09:00
|
|
|
},
|
2018-05-31 14:29:00 -05:00
|
|
|
};
|
2019-10-16 00:17:54 +09:00
|
|
|
},
|
2018-05-31 14:29:00 -05:00
|
|
|
};
|