asksuite-core
Version:
30 lines (25 loc) • 741 B
JavaScript
module.exports = function(config) {
const obj = {};
obj.sendEmail = function(subject, content, to, replyTo, senderName, trackid) {
const mailgun = require('mailgun-js')({
apiKey: config.MAILGUN_API_KEY,
domain: config.MAILGUN_LOGIN,
});
const msg = {
to: to.replace(/\s/g, '').split(','),
from: senderName ? `${senderName} ${config.EMAIL_FROM}` : config.EMAIL_FROM,
subject: subject,
html: content,
'h:Reply-To': replyTo,
'v:trackid': trackid,
};
mailgun.messages().send(msg, function(error, _body) {
if (error) {
console.error(error.toString());
} else {
console.log('enviou o email com sucesso');
}
});
};
return obj;
};