39 lines
889 B
JavaScript
Raw Normal View History

'use strict';
2018-06-11 16:55:04 +02:00
const sendgrid = require('@sendgrid/mail');
2021-04-29 13:51:12 +02:00
const { removeUndefined } = require('@strapi/utils');
2018-06-11 16:55:04 +02:00
module.exports = {
init(providerOptions = {}, settings = {}) {
sendgrid.setApiKey(providerOptions.apiKey);
return {
send(options) {
return new Promise((resolve, reject) => {
const { from, to, cc, bcc, replyTo, subject, text, html, ...rest } = options;
2022-08-08 15:50:34 +02:00
const msg = {
from: from || settings.defaultFrom,
to,
cc,
bcc,
replyTo: replyTo || settings.defaultReplyTo,
subject,
text,
html,
...rest,
2018-06-11 16:55:04 +02:00
};
2022-08-08 23:33:39 +02:00
sendgrid.send(removeUndefined(msg), (err) => {
if (err) {
reject(err);
} else {
resolve();
}
2018-06-11 16:55:04 +02:00
});
});
},
};
},
};