-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
60 lines (51 loc) · 1.51 KB
/
index.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
const nodemailer = require('nodemailer');
//READ JSON
var fs1 = require('fs'),
fs2 = require('fs'),
obj,
tData
// Read the template - read the JSON
fs2.readFile('/path/to/template','utf8', function (err, data) {
if (err) throw err;
tData = data;
fs1.readFile('/path/to/JSON', handleFile)
});
// Write the callback function
function handleFile(err, data) {
if (err) throw err
obj = JSON.parse(data);
const nodemailer = require('nodemailer');
// create reusable transporter object using the default SMTP transport
let transporter = nodemailer.createTransport({
host: 'smtp.gmail.com',
port: 465,
secure: true, // secure:true for port 465, secure:false for port 587
auth: {
user: '',
pass: ''
}
});
for (var k in obj) {
var shtml = "";
shtml = (tData+"")
.replace(/==pass==/g,obj[k].Password)
.replace(/==name==/g,obj[k].Name);
// setup email data with unicode symbols
let mailOptions = {
from: '', // sender address
to: obj[k].Email, // list of receivers
subject: "Welcome" + (obj[k].Name), // Subject line
html: shtml//.replace(/##pass##/gi,obj[k].Password)//.replace(/##pass##/gi,obj[k].Password) // html body ## = add to HTML placeholder
};
// send mail with defined transport object
transporter.sendMail(mailOptions, (error, info) => {
if (error) {
return console.log(error);
}
console.log('Message %s sent: %s', info.messageId, info.response);
});
// obj[k].Email
// obj[k].Password
// obj[k].Name
}
}