Skip to content

Instantly share code, notes, and snippets.

@tliff
Created June 19, 2020 09:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tliff/87b43916b08c740881b6fe7c18c3bc02 to your computer and use it in GitHub Desktop.
Save tliff/87b43916b08c740881b6fe7c18c3bc02 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Exchange.Data.Transport;
using Microsoft.Exchange.Data;
using Microsoft.Exchange.Data.Transport.Smtp;
namespace MyAgents
{
public sealed class MyAgentFactory : SmtpReceiveAgentFactory
{
public override SmtpReceiveAgent CreateAgent(SmtpServer server)
{
return new MyAgent();
}
}
public class MyAgent : SmtpReceiveAgent
{
public MyAgent()
{
this.OnEndOfData += new EndOfDataEventHandler(MyEndOfDataHandler);
}
private void MyEndOfDataHandler(ReceiveMessageEventSource source, EndOfDataEventArgs e)
{
foreach ( EnvelopeRecipient address in e.MailItem.Recipients ) {
e.MailItem.Message.RootPart.AppendChild(new Microsoft.Exchange.Data.Mime.TextHeader("X-Original-Destination", address.ToString()));
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment