Sending Email with return-path not functioning

安稳与你 提交于 2019-12-08 05:48:44

问题


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);
}

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.

any ideas?


回答1:


You're using a slightly wrong approach. Simple Mail Transfer Protocol (RFC 2821) says:

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.

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");


来源:https://stackoverflow.com/questions/8912861/sending-email-with-return-path-not-functioning

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!