46 lines
1.1 KiB
JavaScript
Raw Normal View History

'use strict';
/**
* Module dependencies
*/
2018-06-11 16:55:04 +02:00
/* eslint-disable prefer-template */
// Public node modules.
2018-06-11 16:55:04 +02:00
const sendgrid = require('@sendgrid/mail');
/* eslint-disable no-unused-vars */
module.exports = {
init: config => {
sendgrid.setApiKey(config.apiKey);
return {
send: options => {
return new Promise((resolve, reject) => {
let msg = {
from: options.from || config.defaultFrom,
to: options.to,
cc: options.cc,
bcc: options.bcc,
replyTo: options.replyTo || config.defaultReplyTo,
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,
sendAt: options.sendAt,
batchId: options.batchId,
2018-06-11 16:55:04 +02:00
};
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
});
});
},
};
},
};