Exchange 2010 Agent not catch

Hi,

I'm creating an agent transport handler for exchange 2010

Below is my code:

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Exchange.Data.Transport.Smtp;
using Microsoft.Exchange.Data.Transport;
using Microsoft.Exchange.Data.Transport.Delivery;
using System.IO;
using System.Diagnostics;

namespace ExchangeInAddin
{
    #region InMail
    public class PartialCatchAllFactory : SmtpReceiveAgentFactory
    {
        // Methods
        public override SmtpReceiveAgent CreateAgent(SmtpServer server)
        {
            return new PartialCatchAll();
        }
    }


    public class PartialCatchAll : SmtpReceiveAgent
    {
        // Methods
        public PartialCatchAll()
        {
            this.OnEndOfData += new EndOfDataEventHandler(MyEndOfDataHandler);
            this.OnRcptCommand += new RcptCommandEventHandler(PartialCatchAll_OnRcptCommand);
            this.OnEndOfHeaders += new EndOfHeadersEventHandler(PartialCatchAll_OnEndOfHeaders);

        }
        private void PartialCatchAll_OnEndOfHeaders(ReceiveMessageEventSource source, EndOfHeadersEventArgs e)
        {
            e.MailItem.Message.Subject += "sondh";
        }
        private void PartialCatchAll_OnRcptCommand(ReceiveCommandEventSource source, RcptCommandEventArgs e)
        {
            e.MailItem.Message.Subject += "hello OnRcpt here";
        }
        private void MyEndOfDataHandler(ReceiveMessageEventSource source, EndOfDataEventArgs e)
        {
            e.MailItem.Message.Subject += " - this text appended by MyAgent";

}

    }

}

This is installation command

Install-TransportAgent -Name "ExchangeInAddin" -AssemblyPath "C:\ExchangeDemo\ExchangeInAddin.dll" -TransportAgentFactory "ExchangeInAddin.PartialCatchAllFactory"

Enable-TransportAgent -Name "ExchangeInAddin"

Restart-Service MSExchangeTransport

IISRESET

I check agent by Get-TransportAgent. The state of my agent is enable.

I built and installed success. But when I sent email to test. The subject was not affected by events that I have catched.

What's problem with my agent transport ?

Waiting for the help from everyone !

July 10th, 2013 3:21pm

An SmtpReceiveAgent will only fire for message that are received over SMTP. The Agent wouldn't fire for messages that are just sent between two users on the same server as these messages while they go via the Hub server don't travel via SMTP. (for this type of thing you would need to use a RouterAgent).

To test your agent you will need to send something to your server from an Outside address . To further trace what's happening you can enable PipeLine tracing to see what Agents are being called on when Messages go via the Transport Pipeline http://technet.microsoft.com/en-us/library/bb125018(v=exchg.141).aspx.

Cheers
Glen

Free Windows Admin Tool Kit Click here and download it now
July 11th, 2013 2:04pm

Thank you so much Glen ! You help me understand about SmtpReceiveAgent.

I have another question. 

Does DeliveryAgentManager only fire when I send an email from an user on my server to another ? 

So if I use RoutingAgent, can it catch both the send and receive email ? And how can I distinguish them ?

Regards,

Son Dang,

July 13th, 2013 3:47pm

Delivery Agents "A delivery agent can deliver messages from your SMTP Exchange Server environment to a system that doesnt use the SMTP protocol" ref http://technet.microsoft.com/en-us/library/dd638118(v=exchg.150).aspx

What that means is that you only use delivery agents when you need to delivery messages to a Non SMTP mailbox system (eg a legacy mail system like Notes, GroupWise, MSMail etc).

A RouterAgent will fire on every message no mater the source.

Cheers
Glen

Free Windows Admin Tool Kit Click here and download it now
July 15th, 2013 2:44am

Ah, that is.

You help me alot, thank you !

Son Dang,

July 15th, 2013 1:00pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics