none
TransportAgent on Exchange 2010 RRS feed

  • Question

  • Hi,

    We wrote a transport agent which will be processed twice if emails will be directly send to our Exchange 2010 from our Ironports (Testemail). If the mail will be routed through our old Exchange 2007  it will be processed only once (Testemail2).

    Get-TransportPipline
        OnSubmittedMessage {UmlaufTransportAgent….}
    Get-TransportAgent
        Transport Rule Agent                        1
        Text Messaging Routing Agent                2
        Text Messaging Delivery Agent               3
        SenderBasedRouting                          4
        UmlaufTransportAgent                        5

    Both emails used the same connector – through Exchange 2007 with authentication and from our Ironports anonymous – and are only recognized once in the ReceiveLog.

    Transport rules do not happen twice…

    Any suggestions?

    Viele Grüße
    Christian


    Viele Grüße
    Christian

    Please remember to click "Mark as Answer" on the post that helps you, and to click "Unmark as Answer"; if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.

    Monday, March 12, 2012 4:57 PM

All replies

  • What does your agent actually do ? Is this a Routing Agent or a SMTP Transport Agent. What events are you using within your Transport Agent can you post some of the code your using eg could be your forking the message within the Agent or maybe you have a SMTPRecieveAgent and a Routing Agent which would make sense if its being processed twice on 2010 and once if Routed via 2007.

    Cheers
    Glen

    Monday, March 12, 2012 9:28 PM
  • Hi Glen,

    It is a SMTP Event for OnSubmittedMessage and the agent makes a copy of every incoming/outgoing email and put it to the folder „Umlauf" in the user mailbox. This happens twice for emails which are delivered directly to our Exchange 2010.

    Below you find the code...

    Thanks
    Christian

    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.IO;
    using Microsoft.Exchange.Data.Transport;
    using Microsoft.Exchange.Data.Transport.Email;
    using Microsoft.Exchange.Data.Transport.Routing;
    using Microsoft.Exchange.Data.Mime;
    using System.DirectoryServices;
    using log4net;
    using System.Threading;
    using EWS;
    using System.Text.RegularExpressions;
     
    namespace AET.Umlauf.Server {
           public class UmlaufRoutingAgentFactory: RoutingAgentFactory {
                 #region Variablen
                 [Flags]
                 private enum EmailType: byte {
                        Undefined     = 0,
                        IRONPort      = 1,
                        Private       = 2,
                        TNEF          = 4,
                        JournalReport = 8,
                        ADUser        = 16,
                        MailerDaemon  = 32,
                        Administrator = 64
                 }
     
                 private string _interneId;
                 private ILog _log = null;
                 private string _executionPath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
                 #endregion
     
                 public UmlaufRoutingAgentFactory() {
                 }
     
                 public override RoutingAgent CreateAgent(SmtpServer server) {
                        return new UmlaufRoutingAgent();
                 }
           }
     
           public class UmlaufRoutingAgent: RoutingAgent {
                 public UmlaufRoutingAgent() {
                        #region log4net initialisieren
                        FileInfo fi = new FileInfo(Path.Combine(_executionPath, "log4net.config"));
     
                        log4net.Config.XmlConfigurator.Configure(fi);
     
                        _log = LogManager.GetLogger(typeof(UmlaufRoutingAgent));
                        #endregion
     
                        _interneId = System.Guid.NewGuid().ToString().ToUpper();
     
                        //Handler zuweisen
                        base.OnSubmittedMessage += new SubmittedMessageEventHandler(UmlaufRoutingAgent_OnSubmittedMessage);
                 }
                       
                 private void UmlaufRoutingAgent_OnSubmittedMessage(SubmittedMessageEventSource source, QueuedMessageEventArgs e) {
                        _log.Info(_interneId + " - " + " UmlaufRoutingAgent_OnSubmittedMessage - ENTER ##################################### ");
     
                        DateTime end;
                        DateTime start;
                        TimeSpan neededTime;
     
                        start = DateTime.Now;
     
                        try {
                               ProcessEmail(source, e.MailItem);
                        } catch (Exception ex) {
                               _log.Debug(ex.Message);
                        }
     
                        end = DateTime.Now;
     
                        neededTime = end - start;
     
                        _log.Info(_interneId + " - " + " UmlaufRoutingAgent_OnSubmittedMessage - LEAVE ##################################### Benötigte Zeit: " + string.Format("{0:D2}:{1:D3}", neededTime.Seconds, neededTime.Milliseconds));
                 }
     
                 private void ProcessEmail(SubmittedMessageEventSource source, Microsoft.Exchange.Data.Transport.MailItem mailItem) {
                 }
           }
    }
     

    Tuesday, March 13, 2012 9:12 AM
  • You could try enabling pipeline tracing which should highlight the reason behind each trigger if multiple are occurring.

    Another suggestion would be I would add a custom x-header so you can tell if your agent has already processed a message this can be good idea to if you need to ensure things only happen once which is generally more important when you have the same agent running on multiple Hubs.

    Cheers
    Glen

    Tuesday, March 13, 2012 11:22 AM
  • Hi Glen,

    I enabled pipline tracing and there is an error at the transport rule agent:
     

    If I disable the Transport Rule Agent everything is fine. Also if I disable one special transport rule which seems to be a little bit bigger. I recreated it but without success.

    For MSExchangeTransport I extend the DiagnosticLogging to expert but there is no additional error. Tomorrow I will import the rule in my lab to see if this error happens there too.

    Does someone has an equal issues with transport rules and other transport agents? The transport rules are working without any problems…

    Any ideas?

    Best regards
    Christian    

    Tuesday, March 13, 2012 5:12 PM
  • > Also if I disable one special transport rule which seems to be a little bit bigger. I recreated it but without success.

    What does this rule do can you post the conditions and actions its taking its sounds like whatever its doing it maybe causing the message to be resubmitted (this is why i suggest you use a x-header to cater for this). Eg Address Resolution can cause a message to be deferred as per http://technet.microsoft.com/en-us/library/bb430743.aspx and end up being put on the Submission queue twice.

    Cheers
    Glen

    Wednesday, March 14, 2012 2:50 AM
  • Hi Glen,

    I can not really indentify a rule which cause this issue. Maybe to many rule (17)?!?!

    Our developer will write the X-header today and I will give you a feedback. I believe the best would be to start a call?!?


    Viele Grüße
    Christian

    Please remember to click "Mark as Answer" on the post that helps you, and to click "Unmark as Answer"; if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.

    Wednesday, March 14, 2012 1:28 PM
  • Hi Glen,

    We set the X-header and it is the same email handeled the seconde time:

    X-Mailer: Microsoft Outlook 14.0
    Thread-Index: Ac0B9IBRy+PpdEyoSvWX9XKw0OjCwQ==
    Content-Language: de
    X-Provags-ID: V02:K0:oHLPdLlOl8BgqOADtR4BIhrEheia5KglUFwtDZ28ojE
     K11WnKv92dYUs/sll3Sp7pOknxTS3vnxj9XM91JF1hJGOETdoi
     hvjYgsmbPp5esV30aHiIFzaVBm/zendV4UNdp1ACaOgIOFQWuy
     j7AXWIgzDQD4jMQwURqiCHZ+yV8QL7NJjCcfW6ZMfcBOv3FHQh
     RIbuN5Gnv59NrvYwbDPGw==
    Return-Path: christian.weihs@web.de
    X-MS-Exchange-Organization-AuthSource: Ex10-1.tifi.net
    X-MS-Exchange-Organization-AuthAs: Anonymous
    Aet-Header-Umlauf: Second Time

    Now we can ignore the message processing at the second time or we start I call to find the reason what I would prefer.

    What is your opinion?


    Viele Grüße
    Christian

    Please remember to click "Mark as Answer" on the post that helps you, and to click "Unmark as Answer"; if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.

    Wednesday, March 14, 2012 8:10 PM
  • I would always use the X-header regardless because there are a number of valid reasons for a Message to hit the Submission Queue twice especially if your processing Outbound Email. You may want to look at the other problem as a separate issue if its causing other problems with performance etc.

    Cheers
    Glen

    Thursday, March 15, 2012 4:19 AM
  • You don't get duplicate messages without a good reason (I'm not aware of any bug that would cause this).

    Can you dump the message string, the source and the envelope recipients...

    - Dump  e.MailItem.ToString() 

    - Dump the value for e.MailItem.InboundDeliveryMethod for the emails ...

       Values can be: DeliveryMethod.File, DeliveryMethod.Mailbox, DeliveryMethod.Smtp or DeliveryMethod.Unknown.

    - Dump the value(s) for the receipients.               

           IEnumerator<EnvelopeRecipient> MyEnumerator = e.MailItem.Recipients.GetEnumerator();

           while (MyEnumerator.MoveNext())

                  then dump MyEnumerator.Current.Address.ToString()

    Also, you elaborate on the transport rule/s you're using and have you considered using a later event ? i.e. OnCategorizedMessage

    Cheers,

    Scott

    Thursday, March 15, 2012 6:41 AM
  • Hi,

    I also see the error when I disable our TransportAgent. As a result there must be a problem with our transport rules.

    I imported the transportrulecollection in my lab and I have the same bevavior there.

    ...I started a call to see where problem is...

    Thanks and best regards
    Christian

    Thursday, March 15, 2012 4:53 PM