I am sending mails using nodemailer. I need to know if the mail is sent or not and then update my database but the mail is sent in the transporter(which I do not think returns promises) which takes time and hence the return is always false, even if the mail is sent.
This is my mail sending file which I call from other routes
// mail_file.js
// imports
sendmail = async (req) => {
let transporter = nodemailer.createTransport({
// settings
});
var mailOptions = {
// mailoptions
};
let resp = false;
await transporter.sendMail(mailOptions, function (error, info) {
if (error) {
console.log('error is ' + error);
resp = false;
} else {
console.log('Email sent: ' + info.response);
resp = true;
}
});
return resp;
};
module.exports = sendmail;
When I log the info of the mail, it is after the logging of the response of the sendmail function in the somepath.js