使用 Exchange 2007 传输代理编辑 SMTP 标头
我目前正在编写一个 Exchange 2007 传输代理来替换来自特定发件人的所有外发邮件中的某些标头。我成功地替换了“From”SMTP 标头,但重写“Return-Path”标头似乎不起作用。
为了实现这一切,我编写了一个自定义 SmtpReceiveAgent 并订阅 OnEndOfData 事件,如下所示:
private static void MyAgent_OnEndOfData(ReceiveMessageEventSource source, EndOfDataEventArgs e)
{
try
{
var address = e.MailItem.Message.From.SmtpAddress;
if (address.ToLower().EndsWith("[internal email domain]"))
{
// replace the From: header - WORKING FINE!
e.MailItem.Message.From = new EmailRecipient("[displayname]",
"[email address]");
// replace the Return-Path: header - NOT WORKING!
var headerList = e.MailItem.Message.RootPart.Headers;
var header = (AddressHeader)headerList.FindFirst("Return-Path");
var newheader = new AddressHeader("Return-Path") { Value = "[email address" };
headerList.ReplaceChild(newheader, header);
}
}
catch (Exception ex)
{
// do something useful here
}
}
I'm currently writing an Exchange 2007 Transport Agent to replace some headers in all outgoing mails from a particular sender. I managed to replace the 'From' SMTP header successfully, but rewriting the 'Return-Path' header does not seem to work.
To make this all happen, I have written a custom SmtpReceiveAgent and subscribe to the OnEndOfData event like this:
private static void MyAgent_OnEndOfData(ReceiveMessageEventSource source, EndOfDataEventArgs e)
{
try
{
var address = e.MailItem.Message.From.SmtpAddress;
if (address.ToLower().EndsWith("[internal email domain]"))
{
// replace the From: header - WORKING FINE!
e.MailItem.Message.From = new EmailRecipient("[displayname]",
"[email address]");
// replace the Return-Path: header - NOT WORKING!
var headerList = e.MailItem.Message.RootPart.Headers;
var header = (AddressHeader)headerList.FindFirst("Return-Path");
var newheader = new AddressHeader("Return-Path") { Value = "[email address" };
headerList.ReplaceChild(newheader, header);
}
}
catch (Exception ex)
{
// do something useful here
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
根据 RFC,返回路径标头应该由收件人的 SMTP 服务器设置。如果电子邮件中存在 Return-Path 标头,则收件人的服务器将删除并重置该标头。
也许您所看到的是 RFC 的正确实现。
Per the RFCs, the Return-Path header is supposed to be set by the recipient's SMTP server. If a Return-Path header exists in the email, it is to be removed, and reset by the recipient's server.
Maybe what you are seeing, is the correct implementation of the RFCs.
我不确定,但听起来您可能想要更改“回复”标头而不是“返回路径”。 “return-path”是由服务器设置的。
I'm not sure, but it sounds like you might want to be changing the "reply-to" header and not "return-path". "return-path" is meant to be set by the server.