42 lines
1012 B
JavaScript
Raw Normal View History

'use strict';
2018-06-11 16:55:04 +02:00
const mailgunFactory = require('mailgun-js');
const { removeUndefined } = require('strapi-utils');
2018-06-11 16:55:04 +02:00
module.exports = {
init: (providerOptions = {}, settings = {}) => {
const mailgun = mailgunFactory({
2019-09-27 16:26:09 +02:00
mute: false,
...providerOptions,
});
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,
'h:Reply-To': replyTo || settings.defaultReplyTo,
subject,
text,
html,
...rest,
2018-06-11 16:55:04 +02:00
};
mailgun.messages().send(removeUndefined(msg), function(err) {
if (err) {
reject([{ messages: [{ id: 'Auth.form.error.email.invalid' }] }]);
} else {
resolve();
}
2018-06-11 16:55:04 +02:00
});
});
2019-09-27 16:26:09 +02:00
},
};
2019-09-27 16:26:09 +02:00
},
};