Skip to content

InspectingAgent

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

Description

This sample implements a RoutingAgent. This code executes when the message has been received from the Transport Front-End, put into the queue and is in the process of being categorized by the Hub Transport service.

Business Challenge

This Transport Agent can be used to debug mail-flow if necessary. There are multiple instances where discrepancies between P1 and P2 Sender causes problem, and sometimes there is lacking clarity of what values these are set to.

As such, this Transport Agent just writes on the Event Log an event containing all the P1, P2, and Header information of every message that traverses the transport pipeline. This can prove to be useful to inspect properties of a message for someone willing to develop a Transport Agent or create a Transport Rule but that lacks clarity on which property and value to trigger.

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 (InspectingAgent), 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 InspectingAgent

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 InspectingAgent -TransportAgentFactory "TransportAgents.InspectingAgent" -AssemblyPath "F:\Transport Agents\TransportAgents.dll"

  • Enable the chosen Transport Agent

Enable-TransportAgent InspectingAgent

  • Exit from Exchange Management Shell
  • Restart the MSExchangeTransport service

Restart-Service MSExchangeTransport

Removal

  • Disable the agent

Disable-TransportAgent InspectingAgent

  • Remove the agent

Uninstall-TransportAgent InspectingAgent

  • Exit from Exchange Management Shell
  • Restart the MSExchangeTransport service

Restart-Service MSExchangeTransport

Clone this wiki locally