none
Exchange 2010 Agent not catch RRS feed

  • Question

  • 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 !

    Wednesday, July 10, 2013 12:21 PM

Answers

  • 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

    • Marked as answer by Dang Hong Son Monday, July 15, 2013 4:58 PM
    Thursday, July 11, 2013 11:04 AM
  • Delivery Agents "A delivery agent can deliver messages from your SMTP Exchange Server environment to a system that doesn’t 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

    • Marked as answer by Dang Hong Son Monday, July 15, 2013 4:58 PM
    Monday, July 15, 2013 6:40 AM

All replies

  • 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

    • Marked as answer by Dang Hong Son Monday, July 15, 2013 4:58 PM
    Thursday, July 11, 2013 11:04 AM
  • 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,

    • Marked as answer by Dang Hong Son Monday, July 15, 2013 4:53 PM
    • Unmarked as answer by Dang Hong Son Monday, July 15, 2013 4:57 PM
    Saturday, July 13, 2013 7:44 PM
  • Delivery Agents "A delivery agent can deliver messages from your SMTP Exchange Server environment to a system that doesn’t 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

    • Marked as answer by Dang Hong Son Monday, July 15, 2013 4:58 PM
    Monday, July 15, 2013 6:40 AM
  • Ah, that is.

    You help me alot, thank you !

    Son Dang,

    Monday, July 15, 2013 4:57 PM