Transport agent and journal messages RRS feed

  • Question

  • Months ago, I wrote a routing transport agent which analyzes the subject of emails based on a long-standing company pattern and cc's the mail to a specific mailbox.  This has all been working great, except for one recently-discovered issue.

    The filter naturally processes all journal messages as well.  So for each message sent and filtered, 2-3 or more journal messages also appear to be cc'ed, too.  Since these messages contain the header X-MS-Exchange-Generated-Message-Source: Journal Agent, I was thinking that this code might work to skip these messages:

           private void ProcessMailItem(MailItem item)
                MimeDocument mdMimeDoc = item.Message.MimeDocument;
                HeaderList hlHeaderlist = mdMimeDoc.RootPart.Headers;
                MimeNode lhLastHeader = hlHeaderlist.LastChild;
                 // Check first to verify this is not a journal message.  Otherwise there will be MANY copies cc'ed here.
                AddressHeader isJournal = (AddressHeader)hlHeaderlist.FindFirst("X-MS-Exchange-Generated-Message-Source");
                //if(isJournal.Value == "Journal Agent")
                if (isJournal.Value.Equals("Journal Agent"))
                    LogMessage("ProcessMailItem", item, "Skipping journal message");

    So, I am posting this here as a sanity check before we roll this into production.  Note that for all other cases where we are actually modifying headers and/or adding a CC, there is essentially no return from the function.

    Wednesday, September 10, 2014 6:36 PM

All replies

  • That should work okay but It sort of depends where in the pipeline your agent is firing eg is the Journal Agent is firing before your Agent (you can enable pipeline tracing to see the order in which they fire) and also how many Hub Servers you have in your Org. But that should skip any messages generated by the Journal Agent. Generally if you don't want a message to be processed twice it can useful to add your own header that will be visible to any other agents running on different Hub servers etc.


    Thursday, September 11, 2014 4:49 AM
  • Actually we cannot necessarily do that since the email may be responded to.  If that header were to persist then none of the subsequent messages (replies) would be filtered.  Will let you know how it goes.  Thanks for responding.
    • Edited by ML_GIE Thursday, September 11, 2014 1:48 PM
    Thursday, September 11, 2014 1:45 PM
  • Either should work - check for the journal header or add your own.

    If you add your own it's value should be specific to the message - so that if your agent sees a reply (or a reply to a reply) the value won't (new) match and you'll know that message hasn't been done.



    Scott Quinn | C# developer & messaging specialist (for hire). Contact me at

    Friday, September 12, 2014 2:27 AM
  • That makes sense.  I didn't move past the existence of the header on to being a specific value.
    Friday, September 12, 2014 4:15 PM