开发者

Intercepting outgoing Exchange Server email and modifying it

开发者 https://www.devze.com 2022-12-25 12:38 出处:网络
I want to be able to intercept outgoing email on a specific domain in Exchange Server and modify the headers before it is actually delivered.

I want to be able to intercept outgoing email on a specific domain in Exchange Server and modify the headers before it is actually delivered.

Basically, my company has been bought by another and where we were using MDaemon and signing all our emails with DKim and Doma开发者_如何学编程inKeys, the new company uses Exchange Server which cannot and will not do this. This appears to be a major oversight I would have thought so I think I will need to do it myself. I have already written a COM component that can sign given message files which I use on my personal mail server using hMailServer, so wanted to do a similar thing for Exchange.

Is this possible, and if so how would you do it?

I have looked but could not find an obvious way of doing this. Some of the things I looked at included:

  • Transport Agents
  • Event Sinks
  • Store Events

Any help would be appreciated. Thanks.


For Exchange 2007 and later: It seems that a TransportAgent is the right way of doing it.

A very basic sample:

public class TestAgent : SmtpReceiveAgent
{
    public TestAgent()
    {
        this.OnEndOfData += new EndOfDataEventHandler(MyEndOfDataHandler);
    }
    private void MyEndOfDataHandler(ReceiveMessageEventSource source, EndOfDataEventArgs e)
    {
        // The following line appends text to the subject of the message that caused the event.
        e.MailItem.Message.Subject += " - this text appended by MyAgent";
    }
}

You can change the actual message via the GetContentWriteStream() and just append or replace existing content.

More samples can be found here.

I know... it's a late answer, but I stumbled over this question and just want to leave some helpful links that I found.


Maybe you can use the Generic Exchange Transport Agent (open source, link goes to GitHub) for this. It provides an abstraction layer above the Exchange transport agent and is specifically designed to handle events for incoming/outgoing email. You can call custom batch scripts to rewrite the whole e-mail, e.g. for adding custom headers and so on.

0

精彩评论

暂无评论...
验证码 换一张
取 消