简体   繁体   English

Exchange传输代理-无法更改邮件信封的DisplayName

[英]Exchange Transport Agent - Can't change DisplayName of message envelope

I have a distribution list which is made up of recipients almost exclusively outside of my organization. 我有一个通讯组列表,几乎由我组织外部的所有收件人组成。 Due to issues with one of the recipients mail hosts, they reject all messages with a From header which originates from outside their network. 由于收件人邮件主机之一的问题,它们拒绝所有带有From头的消息,这些头来自其网络外部。 So if user1@company.com sends a message to the list, user2@company.com will never receive it. 因此,如果user1@company.com将消息发送到列表,则user2@company.com将永远不会收到该消息。 As such I have written a transport agent to modify the From and Sender in the P1 and P2 SMTP and Message Envelopes of a mail item to be that of distribution list itself. 因此我写了一个传输代理修改FromSender在邮件项目的P1和P2 SMTP和邮件信封,该通讯组列表本身。 Everything works fine for the most part. 大部分情况下一切正常。

To make it possible to know who sent the email to the distribution list, I have the transport agent set the Display Name of the P2 Message Envelope to be the real email address of the sender. 为了使知道谁发送电子邮件到通讯组列表,我让传输代理将P2消息信封的显示名称设置为发件人的真实电子邮件地址。 This works if someone outside my organization sends a email to the list, but does not if the sender is inside my organization. 如果组织外部的某人向列表发送了电子邮件,但发件人不在组织内部,则不起作用。 I've tried implementing this as both a RoutingAgent and a SmtpReceiveAgent and the behavior is the same. 我尝试将其同时实现为RoutingAgentSmtpReceiveAgent ,并且行为相同。 From my logging I can see that the messages are being processed for senders internal to my organization. 从我的日志记录中,我可以看到正在为组织内部的发件人处理邮件。

Does anyone know what this is not behaving as expected? 有谁知道这不是预期的行为?

public void OnEndOfDataHandler(ReceiveMessageEventSource source, EndOfDataEventArgs eodArgs)
{
    MailItem mailItem = eodArgs.MailItem;
    EmailMessage message = mailItem.Message;
    EnvelopeRecipient distributionList = AddressedToDistributionList(mailItem);

    if(distributionList != null)
    {
        mailItem.FromAddress = distributionList.Address;

        if (message.From.DisplayName == message.From.SmtpAddress)
            message.From = new EmailRecipient(message.From.SmtpAddress.Replace("@", " at "), distributionList.Address.GetAddress(true));
        else
            message.From = new EmailRecipient(message.From.DisplayName + " (" + message.From.SmtpAddress.Replace("@", " at ") + ")", distributionList.Address.GetAddress(true));

        if (message.Sender.DisplayName == message.Sender.SmtpAddress)
            message.Sender = new EmailRecipient(message.Sender.SmtpAddress.Replace("@", " at "), distributionList.Address.GetAddress(true));
        else
            message.Sender = new EmailRecipient(message.Sender.DisplayName + " (" + message.Sender.SmtpAddress.Replace("@", " at ") + ")", distributionList.Address.GetAddress(true));
    }
}

Changing the Display Name won't work because when the message is delivered to the Store Exchange will always resolve the Email address use back the EX Address entry from the GAL. 更改显示名称将无效,因为当邮件传递到Store Exchange时,它将始终解析电子邮件地址,请使用GAL中的EX地址条目。 This is by design and you won't be alter this behavior. 这是设计使然,您将不会更改此行为。 My suggestion would be your agent you should only act after the expansion of the message (eg look at fork https://msdn.microsoft.com/en-us/library/microsoft.exchange.data.transport.routing.queuedmessageeventsource.fork%28v=exchg.80%29.aspx ) and should only act on those messages that are going to be routed to the problematic destination. 我的建议是作为您的代理,您应该仅在扩展消息后采取行动(例如,查看fork https://msdn.microsoft.com/en-us/library/microsoft.exchange.data.transport.routing.queuedmessageeventsource.fork %28v = exchg.80%29.aspx ),并且只应对将被路由到有问题的目的地的邮件起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM