I am using nodemailer and cron Job, I have a function called automationStarts() and inside that function, I am creating a few jobs for example I have created a job which will execute automateTutorSessionReminderBulk() function at 08:00 am and another job which will execute automateTutorHWReminder() function at 08:30 time so the problem is no matter what is the sequence in which these two jobs functions is executing the first function is executing properly(emails are successfully going) but the second function is only showing this in console
[2022-09-05 17:13:32] DEBUG Using 2 plugins for compile
[2022-09-05 17:13:32] DEBUG Sending mail using SMTP (pool)/6.7.5[client:6.7.5]
[2022-09-05 17:13:32] DEBUG Using 2 plugins for compile
[2022-09-05 17:13:32] DEBUG Sending mail using SMTP (pool)/6.7.5[client:6.7.5]
[2022-09-05 17:13:32] DEBUG Using 2 plugins for compile
but not sending emails I am unable to fix this issue any help would be appreciated
this is the code
transporter
let transporter = nodemailer.createTransport({
host: "smtp.office365.com",
port: 587,
secure: false,
auth: {
user: "woooo1@example.com",
pass: "examplepass",
},
logger: true,
tls: {
rejectUnauthorized: false,
},
pool: true,
maxConnections: 1,
maxMessages: 8,
});
auomationStarts function
const automationStarts = () => {
const tutorSessRemindJob = new CronJob(
`00 00 08 * * *`, //8:00 AM
() => {
automateTutorSessionReminderBulk();
},
null,
true,
"Asia/Kolkata"
);
const tutorHWRemindJob1 = new CronJob(
`00 30 08 * * *`, //08:30 AM
() => {
automateTutorHWReminder();
},
null,
true,
"Asia/Kolkata"
);
}
automateTutorSessionReminderBulk function
const automateTutorSessionReminderBulk = () => {
transporter.use(
"compile",
hbs({
viewEngine: {
extname: ".handlebars", // handlebars extension
defaultLayout: false, // name of main template
},
viewPath: "views",
extName: ".handlebars",
})
);
var ResponseData = [];
db.query(`CALL mail_todays_session_tutor()`, function (err, rows) {
if (err) console.log(err);
else {
if (rows[0].length > 0) {
let length = rows[0].length;
rows[0].map((item) => {
db.query(
`CALL send_email_tutor1(?) ; CALL send_email_tutor2(?)`,
[item.tutor_id, item.tutor_id],
function (err1, row1) {
if (err1) console.log(err1);
else {
let mailOptions = {
from: '"Wooooo" woooo1@example.com',
to: "woooo2@example.com",
subject: "woo example email",
text: "Today's emails",
attachments: [
{
filename: "Logo.png",
path: "./Public/images/Logo.png",
cid: "unique@cid",
},
],
template: "tutorSessionReminder",
context: {
Tutor_Name: item.tutor_name,
session1: row1[0],
isActive: row1[2].length > 0 ? true : false,
session2: row1[2],
},
};
transporter.sendMail(mailOptions, (err, data) => {
if (err) {
console.log("eroor occured-----------------", err);
}
ResponseData.push(data);
if (ResponseData.length == length) {
transporter.close();
}
});
}
}
);
//}
});
}
}
});
};
automateTutorHWReminder function
const automateTutorHWReminder = () => {
var ResponseData = [];
transporter.use(
"compile",
hbs({
viewEngine: {
extname: ".handlebars", // handlebars extension
defaultLayout: false,
},
viewPath: "views",
extName: ".handlebars",
})
);
db.query(`CALL hw_upload_reminder()`, function (err, rows) {
if (err) console.log(err);
else {
if (rows[0].length > 0) {
let length = rows[0].length;
rows[0].map((item, index) => {
db.query(
`CALL hw_upload_reminder_level2(?) ;`,
[item.tutor_id],
function (err1, row1) {
row1[0].map((item) => {
console.log(item.session_id);
});
if (err1) console.log(err1);
else {
let mailOptions = {
from: 'woooo1@example.com', // sender address
to: "example@gmail.com",
subject: "example woo emails",
text: "example reminder",
attachments: [
{
filename: "Logo.png",
path: "./Public/images/Logo.png",
cid: "unique@cid",
},
],
template: "tutorHWReminder",
context: {
Tutor_Name: item.tutor_name,
session1: row1[0],
},
};
console.log("yes");
transporter.sendMail(mailOptions, (err, data) => {
if (err) {
//
console.log(err);
}
console.log(data);
ResponseData.push(data);
if (ResponseData.length == length) {
transporter.close();
}
});
}
}
);
});
}
}
});
};