Sender Based Routing revisited (Full Version)

All Forums >> [Microsoft Exchange 2007] >> Message Routing


Typoman -> Sender Based Routing revisited (3.Apr.2009 4:15:37 PM)

I offer Hosted Exchange.  Some clients need to route all of their outbound mail through SmartHost A.  Others need to route out through SmartHost B.  Clearly, Exchange 2007 does not offer the native ability to do this.  I can only route based on recipient, not sender. 

I have been told that I can write or buy a custom routing agent.  I might.  But I want to know if this can be done with multiple Exchange servers.

I only have one single Exchange server with all the roles on it.  Clients access OA,OWA,AS through ISA 2006.  SMTP is filtered in and out by a Barracuda. 

Am I right to assume that since the Send Connectors are defined in the Hub Transport area, that I could have two Hub Transport servers, each with one Send Connector that goes to a different smarthost?  What is the smallest number of Exchange servers I would need?  How would I make some accounts use Hub Transport A while others used Hub Transport B?

I am currently building a testing environment to figure this all out, but I am hoping someone here can get me going in the right direction.

ravisha_22 -> RE: Sender Based Routing revisited (7.Apr.2009 1:46:50 AM)

This can be acheived by adding one more Exchange box in to the organisation with all the three roles and placing them in a different AD site.

Then create a Send connector with each HUB server as the source server to the smarthost you want the mail to be routed.

Place the users in Site A if they want to use Smarthost A, which receives mail from HUB A and similarly in Site B.

It is not possible in the same site, because Exchange Mailbox server loa balances between available HUB servers.

However the point to notice is that if a Mailbox server also hosts a HUB server, the Mailbox server will prefer to route the mail through HUB in the same box over the HUB n different box, so you might be able to acheive isolation without going for different AD sites, but this needs to be tested for mail load, to see if the MB server tries to use the other HUB.

Typoman -> RE: Sender Based Routing revisited (19.Apr.2009 1:55:45 PM)

Brilliant.  Thanks, Ravisha.  Will I need a DC in the 2nd site?

ravisha_22 -> RE: Sender Based Routing revisited (19.Apr.2009 8:48:46 PM)

Yes you will need a GC on the second site, as the routing in Exchange 2007 is purely based on AD site connectors unless specified otherwise.

graham.hosking -> RE: Sender Based Routing revisited (17.Oct.2010 7:11:22 AM)

Sender Based Routing is possible either via a Custom Transport Agent or 3rd party tools/appliance. Local authorities needed to comply with strict mail routing rules for COCO and Government Connect policies.

I hope this helps people for the furture both with Exchange 2007 and 2010.

For this example we wanted to routing mail down diffent smart hosts, based on internal senders email address. But not to route internal mail differently. All you need to do is complie the code below in VS2010.

This routing agent was created to resolve the limitation of being able to route different users down the GovConnect send connector, with Sender Based Routing not being available "out of the box” in both Exchange versions 2007 and 2010.
Let's assume that you have an Exchange server with two send connectors, one being named the "Internet Connector" using DNS for the address space *. This connector will deal with all messages leaving the organisation. The other connector will also be an internet connector but named differently, for the example: "SmartHost Connector” this will have settings for the GovConnect smart host you want to use, however the domain name space is set to only allow this domain: "”
This can be done as follows:
• Create an additional send connector "Smarthost Connector" pointing to the smarthost
• Specify a non-existing domain (e.g. as address space of the new connector
The agent code of this article shows you how to route messages from the domain of "” over the new connector, the routing for all other sender's won't be changed.
Make sure you change this part of the code to suit your domain and any other customisations. ;-) - e.g "youdomainnamehere!!!"
This code is released on a "as is” basis and has no liability to the Originator for use or any security implications that is may have.

1.) Create a C# project (dll/library type)
2.) Copy the following DLLs from the C:\Program Files\Microsoft\Exchange Server\Public directory of an Exchange 2007 server to the debug directory of your new C# project:
a. Microsoft.Exchange.Data.Common.dll
b. Microsoft.Exchange.Data.Transport.dll

3.) Add references to the two DLLs to the C# project using the Visual Studio solution explorer

4.) Add the following code to your project:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.Exchange.Data.Transport;
using Microsoft.Exchange.Data.Transport.Email;
using Microsoft.Exchange.Data.Transport.Smtp;
using Microsoft.Exchange.Data.Transport.Routing;
using Microsoft.Exchange.Data.Common;

