如何使用 JavaMail API 收到已发送电子邮件的确认?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3676919/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I recieive confirmation for delivered email with JavaMail API?
提问by brain_damage
I'm writing a program, that sends email messages and want to know when the receiver receives the email message I've sent to him. How can I do this using JavaMail API?
我正在编写一个程序,它发送电子邮件并想知道接收者何时收到我发送给他的电子邮件。我如何使用 JavaMail API 做到这一点?
If I use SMTPMessage, how exactly to deal with the result after I've set the notify options?
如果我使用 SMTPMessage,那么在我设置了通知选项后究竟如何处理结果?
SMTPMessage smtpMsg = new SMTPMessage(msg);
smtpMsg.setNotifyOptions(SMTPMessage.NOTIFY_SUCCESS);
回答by Doon
please see my answer here (when this questioned was asked about ruby on rails). Tis basically the same answer.
请在此处查看我的回答(当有人询问有关 ruby on rails 的问题时)。这基本上是相同的答案。
回答by Erick Robertson
There is no standard way of doing this that's accepted and honored across the board. I see that you have some options, though:
没有任何标准的方法可以被广泛接受和尊重。不过,我看到您有一些选择:
Add a header "Return-Receipt-To" with your e-mail address in the value. If the recipient of the e-mail has a client which honors this header, then a return receipt will be sent to you when the e-mail is opened. This is not reliable, mind you, as the user can always decide not to send the receipt, even if he has a client that supports it.
Add an image into your e-mail that loads from your server and put a parameter on the image that includes the user's e-mail address. When the e-mail loads, the image will load from your server. Write a script that collects the e-mail parameter and then delivers a blank image. This is also not reliable, however, as many mail clients prompt users if they wish to download images and they can always choose not to. Also, some (mostly older) e-mail clients do not support images.
Perhaps the most reliable way is not to include the message in your e-mail at all. Include only a link to a website where the message can be read, and include their e-mail address or a unique code in the link. This way, you know exactly who read the message. Of course, this has the downside that people aren't actually getting the message in their inbox, and they also may choose not to go to the website to read it.
在值中添加带有您的电子邮件地址的标题“Return-Receipt-To”。如果电子邮件的收件人有一个接受此标题的客户端,则在打开电子邮件时将向您发送回执。请注意,这是不可靠的,因为用户总是可以决定不发送收据,即使他有支持它的客户。
将图像添加到从服务器加载的电子邮件中,并在包含用户电子邮件地址的图像上放置一个参数。当电子邮件加载时,图像将从您的服务器加载。编写一个脚本来收集电子邮件参数,然后传送一个空白图像。然而,这也不可靠,因为许多邮件客户端会提示用户是否希望下载图像,而他们始终可以选择不下载。此外,某些(主要是较旧的)电子邮件客户端不支持图像。
也许最可靠的方法是根本不将消息包含在您的电子邮件中。仅包含指向可以阅读消息的网站的链接,并在链接中包含他们的电子邮件地址或唯一代码。这样,您就可以确切地知道谁阅读了消息。当然,这样做的缺点是人们实际上并没有在收件箱中收到邮件,而且他们也可能选择不去网站阅读。
Ultimately, I think you're going to have to come up with a creative solution to solve this problem, unless you're happy getting spotty results.
最终,我认为你将不得不想出一个创造性的解决方案来解决这个问题,除非你很高兴得到参差不齐的结果。
回答by oyo
You can use SMTP message and request for a delivery status (I don't know if it's coming when the provider receive the mail or if it's when the user open the mail). JavaMail don't support directly these feature directly and you have to read the RFC 3464. I also find this thread with examples but didn't try it javamail
您可以使用 SMTP 消息并请求传递状态(我不知道它是在提供商收到邮件时还是在用户打开邮件时到来)。JavaMail 不直接直接支持这些功能,您必须阅读 RFC 3464。我也找到了带有示例的线程,但没有尝试javamail
You can also look at websina
你也可以看看websina
回答by ice.cube
There is another approach to finding out whether an email has been received or not, it's getting undelivered emails. I've seen a rather good Java implementation here.
还有另一种方法可以确定是否收到了电子邮件,即收到未送达的电子邮件。我见过一个相当不错的Java实现这里。
They used javax.mail (for mail processing) and guava (for processing strings and collections).
他们使用 javax.mail(用于邮件处理)和 guava(用于处理字符串和集合)。
回答by Jordi Castilla
Ok, this is an old discussion, but:
好的,这是一个古老的讨论,但是:
I've found a simple and working solution here(link in spanish).
我发现一个简单的工作液在这里(在西班牙语中的链接)。
You just need to add one more field to the header of the message. To achieve this you must use method addHeader
of Part
class, implemented by Message
class. This method receives 2 parameters, type
and value
of header.
您只需要在消息的标题中再添加一个字段。要做到这一点,你必须使用方法addHeader
的Part
类,以实现Message
类。此方法接收 2 个参数,type
以及value
header。
To get confirmation you must add this header:
要获得确认,您必须添加此标题:
Disposition-Notification-To
And the value
is the mail where we want to send the confirmation answer:
这value
是我们要发送确认答案的邮件:
message.addHeader("Disposition-Notification-To","[email protected]");
ATTENTION:be aware that, nowadays, a lot of mail servers like gmail are discarding this requests, so this will not have effect, but, if you are sure (like me) receiver server allows this, will work like a charm.
注意:请注意,如今,像 gmail 这样的许多邮件服务器都丢弃了此请求,因此这不会产生任何影响,但是,如果您确定(像我一样)接收器服务器允许这样做,它将像魅力一样工作。
回答by Ishaan
Just add a dummy image with display set to none in your message.And set the src attribute of this image to the url you want to call
只需在您的消息中添加一个显示设置为 none 的虚拟图像。并将此图像的 src 属性设置为您要调用的 url