I am trying to implement Nodemailer for sending one or bulk emails but facing trouble to handle when there is a failure in sending email for eg. Email Address not found. I need a list of these bounced emails and other such failures and insert them into the DB,after trying to send the email twice.
Below is my code:
const nodemailer = require("nodemailer");
var smtpConfig = nodemailer.createTransport(
{
host: hostname,
port: port,
secure: false,
auth: {
user: username,
pass: password
},
logger: false,
debug: false
},
{
headers: [],
priority: "normal"
}
);
function sendMailnew() {
const mailOptions = {
from: "email.com,
to: "sjdhf@jhdf.com",
subject: "my testing emails new",
html: "my testing email",
dsn: {
id: "123",
return: "HEADERS",
notify: ["failure", "delay"],
recipient: "abc@gmail.com"
}
};
smtpConfig.sendMail(mailOptions, function(error, response) {
if (error) {
console.log(error);
} else {
console.log("mail sent");
}
});
}
sendMailnew();
I am using gmail SMTP. Please Help.Thanks!Let me know if any more details are needed.