1

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

Mahahari
  • 971
  • 1
  • 19
  • 36

1 Answers1

4

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.

Community
  • 1
  • 1
Ulrich Thomas Gabor
  • 6,584
  • 4
  • 27
  • 41
  • i tried sending mail with empty contents , empty subject using nodemailer , i didnt get any error message as response , response showed 250 OK but mail not sent to the intended recipient – Mahahari Mar 25 '14 at 04:03
  • 1
    All these mails are fine and should reach the recipient. Maybe they are in the spam folder? You only get notified about rejected mails, but not about mails which are accepted and then declared as spam. – Ulrich Thomas Gabor Mar 25 '14 at 07:57
  • Yes , you are right. I checked the spam folder. The mail is there in the spam folder. Is it not possible to detect if the mail goes to spam ? – Mahahari Mar 25 '14 at 09:52
  • No, you cannot detect what the receiver does with the mail. In this case the receiver automatically moves it into another folder. It's not possible to track actions like that. – Ulrich Thomas Gabor Mar 25 '14 at 09:55