41 lines
983 B
JavaScript
Raw Normal View History

'use strict';
2018-06-11 16:55:04 +02:00
const sendgrid = require('@sendgrid/mail');
const _ = require('lodash');
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;
let msg = {
from: from || settings.defaultFrom,
to,
cc,
bcc,
replyTo: replyTo || settings.defaultReplyTo,
subject,
text,
html,
...rest,
2018-06-11 16:55:04 +02:00
};
msg = _.pickBy(msg, value => typeof value !== 'undefined');
sendgrid.send(msg, function(err) {
if (err) {
reject([{ messages: [{ id: 'Auth.form.error.email.invalid' }] }]);
} else {
resolve();
}
2018-06-11 16:55:04 +02:00
});
});
},
};
},
};