可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
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
回答1:
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?
回答2:
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.
回答3:
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.
回答4:
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.
回答5:
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.
回答6:
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.
回答7:
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.
回答8:
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/
回答9:
This link might helps you. This in an experimental jar file which uses RFC 3642 and RFC 3464. It has some basic classes which allows you to get the mail delivery status. And also you'll need Javamail jar file.