Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

send e-mail and check status

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?

like image 842
Dónal Avatar asked Sep 29 '08 19:09

Dónal


4 Answers

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?

like image 180
Paul Tomblin Avatar answered Nov 08 '22 19:11

Paul Tomblin


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.

like image 40
Gary Kephart Avatar answered Nov 08 '22 19:11

Gary Kephart


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.

like image 3
Eric Z Beard Avatar answered Nov 08 '22 19:11

Eric Z Beard


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.

like image 1
Thorsten79 Avatar answered Nov 08 '22 19:11

Thorsten79