传输代理Exchange ServerTransport agents in Exchange Server

通过传输代理,您可以在 Exchange 服务器上安装由 Microsoft、第三方供应商或您的组织创建的自定义软件。Transport agents let you install custom software that is created by Microsoft, by third-party vendors, or by your organization, on an Exchange server. 随后该软件便可以处理通过传输管道的电子邮件。This software can then process email messages that pass through the transport pipeline. 在 Microsoft Exchange Server 2016 或 2019 中,传输管道由以下过程决定:In Microsoft Exchange Server 2016 or 2019, the transport pipeline is made of the following processes:

  • 邮箱服务器的前端传输服务The Front End Transport service on Mailbox servers
  • 邮箱服务器上的传输服务The Transport service on Mailbox servers
  • 邮箱服务器上的邮箱传输服务The Mailbox Transport service on Mailbox servers
  • 边缘传输服务器上的传输服务The Transport service on Edge Transport servers

有关传输管道详细信息,请参阅邮件 流和传输管道For more information about the transport pipeline, see Mail flow and the transport pipeline

Exchange传输通过传输代理 SDK Microsoft Exchange Server扩展性。Exchange transport provides extensibility through the Microsoft Exchange Server Transport Agents SDK. SDK Exchange版本允许第三方实现以下预定义类:The Exchange version of the SDK allows third parties to implement the following predefined classes:

  • SmtpReceiveAgentSmtpReceiveAgent
  • RoutingAgentRoutingAgent
  • DeliveryAgentDeliveryAgent

在遵照 SDK 中的库时,生成的程序集会向 Exchange 注册,这将在 SMTP 会话或邮件处理的特定阶段加载代理并调用其事件处理程序。When complied against libraries in the SDK, the resulting assemblies are registered with Exchange, which loads the agents and invokes their event handlers during specific stages of the SMTP sessions or message processing. 这些阶段或事件,是代理定义的一部分。These stages, or events, are part of the agent definitions. 代理注册信息存储在 XML 配置文件中。The agent registration information is stored in an XML configuration file.

以下列表说明了在传输代理中Exchange。The following list explains the requirements for using transport agents in Exchange.

  • 邮箱服务器和边缘传输服务器上传输服务完全支持 SDK 中所有的预定义类。The Transport service on Mailbox servers and Edge Transport servers fully supports all the predefined classes in the SDK.
  • 前端传输服务仅支持 SDK 中的 SmtpReceiveAgent 类,并且第三方代理无法对 OnEndOfData SMTP 事件进行操作。The Front End Transport service only supports the SmtpReceiveAgent class in the SDK, and third-party agents can't operate on the OnEndOfData SMTP event.
  • 邮箱传输服务完全支持 SDK,因此不能使用邮箱传输服务中任何第三方代理。The Mailbox Transport service doesn't support the SDK at all, so you can't use any third-party agents in the Mailbox Transport service.

传输代理管理Transport agent management

传输代理 cmdlet 需要区分传输服务和前端传输服务。The transport agent cmdlets need to distinguish between the Transport service and the Front End Transport service. 传输代理管理 cmdlet 操作位于 agents.config 的配置文件 %ExchangeInstallPath%TransportRoles\SharedTransport Agent management cmdlets manipulate the configuration file agents.config located at %ExchangeInstallPath%TransportRoles\Shared.

有关详细信息,请参阅管理传输代理Exchange Server。For more information, see Manage transport agents in Exchange Server.

传输代理和 SMTP 事件Transport agents and SMTP events

传输代理使用 SMTP 事件。邮件在传输管道中移动时会触发这些事件。SMTP 事件使传输代理可以在 SMTP 会话期间以及通过组织路由邮件期间,在特定的时间点访问邮件。Transport agents use SMTP events. These events are triggered as messages move through the transport pipeline. SMTP events give transport agents access to messages at specific points during the SMTP conversation and during routing of messages through the organization.

SMTP 接收存在于邮箱服务器的前端传输服务、邮箱服务器和边缘传输服务器的传输服务以及邮箱服务器的邮箱传输传递服务中。SMTP Receive exists in the Front End Transport service on Mailbox servers, the Transport service on Mailbox servers and Edge Transport servers, and the Mailbox Transport Delivery service on Mailbox servers. 分类程序只存在于邮箱服务器和边缘传输服务器上的传输服务。The categorizer exists only in the Transport service on Mailbox servers and Edge Transport servers. 有关传输服务和分类程序的信息,请参阅 mail routing in Exchange ServerFor more information about transport services and the categorizer, see Mail routing in Exchange Server.

下表列出了可提供对传输管道中邮件的访问权限的 SMTP 事件。The following tables list the SMTP events that provide access to messages in the transport pipeline.

SMTP 接收事件SMTP Receive events



