2

Im trying to write an exchange transport agent that tests to see if the subject line is empty, if it is than it inserts a default subject line. whenever i compiled, installed, and enabled this dll the server would no longer route email...

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

}

does anyone know why this might not be working?

thanks

chazjn
  • 313
  • 4
  • 18
Jeff
  • 1,609
  • 3
  • 20
  • 25
  • Install-TransportAgent -Name "DefaultSubjectAgent" -TransportAgentFactory "ExchangeTransportAgent.RoutingFactory" -AssemblyPath "E:\TransportAgents\ExchangeTransportAgent.dll" Enable-TransportAgent -Identity "DefaultSubjectAgent" – Jeff Jan 05 '11 at 20:00
  • these are the commands that i am running to install and enable the agent – Jeff Jan 05 '11 at 20:00

1 Answers1

2

"EventLog.WriteEntry" throw an error maybe. I had the same problem and when remove "EventLog.WriteEntry" all was ok. For now I don't know why.

user660976
  • 36
  • 2
  • thanks - i havent messed with this in awhile but i will test that out and see if it works. – Jeff Mar 22 '11 at 13:05