Final Changes

This commit is contained in:
2019-01-12 15:11:57 +01:00
parent 8095d52da8
commit d9ba223a58

View File

@@ -14,6 +14,8 @@ let transporter = nodemailer.createTransport({
date = new Date(Date.now());
timeString = date.getHours() + "-" + date.getMinutes() + "-" + date.getSeconds();
fileName = "logs\\log " + timeString.toString() + ".txt";
emailNb=0;
emailSentNb=0;
/*fs.writeFile(fileName, '\r\n', function (err) {
if (err) throw err;
@@ -38,20 +40,21 @@ async function send(name, email, phone, callback) {
// send mail with defined transport object
let info = await transporter.sendMail(mailOptions);
return info;
stream.write("\r\nlog: "+JSON.stringify(info));
console.log("\r\nlog:",info);
if(info.accepted[0] == email)
{
stream.write("\r\nResult: Email Sent");
console.log("\r\nResult: Email Sent");
emailSentNb++;
}
//console.log("Message sent: ", info);
}
//sleep(1000*60*2);
//send("Abdellah","abdellahaski@gmail.com","0707970909").catch(console.error);
// Preview only available when sending through an Ethereal account
//console.log("Preview URL: %s", nodemailer.getTestMessageUrl(info));
// Get content from file
// Define to JSON type
var contents = JSON.parse(fs.readFileSync("data.json"));
@@ -71,18 +74,23 @@ var stream = fs.createWriteStream(fileName, {flags:'a'});
});*/
emailNb=students.length;
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());
await send(student.name,student.email,student.phone);
stream.write("\r\nSent "+emailSentNb+"/"+emailNb+" email");
console.log("Sent "+emailSentNb+"/"+emailNb+" email");
if(index < students.length-1)
sendToStudent(students,index+1);
}
sendToStudent(students,0);