//This is a custom transport agent for GovConnect re-routing, created by. 01/08/10 GH

namespace RoutingAgentOverride
public class gcRoutingAgentFactory : RoutingAgentFactory
public override RoutingAgent CreateAgent(SmtpServer server)
RoutingAgent myAgent = new ownRoutingAgent();

return myAgent;
public class ownRoutingAgent : RoutingAgent
public ownRoutingAgent()
//subscribe to different events
base.OnResolvedMessage += new ResolvedMessageEventHandler(ownRoutingAgent_OnResolvedMessage);

void ownRoutingAgent_OnResolvedMessage(ResolvedMessageEventSource source, QueuedMessageEventArgs e)
// This next bit checked each mail item for the secure domain for GCSX and subdomain
if (e.MailItem.FromAddress.DomainPart.Contains(""))

// Here we set the address space we want to use for the next hop. Note that this doesn't change the recipient address.
// Setting the routing domain to "" only means that the routing engine chooses a suitable connector
// for instead of using the recipient's domain.

RoutingDomain myRoutingOverride = new RoutingDomain("");

foreach (EnvelopeRecipient recp in e.MailItem.Recipients)
if (!recp.Address.DomainPart.Contains("YOUR-INTERNAL-DOMAINNAME_HERE"))



catch // (Exception except)



5.) Compile the DLL
6.) Copy the DLL to the HubTransport server
7.) Install the transport agent using the Exchange Management Shell:
Install-TransportAgent "GCagent" -TransportAgentFactory "RoutingAgentOverride.gcRoutingAgentFactory" -AssemblyPath "Path to DLL"

8.) Enable the transport agent using the Exchange Management Shell:
Enable-TransportAgent "GCSX Agent"

9.) IMPORTANT: Exit Powershell
10.) IMPORTANT: Restart the MSExchangeTransport service, (restart-service msexchangetransport)

11.) Verify that the agent was successfully enabled / registered by running Get-Transportagent

motto -> RE: Sender Based Routing revisited (26.Oct.2010 10:37:00 AM)

We tried to do Sender Based Routing with a code similar to the MSDN sample above, but we experienced on a long term, that the performance is bad and it uses high system resources. We had to restart Transport Service from time to time.
But we found a commercial product on the web, called ExSBR. We are using the software since two years now in our hosting environment. Configuration can be applied in Exchange GUI or automatically by powershell. A simple solution, just does what it should do. No problems at all. The vendor is a German company called messageconcept.

Cheers, Michael

graham.hosking -> RE: Sender Based Routing revisited (26.Oct.2010 2:49:50 PM)

I've experienced no issues with using custom transport rules to date. I have already investigated the ExSBR 3rd party add-on, however this was an extreamly expensive product for a simple solution for routing emails. Note that ExSBR will also require an additional payment for maintenance for support and upgrades as with any other 3rd party bolt on.[:-]

Victor Ivanidze -> RE: Sender Based Routing revisited (3.Feb.2011 2:29:53 PM)

Yet another third-party utility designed to provide sender-based routing: RouteBySender

Victor Ivanidze

neustadt -> RE: Sender Based Routing revisited (29.Jul.2011 7:28:48 AM)


I'm having trouble installing my selfcompiled RoutingAgent. The setup looks like this:  Visual Studio 2010 Express on Windows XP-32 with all .NET Versions from 2.0 to 4.0 and the latest security updates. Exchange Server 2010 on Windows 2008R2 with .NET 4.0 and the latest updates.

When I try to load my RoutingAgent Exchange tells me that the .dll or a dependency of it can not be found. the assembly was created by a runtime which is newer than the loaded runtime can thus can not be loaded.
original message in german:

datei.dll oder eine Abhängigkeit davon wurde nicht gefunden. Die Assembly wird von einer Laufzeit erstellt, die aktueller als die derzeit geladene Laufzeit ist, und kann nicht geladen werden.

for which runtime does the dll have to be compiled against, and how do i change the settings for that in visual studio 2010?


wrightyi28 -> RE: Sender Based Routing revisited (6.Oct.2011 5:13:52 AM)

Ensure you copy your new dll to the program files\microsoft\exchange\server\public. This worked for me

Page: [1]