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: "nexthopdomain.com” This can be done as follows: • Create an additional send connector "Smarthost Connector" pointing to the smarthost • Specify a non-existing domain (e.g. nexthopdomain.com) as address space of the new connector The agent code of this article shows you how to route messages from the domain of "yourdomainnamehere.gcsx.gov.uk” 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) { try { // // This next bit checked each mail item for the secure domain for GCSX and subdomain // // if (e.MailItem.FromAddress.DomainPart.Contains("domainnamehere.gcsx.gov.uk")) { // 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 "nexthopdomain.com" only means that the routing engine chooses a suitable connector // for nexthopdomain.com instead of using the recipient's domain. RoutingDomain myRoutingOverride = new RoutingDomain("nexthopdomain.com"); foreach (EnvelopeRecipient recp in e.MailItem.Recipients) { if (!recp.Address.DomainPart.Contains("YOUR-INTERNAL-DOMAINNAME_HERE")) { recp.SetRoutingOverride(myRoutingOverride); } } } } 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
|
|
|
|