1 | module.exports = function(config) {
|
2 | const obj = {};
|
3 |
|
4 | obj.sendEmail = function(subject, content, to, replyTo, senderName, trackid) {
|
5 | const mailgun = require('mailgun-js')({
|
6 | apiKey: config.MAILGUN_API_KEY,
|
7 | domain: config.MAILGUN_LOGIN,
|
8 | });
|
9 |
|
10 | const msg = {
|
11 | to: to.replace(/\s/g, '').split(','),
|
12 | from: senderName ? `${senderName} ${config.EMAIL_FROM}` : config.EMAIL_FROM,
|
13 | subject: subject,
|
14 | html: content,
|
15 | 'h:Reply-To': replyTo,
|
16 | 'v:trackid': trackid,
|
17 | };
|
18 |
|
19 | mailgun.messages().send(msg, function(error, _body) {
|
20 | if (error) {
|
21 | console.error(error.toString());
|
22 | } else {
|
23 | console.log('enviou o email com sucesso');
|
24 | }
|
25 | });
|
26 | };
|
27 |
|
28 | return obj;
|
29 | };
|