This commit is contained in:
2019-01-12 02:38:31 +01:00
parent da6c642f5a
commit 8095d52da8

View File

@@ -15,12 +15,12 @@ date = new Date(Date.now());
timeString = date.getHours() + "-" + date.getMinutes() + "-" + date.getSeconds();
fileName = "logs\\log " + timeString.toString() + ".txt";
fs.writeFile(fileName, '\r\n', function (err) {
/*fs.writeFile(fileName, '\r\n', function (err) {
if (err) throw err;
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
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 stream = fs.createWriteStream(fileName, {flags:'a'});
//stream.write("Starting....");
// Get Value from JSON
/*students.forEach(s => {
@@ -68,9 +71,18 @@ var stream = fs.createWriteStream(fileName, {flags:'a'});
});*/
function sendToStudent(students, index) {
student = students[index];
stream.write(student);
async function sendToStudent(students, index) {
student = students[index];
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);