-
Notifications
You must be signed in to change notification settings - Fork 1
/
emailer.js
39 lines (34 loc) · 1.2 KB
/
emailer.js
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
const nodemailer = require('nodemailer');
const urlencode = require('urlencode');
const configs = require('./config-manager').getConfiguration();
module.exports = function(to, cc, bcc, subject, body, attachments, callback) {
var transporter = nodemailer.createTransport(
configs.email_server.substring(0, configs.email_server.indexOf("://") + 3)
+ urlencode(configs.email_id)
+ ":"
+ urlencode(configs.password)
+ "@"
+ configs.email_server.substring(configs.email_server.indexOf("://") + 3)
);
var mailOptions = {
from: '"' + configs.sender_name + '" <' + configs.email_id + '>',
to: to,
cc: cc,
bcc: bcc,
subject: subject,
text: body,
html: body
};
if (attachments) {
mailOptions.attachments = [];
attachments.forEach(item => {
mailOptions.attachments.push({
'filename': (item.indexOf("/") > -1 ?
item.substring(item.lastIndexOf("/") + 1)
: item.substring(item.lastIndexOf("\\") + 1)),
'path': item
});
});
}
transporter.sendMail(mailOptions, callback);
}