How can I route out certain outbound domains to specific SMTP gateways?

I had a Rocky Mountain university ask how they could route specific internally defined SMTP domains that are sending out of the Hub Transport to an Encryption server. To accomplish this, a custom Transport Agent is required.  A transport agent is akin to the event sinks of Exchange 2003 where you have a custom .dll utilized. To read about what one is go here and how to write one go here.

 

I found a sample transport agent that provides similar functionality:

 

 namespace FFRouting1
{
    public class SampleRoutingAgentFactory : RoutingAgentFactory
    {
        public override RoutingAgent CreateAgent(SmtpServer server)
        {
            RoutingAgent myAgent = new SRoutingAgent();
            return myAgent;
        }
    }
}

public class SRoutingAgent : RoutingAgent
{
    public SRoutingAgent()
    {
        //subscribe to different events
        base.OnResolvedMessage += new ResolvedMessageEventHandler(SRoutingAgent_OnResolvedMessage);
    }

    void SRoutingAgent_OnResolvedMessage(ResolvedMessageEventSource source, QueuedMessageEventArgs e)
    {
        try 
            {
                RoutingDomain myRoutingOverride = new RoutingDomain("contoso.com");
                foreach (EnvelopeRecipient recp in e.MailItem.Recipients)
                {
                    recp.SetRoutingOverride(myRoutingOverride);

                }

                EventLog.WriteEntry("FFRouting1 Agent", "My Routing Agent fired successfully",
                EventLogEntryType.Information, 555);
            }   

        catch (Exception except)
            {
                EventLog.WriteEntry("FFRouting1 Agent", except.Message,
                EventLogEntryType.Error);
            }
     }

}