C#Exchange 2007传输代理

时间:2011-01-05 19:46:35

标签: c# exchange-server exchange-transport-agents

我试图写一个交换传输代理,测试主题行是否为空,如果它是插入默认主题行。每当我编译,安装和启用此DLL时,服务器将不再路由电子邮件...

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using Microsoft.Exchange.Data.Transport;
using Microsoft.Exchange.Data.Transport.Email;
using Microsoft.Exchange.Data.Transport.Smtp;
using Microsoft.Exchange.Data.Transport.Routing;
using Microsoft.Exchange.Data.Common;

namespace ExchangeTransportAgent
{
    public class RoutingFactory : RoutingAgentFactory
    {

        public override RoutingAgent CreateAgent(SmtpServer server)
        {
            RoutingAgent myAgent = new sRoutingAgent();
            return myAgent;
        }
    }
}




class sRoutingAgent : RoutingAgent
{

    public sRoutingAgent()
    {
        //subscribe to different events
        base.OnSubmittedMessage += new SubmittedMessageEventHandler(SRoutingAgent_OnSubmittedMessage);
    }

    void SRoutingAgent_OnSubmittedMessage(SubmittedMessageEventSource source, QueuedMessageEventArgs e)
    {
        if (e.MailItem.Message.Subject == string.Empty)
        {
            try
            {
                e.MailItem.Message.Subject = "Kranichs Jewelers";


                EventLog.WriteEntry("MY Exchange Routing Agent", "MY ROUTING AGENT CHANGED THE SUBJECT",
                EventLogEntryType.Information, 1337);
            }
            catch (Exception except)
            {
                EventLog.WriteEntry("MY Exchange Routing Agent", except.Message,
                    EventLogEntryType.Error);
            }
        }
    }

}

有谁知道为什么这可能不起作用?

感谢

1 个答案:

答案 0 :(得分:2)

“EventLog.WriteEntry”可能会抛出错误。我遇到了同样的问题,当删除“EventLog.WriteEntry”时一切正常。现在我不知道为什么。