Discussion:
Ex 07 Route outbound email differently based on sender?
(too old to reply)
Mike O.
2009-08-25 18:23:02 UTC
Permalink
We have an Exchange 2007 system with about 5,000 users. Currently outbound
internet email goes from the hub transport servers directly out to the
internet (inbound goes through antivirus/antispam filter, etc.).

We're looking at implementing an email encryption system for a subset of our
users (about 100). To do this, we'd like to set the hub servers so that any
outbound email from certain users (preferabley based on A/D group membership)
will go to a smarthost/relay, while everyone not in that group goes out
through the standard method.

It doesn't look like there is a way to set a send connector to only be used
by certain people; the only restriction seems to be based on recipient
domain. Is there some way to set this up so that only certain senders go
through this relay?

Mike O'Donnell
Ed Crowley [MVP]
2009-08-26 00:47:16 UTC
Permalink
The only way I can think of doing that is to create a new Exchange server in
a different AD site for those mailboxes, configure a new send connector that
directs mail to the encryption system, and configure both send connectors
with the -InScopedConnector:$True parameter to ensure that they're used only
by servers in their site.
--
Ed Crowley MVP
"There are seldom good technological solutions to behavioral problems."
.
Post by Mike O.
We have an Exchange 2007 system with about 5,000 users. Currently outbound
internet email goes from the hub transport servers directly out to the
internet (inbound goes through antivirus/antispam filter, etc.).
We're looking at implementing an email encryption system for a subset of our
users (about 100). To do this, we'd like to set the hub servers so that any
outbound email from certain users (preferabley based on A/D group membership)
will go to a smarthost/relay, while everyone not in that group goes out
through the standard method.
It doesn't look like there is a way to set a send connector to only be used
by certain people; the only restriction seems to be based on recipient
domain. Is there some way to set this up so that only certain senders go
through this relay?
Mike O'Donnell
JCirillo [MCA-M]
2009-08-26 03:49:01 UTC
Permalink
This can be accomplished with a custom Transport Agent, which requires a
developer to write.
--
JC
Post by Mike O.
We have an Exchange 2007 system with about 5,000 users. Currently outbound
internet email goes from the hub transport servers directly out to the
internet (inbound goes through antivirus/antispam filter, etc.).
We're looking at implementing an email encryption system for a subset of our
users (about 100). To do this, we'd like to set the hub servers so that any
outbound email from certain users (preferabley based on A/D group membership)
will go to a smarthost/relay, while everyone not in that group goes out
through the standard method.
It doesn't look like there is a way to set a send connector to only be used
by certain people; the only restriction seems to be based on recipient
domain. Is there some way to set this up so that only certain senders go
through this relay?
Mike O'Donnell
Oliver Moazzezi [MVP]
2009-09-03 09:20:00 UTC
Permalink
Post by JCirillo [MCA-M]
This can be accomplished with a custom Transport Agent, which requires a
developer to write.
--
JC
To dive deeper into this, you must have Exchange 2007 SP1 applied and you
can then take advantage of the EnvelopeRecipient.RoutingOverride property
when writing custom Transport Agents.

Read here for more information and sample code:
http://msdn.microsoft.com/en-us/library/microsoft.exchange.data.transport.enveloperecipient.routingoverride.aspx


Otherwise you will have to have to use a third party gateway (you may or may
not already) that can support this outside of Exchange or do as Ed states
and bound senders by AD Sites and limit the Send Connector scopes.

Oliver
Chrischmi
2009-12-15 01:10:48 UTC
Permalink
You can do this with our tool ptecs ExSBR - Sender Based Routing fo
Exchange Server 2007 and 2010. You find a short description o
http://www.slipstick.com/exs/misc.asp or just write us an email to exsb
at ptecs dot de - and you get an eval version from us.

Regards, Chrischm

