如何使用JavaMail将Return-Path设置为发送方地址以外的电子邮件地址? [英] How to set the Return-Path to an email address other than Sender address using JavaMail?

查看:813
本文介绍了如何使用JavaMail将Return-Path设置为发送方地址以外的电子邮件地址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

解决方案

下面的代码是你想要什么,并以正确的方式。重新记录你自己在评论中发布的内容


From: RFC2821:4.4跟踪信息



当传送SMTP服务器使
成为最终传递消息,它
在邮件数据的
开头插入返回路径行。这是使用
的返回路径是必需的; mail
系统必须支持它。
返回路径行在MAIL命令的
中保留
信息。这里,最终
的传送意味着邮件已经离开
SMTP环境。通常,这个
意味着它已经交付给
目标用户或相关的
邮件丢弃,但在某些情况下,它可能是
进一步处理和传输$ b $另一个邮件系统。


和几行后。


一个消息来源的SMTP系统
不应该发送已经
包含一个返回路径头的消息。


如果仔细阅读,您将会明白,只有最终的smtp-server / delivery代理应该添加 Return-Path 头。这不是你作为客户端(试图发送邮件)应该做的事情。最终的smtp服务器将基于信封的发件人地址( SMTP邮件从部分)的返回路径头)



所以设置 mail.smtp.from 是告诉java的信封发件人地址应该是正确的方法不同于部分的



如果您有麻烦,了解不同的 只是看一个telnet smtp-session。其中 replyto@example.com 应符合 smtp.mail.from from @ example .com to m.addFrom(...);

  telnet smtp.example.com 25 
220 smtp.example.com ESMTP .....

helo computername
250 smtp.example.com你好computername [123.123.123.123]

mail from:< replyto@example.com>
250< replyto@example.com>在语法上正确

rcpt to:< rcpt@foo.com&
250< rcpt@foo.com&已验证

data
354输入消息,以。结尾。一行一行
至:Joey< to@joey.com>
来自:Joey< from@example.com>
主题:Joey

嘿Joey!


250 OK id = ....

退出






  props.put(mail.smtp.from,replyto@example.com); 
会话session = Session.getDefaultInstance(道具,null);
MimeMessage m = new MimeMessage(session);
m.addFrom(InternetAddress.parse(from@example.com));


How to set the Return-Path to an email address other than Sender address using JavaMail?

解决方案

The code below does what you want, and does it in the correct way. Reread what you yourself posted in the comment

From: RFC2821: 4.4 Trace Information

When the delivery SMTP server makes the "final delivery" of a message, it inserts a return-path line at the beginning of the mail data. This use of return-path is required; mail systems MUST support it. The return-path line preserves the information in the from the MAIL command. Here, final delivery means the message has left the SMTP environment. Normally, this would mean it had been delivered to the destination user or an associated mail drop, but in some cases it may be further processed and transmitted by another mail system.

and a few lines later.

A message-originating SMTP system SHOULD NOT send a message that already contains a Return-path header.

If you carefully read this you will understand that only the final smtp-server/delivery agent is supposed to add the Return-Path header. It is not something you as client (trying to send a mail) should do. The final smtp-server will base the Return-Path header on the sender address of the envelope (SMTP MAIL FROM part).

So setting mail.smtp.from is the correct way to tell java that the envelope sender address should be different from the from part.

If you have troubles understanding what the different from's are just take a look at a telnet smtp-session. Where replyto@example.com should correspond to smtp.mail.from and from@example.com to m.addFrom(...);

telnet smtp.example.com 25 
220 smtp.example.com ESMTP .....

helo computername
250 smtp.example.com Hello computername [123.123.123.123]

mail from:<replyto@example.com>
250 <replyto@example.com> is syntactically correct

rcpt to:<rcpt@foo.com>
250 <rcpt@foo.com> verified

data
354 Enter message, ending with "." on a line by itself
To: Joey <to@joey.com>
From: Joey <from@example.com> 
Subject: Joey

Hey Joey!

.
250 OK id=....

Quit


props.put("mail.smtp.from", "replyto@example.com");
Session session = Session.getDefaultInstance(props, null);
MimeMessage m = new MimeMessage(session);
m.addFrom(InternetAddress.parse("from@example.com"));

这篇关于如何使用JavaMail将Return-Path设置为发送方地址以外的电子邮件地址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