Transport Agent: Rewriting Sender or Recipient Domain

Lately I've been working on few Transport Agents which I feel maybe handy to share.

While the logic adopted is very simple, the sample showcase how to inspect and modify entries in the P1 and P2 headers.


The requirement was for 2 separate agents one rewriting the sender domain and one rewriting the recipient domain.

The Project contains 2 Solutions; the way these agents works is the following.



If the email is sent TO <somerepicpient> then rewrite the recipient to <somerepicpient>



If the email is sent FROM <somesender> then rewrite the sender as <somesender>


Attached you can find the Visual Studio Project; this includes the Exchange 2013 Microsoft.Exchange.Data.Common and Microsoft.Exchange.Data.Transport DLL's.

The sample though, can be easily adapted to Exchange 2010 if necessary. To do so all that needs to be done consists in removing the 2 DLL's from the References (for each Solution), remove the files from .\<Solution>\Exchange, grab the same DLL's from C:\Program Files\Microsoft\Exchange Server\V14\Public and re-add them to the References (for each Solution).



Comments (2)

  1. Pawel says:


    Thanks for this useful article. I tried to do it on Exchange 2010 (Windows 2008 R2) but when installing the agent I’m getting “This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded.”

    I tried to build the solution using .net framework 3.5, but still the same error.
    I’m not able to build using .net below 3.5 because I’m getting an error below. Any workaround?


    Warning 11 The primary reference “Microsoft.Exchange.Data.Common, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL” could not be resolved because it has an indirect dependency on the framework assembly “System.Core, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089” which could not be resolved in the currently targeted framework. “.NETFramework,Version=v2.0”. To resolve this problem, either remove the reference “Microsoft.Exchange.Data.Common, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL” or retarget your application to a framework version which contains “System.Core, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089”. RecipientDomainRewrite

    1. Hi Pawel,

      You probably need to use the Microsoft.Exchange.Data.Common.dll that comes with Exchange 2010 instead.
      The agent will then need to target .NET 3.5.

Skip to main content