--
Chrischm
http://forums.slipstick.co
Graham Hosking
2010-10-17 11:04:09 UTC
Permalink
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
Post by Mike O.
We have an Exchange 2007 system with about 5,000 users. Currently outbound
internet email goes from the hub transport servers directly out to the
internet (inbound goes through antivirus/antispam filter, etc.).
We're looking at implementing an email encryption system for a subset of our
users (about 100). To do this, we'd like to set the hub servers so that any
outbound email from certain users (preferabley based on A/D group membership)
will go to a smarthost/relay, while everyone not in that group goes out
through the standard method.
It does not look like there is a way to set a send connector to only be used
by certain people; the only restriction seems to be based on recipient
domain. Is there isome way to set this up so that only certain senders go
through this relay?
Mike O'Donnell
Post by Ed Crowley [MVP]
The only way I can think of doing that is to create a new Exchange server in
a different AD site for those mailboxes, configure a new send connector that
directs mail to the encryption system, and configure both send connectors
with the -InScopedConnector:$True parameter to ensure that they are used only
by servers in their site.
--
Ed Crowley MVP
"There are seldom good technological solutions to behavioral problems."
.
Post by JCirillo [MCA-M]
This can be accomplished with a custom Transport Agent, which requires a
developer to write.
--
JC
Post by Oliver Moazzezi [MVP]
To dive deeper into this, you must have Exchange 2007 SP1 applied and you
can then take advantage of the EnvelopeRecipient.RoutingOverride property
when writing custom Transport Agents.
http://msdn.microsoft.com/en-us/library/microsoft.exchange.data.transport.enveloperecipient.routingoverride.aspx
Otherwise you will have to have to use a third party gateway (you may or may
not already) that can support this outside of Exchange or do as Ed states
and bound senders by AD Sites and limit the Send Connector scopes.
Oliver
You can do this with our tool ptecs ExSBR - Sender Based Routing for
Exchange Server 2007 and 2010. You find a short description on
http://www.slipstick.com/exs/misc.asp or just write us an email to exsbr
at ptecs dot de - and you get an eval version from us.
Regards, Chrischmi
--
Chrischmi
http://forums.slipstick.com
Submitted via EggHeadCafe - Software Developer Portal of Choice
Using ASP.NET Session with Silverlight and WCF Services
http://www.eggheadcafe.com/tutorials/aspnet/c72cc77a-bf84-4180-a35b-46b8726ab782/using-aspnet-session-with-silverlight-and-wcf-services.aspx
Graham Hosking
2010-10-17 11:05:46 UTC
Permalink
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
Post by Mike O.
We have an Exchange 2007 system with about 5,000 users. Currently outbound
internet email goes from the hub transport servers directly out to the
internet (inbound goes through antivirus/antispam filter, etc.).
We're looking at implementing an email encryption system for a subset of our
users (about 100). To do this, we'd like to set the hub servers so that any
outbound email from certain users (preferabley based on A/D group membership)
will go to a smarthost/relay, while everyone not in that group goes out
through the standard method.
It does not look like there is a way to set a send connector to only be used
by certain people; the only restriction seems to be based on recipient
domain. Is there isome way to set this up so that only certain senders go
through this relay?
Mike O'Donnell
Post by Ed Crowley [MVP]
The only way I can think of doing that is to create a new Exchange server in
a different AD site for those mailboxes, configure a new send connector that
directs mail to the encryption system, and configure both send connectors
with the -InScopedConnector:$True parameter to ensure that they are used only
by servers in their site.
--
Ed Crowley MVP
"There are seldom good technological solutions to behavioral problems."
.
Post by JCirillo [MCA-M]
This can be accomplished with a custom Transport Agent, which requires a
developer to write.
--
JC
Post by Oliver Moazzezi [MVP]
To dive deeper into this, you must have Exchange 2007 SP1 applied and you
can then take advantage of the EnvelopeRecipient.RoutingOverride property
when writing custom Transport Agents.
http://msdn.microsoft.com/en-us/library/microsoft.exchange.data.transport.enveloperecipient.routingoverride.aspx
Otherwise you will have to have to use a third party gateway (you may or may
not already) that can support this outside of Exchange or do as Ed states
and bound senders by AD Sites and limit the Send Connector scopes.
Oliver
You can do this with our tool ptecs ExSBR - Sender Based Routing for
Exchange Server 2007 and 2010. You find a short description on
http://www.slipstick.com/exs/misc.asp or just write us an email to exsbr
at ptecs dot de - and you get an eval version from us.
Regards, Chrischmi
--
Chrischmi
http://forums.slipstick.com
Post by Graham Hosking
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?
? 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)
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
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
Install-TransportAgent "GCagent" -TransportAgentFactory "RoutingAgentOverride.gcRoutingAgentFactory" -AssemblyPath "Path to DLL"
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
Submitted via EggHeadCafe - Software Developer Portal of Choice
Using ASP.NET Session with Silverlight and WCF Services
http://www.eggheadcafe.com/tutorials/aspnet/c72cc77a-bf84-4180-a35b-46b8726ab782/using-aspnet-session-with-silverlight-and-wcf-services.aspx
Victor Ivanidze
2011-02-03 19:33:46 UTC
Permalink
There exists another tool named RoutBySender:
http://ivasoft.com/routebysender.shtml
Post by Mike O.
We have an Exchange 2007 system with about 5,000 users. Currently outbound
internet email goes from the hub transport servers directly out to the
internet (inbound goes through antivirus/antispam filter, etc.).
We're looking at implementing an email encryption system for a subset of our
users (about 100). To do this, we'd like to set the hub servers so that any
outbound email from certain users (preferabley based on A/D group membership)
will go to a smarthost/relay, while everyone not in that group goes out
through the standard method.
It does not look like there is a way to set a send connector to only be used
by certain people; the only restriction seems to be based on recipient
domain. Is there isome way to set this up so that only certain senders go
through this relay?
Mike O'Donnell
Post by Ed Crowley [MVP]
The only way I can think of doing that is to create a new Exchange server in
a different AD site for those mailboxes, configure a new send connector that
directs mail to the encryption system, and configure both send connectors
with the -InScopedConnector:$True parameter to ensure that they are used only
by servers in their site.
--
Ed Crowley MVP
"There are seldom good technological solutions to behavioral problems."
.
Post by JCirillo [MCA-M]
This can be accomplished with a custom Transport Agent, which requires a
developer to write.
--
JC
Post by Oliver Moazzezi [MVP]
To dive deeper into this, you must have Exchange 2007 SP1 applied and you
can then take advantage of the EnvelopeRecipient.RoutingOverride property
when writing custom Transport Agents.
http://msdn.microsoft.com/en-us/library/microsoft.exchange.data.transport.enveloperecipient.routingoverride.aspx
Otherwise you will have to have to use a third party gateway (you may or may
not already) that can support this outside of Exchange or do as Ed states
and bound senders by AD Sites and limit the Send Connector scopes.
Oliver
You can do this with our tool ptecs ExSBR - Sender Based Routing for
Exchange Server 2007 and 2010. You find a short description on
http://www.slipstick.com/exs/misc.asp or just write us an email to exsbr
at ptecs dot de - and you get an eval version from us.
Regards, Chrischmi
--
Chrischmi
http://forums.slipstick.com
Post by Graham Hosking
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?
? 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)
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
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
Install-TransportAgent "GCagent" -TransportAgentFactory "RoutingAgentOverride.gcRoutingAgentFactory" -AssemblyPath "Path to DLL"
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
Post by Graham Hosking
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?
? 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)
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
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
Install-TransportAgent "GCagent" -TransportAgentFactory "RoutingAgentOverride.gcRoutingAgentFactory" -AssemblyPath "Path to DLL"
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
Submitted via EggHeadCafe
WCF Generic DataContract object Serializer
http://www.eggheadcafe.com/tutorials/aspnet/59ae2b9e-a3be-4cd5-a0ef-939a7abbdc3a/wcf-generic-datacontract-object-serializer.aspx
Sky Port
2011-03-24 14:14:58 UTC
Permalink
Hello,

