Question

I am using nodemailer to send mails.

My requirement is to keep track of bounced emails or undelivered emails.

How to do that ? Please help

Was it helpful?

Solution

You cannot do this easily in the current configuration. The mail functions do not return immediately, if a mail was delivered or the recipient is unavailable. The mail is just accepted by the SMTP server and then your script goes on. The SMTP server (in the background and asynchronously) tries to send the mail (likely multiple times) and only if it fails, sends a mail back.

This mail you get back is the one which you are interested in.

The MDA/MTA you use (for example sendmail) should be configured to pass on incoming mails into a script you set up. This way your script gets automatically started, if there come in new mails you are interested in. How to configure your MDA/MTA was already answered.

If this works, you need to "parse" the mail. I think the mail is provided to your script as standard input stream. You can access this one with process.stdin. You must then check the mail for errors, bounces, or whatever you are interested in and can possibly save the status of the recipient in a database.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top