Thanks for your answer Glen
The following code is on exchange 2010 but i need it to check for a security group membership if possible
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;
namespace RoutingAgentOverride
{
public class SampleRoutingAgentFactory : 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
{
// For testing purposes we do not only check the sender address but the subject line as well
// If the subject contains the substring "REDIR" then the default routing is overwritten.
//
// Instead of hard-coding the sender you could also perform an LDAP-query, read the information
// from a text file, etc.
//
if (e.MailItem.FromAddress.DomainPart.Contains("contoso.com")
&& e.MailItem.Message.Subject.Contains("[encrypt]"))
{
// 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 recpient's domain.
RoutingDomain myRoutingOverride = new RoutingDomain("nexthopdomain.com");
foreach (EnvelopeRecipient recp in e.MailItem.Recipients)
{
recp.SetRoutingOverride(myRoutingOverride);
}
}
}
catch // (Exception except)
{
}
}
}