Thanks, this is greate but can you explain the part related to the nexthopdomain ! is this the send connector name or the smarthost i'm routing the emails to.

#example:
I have 2 domain names on my exch server (domain1.com) and (domain2.com), i need all users addresses sending from: @domain1.com to use the connector which route to a smarthost, and all users addresses sending from: @domain2.com to use the default send connector.

i have 2 connectors:
connector1: type=smtp, add space= * , cost=1
connector2: type=smtp, add space= *.special.com , cost=1


please can you define the inputs in my example in the above agent code ? and send back to me.

Thank you in advance.

Regards,
SkyPorts
-------------------------
Post by Mike O.
We have an Exchange 2007 system with about 5,000 users. Currently outbound
internet email goes from the hub transport servers directly out to the
internet (inbound goes through antivirus/antispam filter, etc.).
We're looking at implementing an email encryption system for a subset of our
users (about 100). To do this, we'd like to set the hub servers so that any
outbound email from certain users (preferabley based on A/D group membership)
will go to a smarthost/relay, while everyone not in that group goes out
through the standard method.
It does not look like there is a way to set a send connector to only be used
by certain people; the only restriction seems to be based on recipient
domain. Is there isome way to set this up so that only certain senders go
through this relay?
Mike O'Donnell
Post by Ed Crowley [MVP]
The only way I can think of doing that is to create a new Exchange server in
a different AD site for those mailboxes, configure a new send connector that
directs mail to the encryption system, and configure both send connectors
with the -InScopedConnector:$True parameter to ensure that they are used only
by servers in their site.
--
Ed Crowley MVP
"There are seldom good technological solutions to behavioral problems."
.
Post by JCirillo [MCA-M]
This can be accomplished with a custom Transport Agent, which requires a
developer to write.
--
JC
Post by Oliver Moazzezi [MVP]
To dive deeper into this, you must have Exchange 2007 SP1 applied and you
can then take advantage of the EnvelopeRecipient.RoutingOverride property
when writing custom Transport Agents.
http://msdn.microsoft.com/en-us/library/microsoft.exchange.data.transport.enveloperecipient.routingoverride.aspx
Otherwise you will have to have to use a third party gateway (you may or may
not already) that can support this outside of Exchange or do as Ed states
and bound senders by AD Sites and limit the Send Connector scopes.
Oliver
You can do this with our tool ptecs ExSBR - Sender Based Routing for
Exchange Server 2007 and 2010. You find a short description on
http://www.slipstick.com/exs/misc.asp or just write us an email to exsbr
at ptecs dot de - and you get an eval version from us.
Regards, Chrischmi
--
Chrischmi
http://forums.slipstick.com
Post by Graham Hosking
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”
• 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)
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
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
Install-TransportAgent "GCagent" -TransportAgentFactory "RoutingAgentOverride.gcRoutingAgentFactory" -AssemblyPath "Path to DLL"
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
Post by Graham Hosking
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”
• 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)
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
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
Install-TransportAgent "GCagent" -TransportAgentFactory "RoutingAgentOverride.gcRoutingAgentFactory" -AssemblyPath "Path to DLL"
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
Post by Victor Ivanidze
http://ivasoft.com/routebysender.shtml
Loading...