tags:

views:

1509

answers:

9

Hi,

Using Java mail, I would like to send an e-mail and check the status. Possible statuses include:

  • Hard-bounce: No mail server found
  • Soft-bounce: Mail server found, but account not found
  • Success

Is it even possible to send an e-mail and get some feedback about the delivery attempt in the manner I've described above?

EDIT: A respondent suggested looking for a Java library that provides the same functionality as ListNanny. I've searched around, but haven't found anything. Any idea if such a library exists?

Cheers, Don

A: 

Try checking out the RFC's

Nicholas Mancuso
+4  A: 

You can't do this reliably or consistently. What happens if your local mail server passes it onto a corporate out-going mail server, and then it bounces when that server tries to pass it on? What happens if the mail server can't talk to the other mail server and then the message times out after 4 days?

Paul Tomblin
+1  A: 

Finding the mail server and connecting: easy. Checking for an account: possible. But it depends on whether you get access to the mail server in the first place. It may decline your connection attempts (e.g. because your network is blacklisted)

The most complicated thing is what you call "success":

Short answer: No.

Long answer: Theoretically it would be possible, but you would have to wait for hours if not days to know the status. With graylisting, whitelisting, spam-blocking mail servers many will only accept an email after several delivery attempts. You will only know about delivery success when they have finally delivered or given up on the mail. And depending on mail server load the sending of an email may be postponed for an arbitrary amount of time.

Thorsten79
+1  A: 

I'm not famliar specifically w/Javamail, but I would say this: Even "success" may not be success.

You're definition of hard and soft failures should be simple enough to check. If you can't find a server it's hard, if you connet and the server says "mailbox not found" it's "soft". But what if the server accepts the message and then bounces it later? Many front-end servers accept unknown messages, either by design or necessity (front end relay for "real" backend servers) and if the message is later found to be addressed to an invalid address the message is bounced back to the sender. In that case you'll have reported a "success" in sending when it's really not successful.

Ensuring delivery is next to impossible w/out some sort of "click here" embedded in the message.

WaldenL
+3  A: 

What you have to do is set the envelope SMTP sender to an address you monitor for NDR messages. You have to parse the emails as they come in and figure out what went wrong. This is commonly done for mailing lists, and products like ListNanny are used to process the messages (it's a .NET product, but I'm sure there is a Java equivalent, or you could write it yourself).

The envelope "from" is different than the message "from" address. It's part of the SMTP conversation that happens between your code and your MTA. All NDRs will be sent to that address.

Eric Z Beard
ListNanny sounds like exactly what I need. I haven't found an equivalent Java library (yet) though.
Don
It isn't *too* hard to do it yourself, at least at a basic level. If you can find an NDR to look at, you'll find a few semi-standard chunks of data that are easy to parse. Just knowing that you got an NDR is often enough.
Eric Z Beard
I had a quick look into it, and it seems the specific format of an NDR is not standardized, or if it is, there are many non-compliant implementations.
Don
+1  A: 

Don't rely on what you get back (if you get back) info from a server.

Many mail servers are now set up to not indicate whether the receipient exists or not, due the the security hole it creates. (e.g. if a given domain is reporting ("yes"/"no") for the existence of an email address, a hacker would simply unleash a dictionary attack on the server to determine all the valid users, and thus they get an instant spam list.

scunliffe
+2  A: 

If you're sending out HTML email, you might want to embed a 1 pixel transparent image in the email. The image URL would actually reference a servlet that returns the image. The URL would also have some sort of message id as a parameter. The idea behind this is that when the user reads the message, he/she displays the image, which triggers your servlet, which writes to the db that the message had been read.

Gary Kephart
+1  A: 

You can use http://www.mailcounter.info free service to check whether your email has been read as well as how many times it has been read by t he user. Its a free service.

A: 

what you should do is actually check the MX record of the recipient's email (DNS MX query of the domain portion of the email address) and send the message via the SMTP server that is resolved.

this way, if the MX record is not found, you get a "Hard Bounce", if it is found but the send method throws an exception, you get a "Soft Bounce", and if it goes through - you get a "Success".

you can use the dnsjava project to resolve the MX record. http://www.dnsjava.org/

Jay