Using Java mail, I would like to send an e-mail and check the status. Possible statuses include:
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?
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?
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With