2018-05-31 14:29:00 -05:00
|
|
|
'use strict';
|
|
|
|
|
2020-05-15 15:05:35 +02:00
|
|
|
const sendmailFactory = require('sendmail');
|
2021-04-29 13:51:12 +02:00
|
|
|
const { removeUndefined } = require('@strapi/utils');
|
2018-05-31 14:29:00 -05:00
|
|
|
|
|
|
|
module.exports = {
|
2021-09-13 12:03:12 +02:00
|
|
|
init(providerOptions = {}, settings = {}) {
|
2020-05-15 15:05:35 +02:00
|
|
|
const sendmail = sendmailFactory({
|
|
|
|
silent: true,
|
|
|
|
...providerOptions,
|
|
|
|
});
|
2018-05-31 14:29:00 -05:00
|
|
|
return {
|
2021-09-13 12:03:12 +02: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;
|
|
|
|
|
2022-08-08 15:50:34 +02:00
|
|
|
const msg = {
|
2020-05-15 16:22:05 +02:00
|
|
|
from: from || settings.defaultFrom,
|
|
|
|
to,
|
|
|
|
cc,
|
|
|
|
bcc,
|
|
|
|
replyTo: replyTo || settings.defaultReplyTo,
|
|
|
|
subject,
|
|
|
|
text,
|
|
|
|
html,
|
|
|
|
...rest,
|
|
|
|
};
|
|
|
|
|
2022-08-08 23:33:39 +02:00
|
|
|
sendmail(removeUndefined(msg), (err) => {
|
2020-05-15 16:22:05 +02:00
|
|
|
if (err) {
|
2020-06-09 12:11:25 +02:00
|
|
|
reject(err);
|
2020-05-15 16:22:05 +02:00
|
|
|
} 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
|
|
|
};
|