mirror of
https://github.com/strapi/strapi.git
synced 2025-07-28 19:34:51 +00:00
39 lines
900 B
JavaScript
39 lines
900 B
JavaScript
'use strict';
|
|
|
|
const sendgrid = require('@sendgrid/mail');
|
|
const { removeUndefined } = require('@strapi/utils');
|
|
|
|
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;
|
|
|
|
let msg = {
|
|
from: from || settings.defaultFrom,
|
|
to,
|
|
cc,
|
|
bcc,
|
|
replyTo: replyTo || settings.defaultReplyTo,
|
|
subject,
|
|
text,
|
|
html,
|
|
...rest,
|
|
};
|
|
|
|
sendgrid.send(removeUndefined(msg), function(err) {
|
|
if (err) {
|
|
reject(err);
|
|
} else {
|
|
resolve();
|
|
}
|
|
});
|
|
});
|
|
},
|
|
};
|
|
},
|
|
};
|