2018-07-24 10:28:44 +03:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const nodeSES = require('node-ses');
|
2021-04-29 13:51:12 +02:00
|
|
|
const { removeUndefined } = require('@strapi/utils');
|
2018-07-24 10:28:44 +03:00
|
|
|
|
|
|
|
module.exports = {
|
2021-09-13 12:03:12 +02:00
|
|
|
init(providerOptions = {}, settings = {}) {
|
2022-08-08 15:50:34 +02:00
|
|
|
const client = nodeSES.createClient({ ...providerOptions });
|
2018-07-24 10:28:44 +03:00
|
|
|
|
|
|
|
return {
|
2021-09-13 12:03:12 +02:00
|
|
|
send(options) {
|
2018-07-24 10:28:44 +03: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;
|
2018-07-24 10:28:44 +03:00
|
|
|
|
2022-08-08 15:50:34 +02:00
|
|
|
const msg = {
|
2020-05-15 15:05:35 +02:00
|
|
|
from: from || settings.defaultFrom,
|
|
|
|
to,
|
|
|
|
cc,
|
|
|
|
bcc,
|
|
|
|
replyTo: replyTo || settings.defaultReplyTo,
|
|
|
|
subject,
|
2020-05-28 15:26:13 +05:30
|
|
|
altText: text,
|
|
|
|
message: html,
|
2020-05-15 15:05:35 +02:00
|
|
|
...rest,
|
2018-07-24 10:28:44 +03:00
|
|
|
};
|
2022-08-08 23:33:39 +02:00
|
|
|
client.sendEmail(removeUndefined(msg), (err) => {
|
2018-07-24 10:28:44 +03:00
|
|
|
if (err) {
|
2020-10-07 08:38:18 -04:00
|
|
|
if (err.Message) {
|
2022-08-08 23:33:39 +02:00
|
|
|
// eslint-disable-next-line prefer-promise-reject-errors
|
2020-10-07 08:38:18 -04:00
|
|
|
reject(`${err.Message} ${err.Detail ? err.Detail : ''}`);
|
|
|
|
}
|
2020-06-09 12:11:25 +02:00
|
|
|
reject(err);
|
2018-07-24 10:28:44 +03:00
|
|
|
} else {
|
|
|
|
resolve();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2019-07-02 15:09:59 +02:00
|
|
|
},
|
2018-07-24 10:28:44 +03:00
|
|
|
};
|
2019-07-02 15:09:59 +02:00
|
|
|
},
|
2018-07-24 10:28:44 +03:00
|
|
|
};
|