-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmailer.js
More file actions
65 lines (55 loc) · 1.52 KB
/
mailer.js
File metadata and controls
65 lines (55 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
'use strict';
var argv = require('yargs').argv;
var fs = require('fs');
var path = require('path');
var config = require('confucious');
var enableMailer = true;
if (enableMailer) {
console.log('Emailing enabled.');
var nodemailer = require("nodemailer");
module.exports = {
send: function (msg) {
return new Promise(function (resolve, reject) {
var transport = nodemailer.createTransport({
service: config.get('mail:service'),
host: config.get('mail:host'),
secure: config.get('mail:secure'),
auth: {
user: config.get('mail:username'),
pass: config.get('mail:password'),
},
});
transport.sendMail(
{
to: config.get('mail:to'),
from: config.get('mail:from'),
replyTo: config.get('mail:replyTo'),
subject: config.get('mail:subject') + ' [' + config.get('source') + ']',
text: msg.text,
attachments: msg.attachments || [],
},
function (err, response) {
if (err) {
console.error('Error occured sending email', err);
reject(err);
}
else {
console.log("Message sent: ");
console.log(response);
resolve(response);
}
}
);
})
},
}
}
else {
console.log('Emailing disabled.');
module.exports = {
send: function (msg) {
console.log('Email: ' + msg.text);
return Promise.resolve();
},
}
}