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