发送电子邮件,返回路径不起作用 [英] Sending Email with return-path not functioning
问题描述
我正在使用 System.Net.Mail
电子邮件。在代码中,我设置电子邮件的返回路径如下:
I am using System.Net.Mail
email. in the code i am setting the return-path of email as follow:
string sReturnPath = ConfigurationManager.AppSettings["ReturnPath"].ToString();
if (sReturnPath.Length > 0) {
msg.Headers.Add("Return-Path", sReturnPath);
}
如果交货失败,它应该返回返回路径, t,即使我可以看到电子邮件的返回路径的标题来自我指定的配置文件。
If the delivery has failed it should go to return-path but it doesn't, even though I can see the header of email's return-path being from config file that I specified. The email gets returned to sender.
推荐答案
你使用的方法略为错误。简单邮件传输协议( RFC 2821 )说:
You're using a slightly wrong approach. Simple Mail Transfer Protocol (RFC 2821) says:
消息始发的SMTP系统不应发送一条消息,其中
已经包含一个返回路径头。执行
中继功能的SMTP服务器不得检查消息数据,特别是不能
,以确定是否存在返回路径头。
A message-originating SMTP system SHOULD NOT send a message that
already contains a Return-path header. SMTP servers performing a
relay function MUST NOT inspect the message data, and especially not
to the extent needed to determine if Return-path headers are present.
如果您希望将邮件返回到 From指定的地址以外的地址:
字段,则应在SMTP消息信封中设置地址,而不是在消息头中设置。您可以通过设置发件人
属性来实现此目的:
If you want your message to be returned to the address other than the one specified in the From:
field, then the address should be set in the SMTP message envelope rather than in the message header. You can achieve this by setting the Sender
property:
MailMessage msg = new MailMessage();
msg.Sender = new MailAddress("not-deliviered@sample.org", "Sam1");
这篇关于发送电子邮件,返回路径不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!