2018-05-31 14:29:00 -05:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Module dependencies
|
|
|
|
*/
|
|
|
|
|
2018-06-11 16:55:04 +02:00
|
|
|
/* eslint-disable prefer-template */
|
2018-05-31 14:29:00 -05:00
|
|
|
// Public node modules.
|
2018-06-11 16:55:04 +02:00
|
|
|
const sendgrid = require('@sendgrid/mail');
|
|
|
|
|
2018-05-31 14:29:00 -05:00
|
|
|
/* eslint-disable no-unused-vars */
|
|
|
|
module.exports = {
|
2019-07-02 15:09:59 +02:00
|
|
|
init: config => {
|
2020-05-14 11:26:19 +02:00
|
|
|
sendgrid.setApiKey(config.apiKey);
|
2018-05-31 14:29:00 -05:00
|
|
|
|
|
|
|
return {
|
2020-03-21 02:02:47 +13:00
|
|
|
send: options => {
|
2018-05-31 14:29:00 -05:00
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
let msg = {
|
2020-05-14 11:26:19 +02:00
|
|
|
from: options.from || config.defaultFrom,
|
2018-05-31 14:29:00 -05:00
|
|
|
to: options.to,
|
2020-05-14 11:26:19 +02:00
|
|
|
cc: options.cc,
|
|
|
|
bcc: options.bcc,
|
|
|
|
replyTo: options.replyTo || config.defaultReplyTo,
|
2018-05-31 14:29:00 -05:00
|
|
|
subject: options.subject,
|
|
|
|
text: options.text,
|
2019-04-01 15:38:10 +07:00
|
|
|
html: options.html,
|
|
|
|
templateId: options.templateId,
|
|
|
|
dynamic_template_data: options.dynamic_template_data,
|
2020-01-17 23:02:51 -05:00
|
|
|
sendAt: options.sendAt,
|
|
|
|
batchId: options.batchId,
|
2018-06-11 16:55:04 +02:00
|
|
|
};
|
2018-05-31 14:29:00 -05:00
|
|
|
|
2019-07-02 15:09:59 +02:00
|
|
|
sendgrid.send(msg, function(err) {
|
2018-05-31 14:29:00 -05:00
|
|
|
if (err) {
|
|
|
|
reject([{ messages: [{ id: 'Auth.form.error.email.invalid' }] }]);
|
|
|
|
} else {
|
|
|
|
resolve();
|
|
|
|
}
|
2018-06-11 16:55:04 +02:00
|
|
|
});
|
2018-05-31 14:29:00 -05:00
|
|
|
});
|
2019-07-02 15:09:59 +02:00
|
|
|
},
|
2018-05-31 14:29:00 -05:00
|
|
|
};
|
2019-07-02 15:09:59 +02:00
|
|
|
},
|
2018-05-31 14:29:00 -05:00
|
|
|
};
|