序列Sequence SMTP 事件SMTP event 说明Description
11 OnConnectEventOnConnectEvent 通过远程 SMTP 主机的初始连接触发此事件。This event is triggered by the initial connection from a remote SMTP host.
22 OnHeloCommandOnHeloCommand 远程 SMTP 主机发出命令 HELO 时将触发此事件。This event is triggered when the HELO command is issued by the remote SMTP host.
33 OnEhloCommandOnEhloCommand 远程 SMTP 主机发出命令 EHLO 时将触发此事件。This event is triggered when the EHLO command is issued by the remote SMTP host.
4 4 OnStartTlsCommandOnStartTlsCommand 远程 SMTP 主机发出命令 STARTTLS 时将触发此事件。This event is triggered when the STARTTLS command is issued by the remote SMTP host.
5 5 OnAuthCommandOnAuthCommand 远程 SMTP 主机发出命令 AUTH 时将触发此事件。This event is triggered when the AUTH command is issued by the remote SMTP host.
6 6 OnProcessAuthenticationOnProcessAuthentication 处理远程 SMTP 主机的身份验证时,将触发此事件。This event is triggered when authentication with the remote SMTP host is being processed.
7 7 OnEndOfAuthenticationOnEndOfAuthentication 远程 SMTP 主机完成身份验证时将触发此事件。This event is triggered when the remote SMTP host has completed authentication.
8 8 OnXSessionParamsCommandOnXSessionParamsCommand 远程 SMTP 主机发出命令 XSESSIONPARAMS 时将触发此事件。This event is triggered when the XSESSIONPARAMS command is issued by the remote SMTP host.
9 9 OnMailCommandOnMailCommand 远程 SMTP 主机发出命令 MAIL FROM 时将触发此事件。This event is triggered when the MAIL FROM command is issued by the remote SMTP host.
10 10 OnRcptToCommandOnRcptToCommand 远程 SMTP 主机发出命令 RCPT TO 时将触发此事件。This event is triggered when the RCPT TO command is issued by the remote SMTP host.
1111 OnDataCommandOnDataCommand 远程 SMTP 主机发出 (二进制) 或 (二) 命令时,将触发 DATA BDAT 此事件。This event is triggered when the DATA (text) or BDAT (binary data) command is issued by the remote SMTP host.
12 12 OnEndOfHeadersOnEndOfHeaders 远程 SMTP 主机完成提交电子邮件头时,将触发此事件。This event is triggered when the remote SMTP host has completed submitting the email message headers. 这由用于分隔邮件 () 正文的空行 <CRLF> 表示。This is indicated by a blank line (<CRLF>) that separates the message headers and the message body.
1313 OnProxyInboundMessageOnProxyInboundMessage 当前端传输服务将入站 SMTP 会话中继或代理到邮箱服务器上传输服务时,将触发此事件。This event is triggered when an inbound SMTP session is relayed or proxied by the Front End Transport service to the Transport service on a Mailbox server.
14 14 OnEndOfDataOnEndOfData 当远程 SMTP 主机发送数据结尾命令时,将触发此事件:This event is triggered when the remote SMTP host issues an end of data command:
  • 对于命令启动的文本 DATA 会话,数据结尾指示符为 <CRLF>.<CRLF>For text sessions started by the DATA command, the end of data indicator is <CRLF>.<CRLF>.
  • 对于命令启动的二进制 BDAT 会话,数据结尾指示符为 BDAT LASTFor binary sessions started by the BDAT command, the end of data indicator is BDAT LAST.
** OnHelpCommandOnHelpCommand 如果命令由远程 SMTP 主机发出 HELP ,将触发此事件。This event is triggered if the HELP command is issued by the remote SMTP host.
** OnNoopCommandOnNoopCommand 如果命令由远程 SMTP 主机发出 NOOP ,将触发此事件。This event is triggered if the NOOP command is issued by the remote SMTP host.
** OnRejectOnReject 如果接收 SMTP 主机向发送 SMTP 主机发出临时或永久传递状态通知 (也称为 DSN、未送达报告、NDR 或退回邮件) 代码,则触发此事件。This event is triggered if the receiving SMTP host issues a temporary or permanent delivery status notification (also known as a DSN, non-delivery report, NDR, or bounce message) code to the sending SMTP host.
** OnRsetCommandOnRsetCommand 如果发送 SMTP 主机发出命令 RSET ,将触发此事件。This event is triggered if the RSET command is issued by the sending SMTP host.
1515 OnDisconnectEventOnDisconnectEvent 接收或发送 SMTP 主机断开 SMTP 会话前,将触发此事件。This event is triggered by the disconnection of the SMTP conversation by either the receiving or sending SMTP host. 通常,远程 SMTP 主机 QUIT 发出命令时会发生此情况。Typically, this happens when the QUIT command is issued by the remote SMTP host.

