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);
}
}
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