44 lines
1.0 KiB
JavaScript
Raw Normal View History

'use strict';
2018-06-11 16:55:04 +02:00
const mailgunFactory = require('mailgun-js');
const _ = require('lodash');
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
};
msg = _.pickBy(msg, value => typeof value !== 'undefined');
2019-09-27 16:26:09 +02:00
mailgun.messages().send(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
},
};