Changes
This commit is contained in:
28
script.js
28
script.js
@@ -15,12 +15,12 @@ date = new Date(Date.now());
|
|||||||
timeString = date.getHours() + "-" + date.getMinutes() + "-" + date.getSeconds();
|
timeString = date.getHours() + "-" + date.getMinutes() + "-" + date.getSeconds();
|
||||||
fileName = "logs\\log " + timeString.toString() + ".txt";
|
fileName = "logs\\log " + timeString.toString() + ".txt";
|
||||||
|
|
||||||
fs.writeFile(fileName, '\r\n', function (err) {
|
/*fs.writeFile(fileName, '\r\n', function (err) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
console.log('It\'s saved!');
|
console.log('It\'s saved!');
|
||||||
}); // => message.txt erased, contains only 'Hello Node'
|
});*/ // => message.txt erased, contains only 'Hello Node'
|
||||||
|
|
||||||
async function send(name, email, phone) {
|
async function send(name, email, phone, callback) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -36,9 +36,11 @@ async function send(name, email, phone) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// send mail with defined transport object
|
// send mail with defined transport object
|
||||||
let info = await transporter.sendMail(mailOptions)
|
let info = await transporter.sendMail(mailOptions);
|
||||||
|
|
||||||
console.log("Message sent: ", info);
|
return info;
|
||||||
|
|
||||||
|
//console.log("Message sent: ", info);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -56,6 +58,7 @@ var contents = JSON.parse(fs.readFileSync("data.json"));
|
|||||||
var students = contents["students"];
|
var students = contents["students"];
|
||||||
|
|
||||||
var stream = fs.createWriteStream(fileName, {flags:'a'});
|
var stream = fs.createWriteStream(fileName, {flags:'a'});
|
||||||
|
//stream.write("Starting....");
|
||||||
// Get Value from JSON
|
// Get Value from JSON
|
||||||
/*students.forEach(s => {
|
/*students.forEach(s => {
|
||||||
|
|
||||||
@@ -68,9 +71,18 @@ var stream = fs.createWriteStream(fileName, {flags:'a'});
|
|||||||
|
|
||||||
});*/
|
});*/
|
||||||
|
|
||||||
function sendToStudent(students, index) {
|
async function sendToStudent(students, index) {
|
||||||
student = students[index];
|
student = students[index];
|
||||||
stream.write(student);
|
stream.write("\r\n------ Student" + index+": " + student.name + "--------------\r\n");
|
||||||
|
console.log("\r\n------ Student" + index+": " + student.name + "--------------\r\n");
|
||||||
|
stream.write("Sending ...\r\n");
|
||||||
|
console.log("Sending ...\r\n");
|
||||||
|
result = await send(student.name,student.email,student.phone);
|
||||||
|
stream.write(result.toString());
|
||||||
|
|
||||||
|
if(index < students.length-1)
|
||||||
|
sendToStudent(students,index+1);
|
||||||
|
|
||||||
}
|
}
|
||||||
sendToStudent(students,0);
|
sendToStudent(students,0);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user