Hi All,
I have done a lot of research on writing a code for custom Transport Agent.
What I need to achieve is that one of Linux server sends an email @linux.com through our Exchange system here and I'd like the receiver will get @domain.com instead of @linux.com. Because there are a couple users in that domain, so whoever sends from this linux.com will get changed (@domain.com) at the destination.
From my research and modify the codes from number of websites
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
{
if (e.MailItem.FromAddress.DomainPart.Contains("linux.com"))
{
e.MailItem.FromAddress = new RoutingAddress("Localpart", "domain.com");
e.MailItem.Message.From.SmtpAddress = "localpart" + "@" + "domain.com";
e.MailItem.Message.Sender.SmtpAddress = "localpart" + "@" + "domain.com";
}
}
catch
{
}
}
}
I have not tested, would it work?
Thanks