Final Changes
This commit is contained in:
26
script.js
26
script.js
@@ -14,6 +14,8 @@ let transporter = nodemailer.createTransport({
|
|||||||
date = new Date(Date.now());
|
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";
|
||||||
|
emailNb=0;
|
||||||
|
emailSentNb=0;
|
||||||
|
|
||||||
/*fs.writeFile(fileName, '\r\n', function (err) {
|
/*fs.writeFile(fileName, '\r\n', function (err) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
@@ -38,18 +40,19 @@ async function send(name, email, phone, callback) {
|
|||||||
// send mail with defined transport object
|
// send mail with defined transport object
|
||||||
let info = await transporter.sendMail(mailOptions);
|
let info = await transporter.sendMail(mailOptions);
|
||||||
|
|
||||||
return info;
|
stream.write("\r\nlog: "+JSON.stringify(info));
|
||||||
|
console.log("\r\nlog:",info);
|
||||||
//console.log("Message sent: ", info);
|
|
||||||
|
|
||||||
|
if(info.accepted[0] == email)
|
||||||
|
{
|
||||||
|
stream.write("\r\nResult: Email Sent");
|
||||||
|
console.log("\r\nResult: Email Sent");
|
||||||
|
emailSentNb++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//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
|
// Get content from file
|
||||||
@@ -71,18 +74,23 @@ var stream = fs.createWriteStream(fileName, {flags:'a'});
|
|||||||
|
|
||||||
});*/
|
});*/
|
||||||
|
|
||||||
|
emailNb=students.length;
|
||||||
async function sendToStudent(students, index) {
|
async function sendToStudent(students, index) {
|
||||||
student = students[index];
|
student = students[index];
|
||||||
stream.write("\r\n------ Student" + index+": " + student.name + "--------------\r\n");
|
stream.write("\r\n------ Student" + index+": " + student.name + "--------------\r\n");
|
||||||
console.log("\r\n------ Student" + index+": " + student.name + "--------------\r\n");
|
console.log("\r\n------ Student" + index+": " + student.name + "--------------\r\n");
|
||||||
stream.write("Sending ...\r\n");
|
stream.write("Sending ...\r\n");
|
||||||
console.log("Sending ...\r\n");
|
console.log("Sending ...\r\n");
|
||||||
result = await send(student.name,student.email,student.phone);
|
await send(student.name,student.email,student.phone);
|
||||||
stream.write(result.toString());
|
stream.write("\r\nSent "+emailSentNb+"/"+emailNb+" email");
|
||||||
|
console.log("Sent "+emailSentNb+"/"+emailNb+" email");
|
||||||
|
|
||||||
if(index < students.length-1)
|
if(index < students.length-1)
|
||||||
sendToStudent(students,index+1);
|
sendToStudent(students,index+1);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
sendToStudent(students,0);
|
sendToStudent(students,0);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user