** 在 OnConnectEvent 之后和 OnDisconnectEvent 之前,随时可以发生这些事件。** These events can occur at any time after OnConnectEvent but before OnDisconnectEvent.

分类程序事件Categorizer events



序列Sequence 分类程序事件Categorizer event 说明Description
11 OnSubmittedMessageOnSubmittedMessage 当邮件到达接收服务器传输服务中的提交队列时,将触发Exchange事件。This event is triggered when a message arrives in the Submission queue in the Transport service on the receiving Exchange server.
22 OnResolvedMessageOnResolvedMessage 在解析所有收件人之后到为每个收件人确定跃点之前的这段时间,将触发此事件。使用 OnResolvedMessage 路由事件,能够通过每个收件人的 SetRoutingOverride 方法使用后续事件覆盖默认的路由行为。 This event is triggered after all the recipients have been resolved, but before the next hop has been determined for each recipient. The OnResolvedMessage routing event enables subsequent events to override the default routing behavior by using the per-recipient SetRoutingOverride method.
33 OnRoutedMessageOnRoutedMessage 对邮件进行分类、扩展通讯组列表并且解析了收件人后,将会触发此事件。This event is triggered after messages have been categorized, distribution lists have been expanded, and recipients have been resolved.
4 4 OnCategorizedMessageOnCategorizedMessage 分类程序完成邮件处理时,将触发此事件。This event is triggered when the categorizer completes processing the message.

传输代理的优先级Priority of transport agents

传输代理对传输管道中的邮件的运行顺序有两个因素:Two factors determine the order that transport agents act on messages in the transport pipeline:

  1. 注册传输代理位置的 SMTP 事件,以及该 SMTP 事件遇到邮件的时间。The SMTP event where the transport agent is registered, and when that SMTP event encounters messages.
  2. 多个代理注册到同一个 SMTP 事件时,分配给传输代理的优先级值。最高优先级为 1。较高的整数值表示较低的代理优先级。The priority value that's assigned to the transport agent if there are multiple agents registered to the same SMTP event. The highest priority is 1. A higher integer value indicates a lower agent priority.

例如,假设您已配置以下传输代理:For example, suppose you configured the following transport agents:

  • 优先级为 1 的传输代理 A 与优先级为 2 的传输代理 C 被注册到 OnEndOfHeaders SMTP 事件。Transport Agent A with a priority of 1 and Transport Agent C with a priority of 2 are registered to the OnEndOfHeaders SMTP event.
  • 优先级为 4 的传输代理 B 被注册到 OnMailCommand SMTP 事件。Transport Agent B with a priority of 4 is registered to the OnMailCommand SMTP event.

因为 OnMailCommand 事件在 OnEndOfHeaders 事件之前遇到邮件,因此传输代理 B 最先应用于邮件。当邮件到达 OnEndOfHeaders 事件时,因为传输代理 A 优先级高于(整数值低于)传输代理 C,所以在传输代理 C 之前先应用传输代理 A。Transport Agent B is applied to messages first because the OnMailCommand event encounters messages before the OnEndOfHeaders event. When messages reach the OnEndOfHeaders event, Transport Agent A is applied before Transport Agent C because Transport Agent A has a higher priority (lower integer value) than Transport Agent C.

内置传输代理Built-in transport agents

Exchange Server包括许多内置的传输代理,这些代理提供反垃圾邮件、传输规则和日记等功能。Exchange Server includes many built-in transport agents that provide features such as anti-spam, transport rules and journaling. 邮箱服务器上大多数内置传输代理Exchange传输代理管理 cmdlet 不可见且不可管理。Most of the built-in transport agents on Exchange Mailbox servers are invisible and unmanageable by the transport agent management cmdlets. 实际上,所有可见且可管理的内置传输代理都位于邮箱服务器和边缘传输服务器的传输服务中。Virtually all of the built-in transport agents that are visible and manageable are in the Transport service on Mailbox servers and Edge Transport servers.

邮箱服务器上更令人关注的内置传输代理详见下表。请注意,此表不包括许多不可见且不受管理的传输代理。The more interesting built-in transport agents on Mailbox servers are described in the following table. Note that this table doesn't include many of the invisible and unmanageable transport agents.

邮箱服务器上令人关注的内置传输代理Interesting built-in transport agents on Mailbox servers


