0

We are currently going through a proof of concept creating a Transport Agent that is derived from the Microsoft.Exchange.Data.Transport.Routing.RoutingAgent. We use the OnResolvedMessage event to reroute emails to our external Email server (non Exchange server). This all works fine, and we can reroute the emails to the external server. However, it appears that if an email contains both an internal and external recipient the email will be split into two separate emails and result in two emails going to the external email server. While the two emails contain the same content, just different RCPT TO headers, this will cause the external email server to process the same email twice which is less than desirable for our project.

This is my first time creating a transport agent, and I am trying to determine if there is some setting for exchange server that needs to be changed in order to stop emails that meet this criteria from being split into multiple emails?

The main goal of our transport agent will be to allow emails going to internal recipients to be processed by the external email server, as they currently will be placed into the internal user's mailbox unprocessed. It might have to do with our send/receive connectors, any guidance on any gotchas around those would be much appreciated. If a routing agent is not the correct solution for this problem, we are open to other possibilities.

Snippet of our event handler:

private void OnOnResolvedMessage(ResolvedMessageEventSource source, QueuedMessageEventArgs queuedMessageEventArgs)
{
        var mailItem = queuedMessageEventArgs.MailItem;
        var origSubject = mailItem.Message.Subject;
        mailItem.Message.Subject = "RouteAgent: " + origSubject;

        foreach (var recipient in mailItem.Recipients)
        {
            var newRouteDomain = new RoutingDomain("externalSendConnectorAddressSpace.com");
            var dest = new RoutingOverride(newRouteDomain, DeliveryQueueDomain.UseOverrideDomain);
            source.SetRoutingOverride(recipient, dest);
        }
}
cjablonski76
  • 173
  • 1
  • 13

1 Answers1

0

By the time OnResolved Message gets called in the Transport Pipeline the recipients will have been resolved and Bifurcation will have happened on the Message the rules for which are mostly explained in https://technet.microsoft.com/en-us/library/bb430743(v=exchg.150).aspx . EdgeTransport.exe.config is the place where the configuration of the Transport pipeline can be done but I don't believe there is any configuration option for what your trying to do.

If you catch the Message in OnSubmission event this will allow you to get the Message before any categorization has occurred. At that point you can more or less do what you want to the Message. However there are other things that occur as part of the Categorization process such as content conversion https://technet.microsoft.com/en-us/library/bb232174(v=exchg.150).aspx .

However, it appears that if an email contains both an internal and external recipient the email will be split into two separate emails and result in two emails going to the external email server. While the two emails contain the same content, just different RCPT TO headers, this will cause the external email server to process the same email twice which is less than desirable for our project.

This shouldn't really be a big deal for the external service as this should be something that would be expected in any process that was processing emails eg its easy for the external service correlate using the Internet MessageId etc. IMO your trying to solve the problem at the wrong end.

Cheers Glen

Glen Scales
  • 20,495
  • 1
  • 20
  • 23
  • Is there any way to not have the content conversion happen to the version sent to the internal users? We are actually having issues processing the internal user's version of the email. While it should be ok to send out more than one email as you've mentioned, we need them to actually be the same content if possible. – cjablonski76 Dec 15 '15 at 17:29
  • Content conversion means it converts the TNEFStream which typically a remote domain won't be able understand https://technet.microsoft.com/en-us/library/bb232174(v=exchg.150).aspx. For messages sent internally the content doesn't get converted because their is no point. (The store will do an on the fly conversion if a particular client request it like POP or IMAP). As a starting point I would suggest you do some tracing https://technet.microsoft.com/en-us/library/bb397226(v=exchg.150).aspx this will give you an idea of what is and isn't happening on particular messages in the Pipeline – Glen Scales Dec 16 '15 at 02:55
  • I just realized I meant to ask if there was a way to ensure that the internal recipient's content is converted so that it would match the content of the external recipients? Thanks for all of the help, so far I've not found any correct way to get internal emails to go to the external server with the same content as the external recipients. – cjablonski76 Dec 16 '15 at 19:19
  • I haven't tried this but I would suggest you look at the domain you using as the routing override. You should be able to specify the type of content conversion is used for that domain by defining is as a remote domain. The content conversion tracing should then tell you if it works or not – Glen Scales Dec 17 '15 at 01:27
  • I have not been able to get the internal recipients to stop going out in microsoft's format. I was thinking about instead temporarily manipulating the internal recipient addresses so they will be considered external, and then the external email server will know how to change them back to their original intended recipient address. Would you see any immediate reasons why this would be an unacceptable approach? – cjablonski76 Feb 11 '16 at 18:19
  • Sure sounds reasonable – Glen Scales Feb 12 '16 at 02:48