Skip to content

TaggingAgent

Tommaso Toniolo edited this page Apr 12, 2024 · 3 revisions

Description

This sample implements a SmtpReceiveAgent. This code executes when the message has been received from the Transport Front-End; it has to execute early in the Transport Pipeline as otherwise Exchange could reject the message (Directory-Based Edge Blocking) given the recipient address would not exist.

Business Challenge

This agent implements Plus Addressing in Exchange Server. This feature is available in Exchange On-Line but is not available in Exchange Server. The official documentation for Exchange Online, as a reference, can be found on here.

Plus addressing simply allows an existing address, such as someone@domain to receive messages on the address someone+tag@domain.

Given the address with the tag wouldn't exist in the Exchange, Exchange Server would naturally reject the message; with this agent such behaviour is overridden and the P1 header (used for routing the message) it overwritten to allow identifying the correct mailbox and allowing the message to be delivered.

The address is willingly not updated in the P2 header (the message itself, what you'd see in TO/CC/BCC in Outlook or OWA) as in this way the recipient could create Inbox Rules that acts based on the tag presence.

Let's assume a user is assigned the address [email protected], and wants to be able to use a different address when subscribing to newsletter, such as [email protected] and use instead the address [email protected] for receiving messages that are crucial for them. By enabling this transport agent, the user would be able to receive such messages sent to the tagged email addressed. The employee could also create inbox rules, for example, that would move to Junk Mail folder the messages sent to [email protected] while another rule could flag messages sent to [email protected].

Logging

This Transport Agent implements Event Logging for its operation. This has been chosen at it diminishes the chances of crashing the transport service in scenarios such as when a log file (if logging to text) could be locked by another process (i.e. anti-virus) or not accessible (i.e. missing permissions or non-existing path).

Event Logs would be recorded in the Application Event Log on the server; the agent would try to register a Source matching its name (TaggingAgent), if this is not possible it will try to fall back on the DLL name (TransportAgents) and, in case that is not possible as only applications running elevated has the privilege to do so, will fall back to logging entries as "Application" which should be already present and registered.

If you want to make sure the Transport Agent is capable or logging events under its own, separate, source for a quicker identification of the relevant events, please create the source manually on an elevated PowerShell prompt.

This can be done with the following command.

New-EventLog -LogName Application -Source TaggingAgent

Alternatively, if you want all different agents to log theri events on a single source, you can create the TransportAgents one as follows.

New-EventLog -LogName Application -Source TransportAgents

image

Installation

  • Copy the DLL to the server (i.e. F:\Transport Agents); Make sure the Exchange accounts have access to the folder
  • Install the transport agent

Install-TransportAgent -Name TaggingAgent -TransportAgentFactory "TransportAgents.TaggingAgent" -AssemblyPath "F:\Transport Agents\TransportAgents.dll"

  • Enable the chosen Transport Agent

Enable-TransportAgent TaggingAgent

  • Exit from Exchange Management Shell
  • Restart the MSExchangeTransport service

Restart-Service MSExchangeTransport

Removal

  • Disable the agent

Disable-TransportAgent TaggingAgent

  • Remove the agent

Uninstall-TransportAgent TaggingAgent

  • Exit from Exchange Management Shell
  • Restart the MSExchangeTransport service

Restart-Service MSExchangeTransport

Clone this wiki locally