代理名Agent name 易于管理?Manageable? 优先级Priority SMTP 或分类程序事件SMTP or categorizer events
传输规则代理Transport Rule Agent Yes 11 OnResolvedMessageOnResolvedMessage
DLP 策略代理DLP Policy Agent Yes 22 OnResolvedMessageOnResolvedMessage
保留策略代理Retention Policy Agent Yes 33 OnResolvedMessageOnResolvedMessage
监管审核代理Supervisory Review Agent Yes 4 4 OnResolvedMessageOnResolvedMessage
恶意软件代理Malware Agent Yes 5 5 OnSubmittedMessageOnSubmittedMessage
文本消息路由代理Text Messaging Routing Agent Yes 6 6 OnSubmittedMessageOnSubmittedMessage
文本消息传递代理Text Messaging Delivery Agent Yes 7 7 不适用n/a
系统探测器放置 Smtp 代理System Probe Drop Smtp Agent Yes 8 8 OnEndOfHeadersOnEndOfHeaders
系统探测器放置路由代理System Probe Drop Routing Agent Yes 9 9 OnCategorizedMessageOnCategorizedMessage
日记代理Journal Agent No 无法配置Not configurable OnRoutedMessageOnRoutedMessage
日记报告解密代理Journal Report Decryption Agent No 无法配置Not configurable OnCategorizedMessageOnCategorizedMessage
RMS 解密代理RMS Decryption Agent No 无法配置Not configurable OnSubmittedMessageOnSubmittedMessage
RMS 加密代理RMS Encryption Agent No 无法配置Not configurable OnSubmittedMessageOnSubmittedMessage

OnRoutedMessageOnRoutedMessage

RMS 协议解密代理RMS Protocol Decryption Agent No 无法配置Not configurable OnEndOfDataOnEndOfData

边缘传输服务器上令人关注的内置传输代理Interesting built-in transport agents on Edge Transport servers

通过传输代理管理 cmdlet 或其他特定功能 cmdlet,边缘传输服务器上的大多数内置传输代理均可见且易管理。On Edge Transport servers, most of the built-in transport agents are visible and manageable by the transport agent management cmdlets or by other feature-specific cmdlets.

边缘传输服务器上更令人关注的内置传输代理详见下表。请注意,此表不包括不可见或不受管理的传输代理。The more interesting built-in transport agents on Edge Transport servers are described in the following table. Note that this table doesn't include invisible or unmanageable transport agents.




代理名Agent name 易于管理?Manageable? 优先级Priority SMTP 或分类程序事件SMTP or categorizer events
连接筛选代理Connection Filtering Agent Yes 11 OnConnectEventOnConnectEvent

OnMailCommandOnMailCommand

OnRcptCommandOnRcptCommand

OnEndOfHeadersOnEndOfHeaders

地址重写入站代理Address Rewriting Inbound Agent Yes 22 OnRcptCommandOnRcptCommand

OnEndOfHeadersOnEndOfHeaders

边缘规则代理Edge Rule Agent Yes 33 OnEndOfDataOnEndOfData
内容筛选器代理*Content Filter Agent* Yes 4 4 OnEndOfDataOnEndOfData
发件人 ID 代理*Sender ID Agent* Yes 5 5 OnEndOfHeadersOnEndOfHeaders
发件人筛选器代理*Sender Filter Agent* Yes 6 6 OnMailCommandOnMailCommand

OnEndOfHeadersOnEndOfHeaders

收件人筛选器代理Recipient Filter Agent Yes 7 7 OnRcptCommandOnRcptCommand
协议分析代理*Protocol Analysis Agent* Yes 8 8 OnConnectEventOnConnectEvent

OnEndOfHeadersOnEndOfHeaders

OnEndOfDataOnEndOfData

OnRejectOnReject

OnRsetCommandOnRsetCommand

OnDisconnectEventOnDisconnectEvent

附件筛选代理Attachment Filtering Agent Yes 9 9 OnEndOfDataOnEndOfData
地址重写出站代理Address Rewriting Outbound Agent Yes 10 10 OnSubmittedMessageOnSubmittedMessage

OnRoutedMessageOnRoutedMessage

* 您还可以在邮箱服务器上安装和配置这些反垃圾邮件代理。* You can also install and configure these anti-spam agents on Mailbox servers. 有关详细信息,请参阅在邮箱服务器上启用反垃圾邮件功能For more information, see Enable antispam functionality on Mailbox servers.

解决传输代理问题Troubleshoot transport agents

为了帮助您解决传输代理问题,可以使用以下功能:To help you troubleshoot issues with transport agents, you can use the following features:

  • Get-TransportPipeline: 此 cmdlet 显示 SMTP 事件以及服务器上遇到邮件的相应传输Exchange代理。Get-TransportPipeline: This cmdlet shows the SMTP events and the corresponding transport agents that encounter messages on the Exchange server. 有关详细信息,请参阅在传输管道中查看传输Exchange Server。For more information, see View transport agents in the transport pipeline in Exchange Server.

  • 管道跟踪:管道跟踪在邮件遇到每个传输代理之前和之后创建邮件的准确快照。Pipeline Tracing: Pipeline tracing creates an exact snapshot of a message before and after it encounters each transport agent. 这使您可以找到导致意外结果的传输代理。This allows you to find a transport agent that's causing unexpected results. 有关详细信息,请参阅 管道跟踪For more information, see Pipeline tracing.