如何使用 JavaMail API 接收已发送电子邮件的确认?

2022-01-17 00:00:00 email smtp java email-confirmation

我正在编写一个程序,它发送电子邮件并想知道接收者何时收到我发送给他的电子邮件.如何使用 JavaMail API 做到这一点?

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?

如果我使用 SMTPMessage,我设置了通知选项后,具体如何处理结果?

If I use SMTPMessage, how exactly to deal with the result after I've set the notify options?

SMTPMessage smtpMsg = new SMTPMessage(msg);
smtpMsg.setNotifyOptions(SMTPMessage.NOTIFY_SUCCESS);

推荐答案

没有标准的方法可以被广泛接受和尊重.不过,我看到您有一些选择:

There is no standard way of doing this that's accepted and honored across the board. I see that you have some options, though:

  • 在值中添加带有您的电子邮件地址的标题Return-Receipt-To".如果电子邮件的收件人有一个认可此标头的客户,则在打开电子邮件时会向您发送回执.请注意,这并不可靠,因为用户总是可以决定不发送收据,即使他有支持它的客户端.

  • 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.

最终,我认为你必须想出一个创造性的解决方案来解决这个问题,除非你很高兴得到参差不齐的结果.

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.

相关文章