File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Other JSE/JEE APIs and the fly likes JavaMail API and Postmaster undeliverable errors Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "JavaMail API and Postmaster undeliverable errors" Watch "JavaMail API and Postmaster undeliverable errors" New topic

JavaMail API and Postmaster undeliverable errors

Michael Cropper
Ranch Hand

Joined: Sep 30, 2009
Posts: 137

I was wondering if there is any kind of standard way to identify a bounced email (ie after sending to an address that doesn't exist)?

I am using JavaMail to read the incoming email, so I have access to all of the data stored - but programatially I am unsure what is the best option to identify these bounced emails.
Do all bounced emails have the "from" set to ""?
Do all bounced emails have the "subject" set to "Delivery Status Notification (Failure)"?

Does anyone know of any standard way to detect these errors?

Since I need to handle these bounces (by flagging them, so I don't keep emailing invalid addresses), I want to make sure that the script I write will catch all of the errors from different mail servers.

Paul Clapham

Joined: Oct 14, 2005
Posts: 19864

Unfortunately the answer to all of those questions is "No".

The script I have for capturing bounce messages has about a dozen different subject lines. And I haven't even attempted to extract the culprit e-mail address from the bounce message; the message formats vary even more widely than the subject lines do.

All you can do is to monitor the bounce messages as they come in, and modify your procedure to handle each different format as you encounter it.

However... there is a new e-mail feature called Delivery Status Notification. Here's a link to the part of the JavaMail API documentation which describes it: It comes with a Warning, and there's no guarantee that servers will send you these things, and so on and so on, but it might be worth experimenting with them.
Michael Cropper
Ranch Hand

Joined: Sep 30, 2009
Posts: 137
I had a feeling that would be the answer

Just thought of an easy way I can do this on my system though...

Simply compare the "from" data in the incoming email, then cross reference this against the list of email addresses within the DB - if there is no match, it is safe to say that the email has bounced.

I can then forward all of the bounced emails content & headers to a certain email address, where I can begin looking at these on a case by case basis to see how I can extract the original "to" from the postmaster delivery failure.

Should keep me busy for a while :-)

It is sorta covered in the JavaRanch Style Guide.
subject: JavaMail API and Postmaster undeliverable errors
It's not a secret anymore!