I’m using Nodemailer with Gmail for sending emails in my Node.js application. However, I’m having trouble determining the status of emails, particularly when the recipient’s email address is incorrect or the email fails to deliver.
Currently, I’m getting a status of true
for email sending every time, but when I check Gmail, it says “Sorry, email not found”. How can I get the accurate status of email delivery, especially in cases where the recipient email is incorrect or the email fails to deliver?
Here’s my current setup for sending emails:
// Nodemailer setup
const nodemailer = require('nodemailer');
// Create a transporter
let transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
user: '[email protected]',
pass: 'your-password'
}
});
// Email options
let mailOptions = {
from: '[email protected]',
to: '[email protected]',
subject: 'Test Email',
text: 'This is a test email.'
};
// Send email
transporter.sendMail(mailOptions, function(error, info) {
if (error) {
console.log('Email failed to send:', error);
} else {
console.log('Email sent:', info.response);
}
});
How can I modify this setup to accurately detect email delivery status, especially when emails fail to deliver due to incorrect recipient email addresses or other issues?
khem K is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.