| Internet-Draft | MTA Hooks | May 2026 |
| De Gennaro | Expires 9 November 2026 | [Page] |
This document specifies MTA Hooks, an HTTP-based protocol enabling Mail Transfer Agents (MTAs) to delegate message processing decisions to external services. MTA Hooks provides a modern alternative to legacy mail filtering protocols by leveraging ubiquitous HTTP infrastructure, supporting both JSON and CBOR serialization, and offering fine-grained capability negotiation. The protocol supports both inbound message reception and outbound message delivery scenarios, allowing external scanners to inspect messages, modify content, and influence routing decisions at various stages of mail processing.¶
This Internet-Draft is submitted in full conformance with the provisions of BCP 78 and BCP 79.¶
Internet-Drafts are working documents of the Internet Engineering Task Force (IETF). Note that other groups may also distribute working documents as Internet-Drafts. The list of current Internet-Drafts is at https://datatracker.ietf.org/drafts/current/.¶
Internet-Drafts are draft documents valid for a maximum of six months and may be updated, replaced, or obsoleted by other documents at any time. It is inappropriate to use Internet-Drafts as reference material or to cite them other than as "work in progress."¶
This Internet-Draft will expire on 9 November 2026.¶
Copyright (c) 2026 IETF Trust and the persons identified as the document authors. All rights reserved.¶
This document is subject to BCP 78 and the IETF Trust's Legal Provisions Relating to IETF Documents (https://trustee.ietf.org/license-info) in effect on the date of publication of this document. Please review these documents carefully, as they describe your rights and restrictions with respect to this document. Code Components extracted from this document must include Revised BSD License text as described in Section 4.e of the Trust Legal Provisions and are provided without warranty as described in the Revised BSD License.¶
Mail Transfer Agents require extensible mechanisms to integrate with external services for spam filtering, virus scanning, policy enforcement, and compliance monitoring. While legacy protocols such as the Milter protocol have served this purpose, they present challenges in modern deployments including proprietary wire formats, limited tooling, and operational complexity.¶
MTA Hooks addresses these challenges by defining an HTTP-based protocol for mail processing delegation. The protocol leverages the widespread availability of HTTP client and server implementations, standard serialization formats, and established operational practices for HTTP services.¶
MTA Hooks achieves broad deployment compatibility by building upon standard HTTP semantics and methods, allowing implementers to leverage existing HTTP client and server libraries. The protocol supports both JSON and CBOR serialization to accommodate environments with different performance and parsing requirements. Capability negotiation during registration enables graceful feature discovery and forward compatibility as the protocol evolves. Mandatory transport encryption protects message content in transit, while the authentication mechanism remains pluggable to integrate with diverse deployment environments. The HTTP foundation ensures compatibility with existing operational infrastructure including load balancers, reverse proxies, and monitoring systems.¶
MTA Hooks supports two primary use cases: inbound processing during message reception from remote clients, and outbound processing during message delivery to remote servers. Both scenarios follow a consistent request-response pattern where the MTA invokes the registered hook endpoints at configured processing stages.¶
The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in BCP 14 [RFC2119] [RFC8174] when, and only when, they appear in all capitals, as shown here.¶
The following terms are used throughout this document:¶
MTA (Mail Transfer Agent): A software component responsible for transferring electronic mail messages between hosts, as described in [RFC5321].¶
Hook Endpoint: An HTTP server endpoint that receives hook invocations from an MTA and returns processing instructions.¶
Scanner: A service that registers with an MTA to receive hook invocations. Scanners perform functions such as spam filtering, virus scanning, or policy enforcement. The terms "scanner" and "hook endpoint" are used interchangeably when referring to the service receiving hook requests.¶
Registration: The process by which an MTA establishes a session with a scanner, including capability negotiation and assignment of a registration identifier.¶
Inbound Processing: Hook invocation during message reception, when the MTA accepts a message from a remote SMTP client.¶
Outbound Processing: Hook invocation during message delivery, when the MTA transmits a message to a remote SMTP server.¶
Stage: A specific point in mail processing at which the MTA invokes registered hooks. Different stages provide access to different message properties.¶
Action: An instruction from a scanner indicating how the MTA should proceed with message processing.¶
Modification: A change to message properties requested by a scanner, expressed as operations on the hook request object.¶
This specification defines several object types used throughout the protocol. The following primitive types are used:¶
A JSON string value.¶
An integer in the range -2^53+1 <= value <= 2^53-1.¶
An integer in the range 0 <= value <= 2^53-1.¶
A JSON boolean value (true or false).¶
A string in "date-time" format as defined in [RFC3339], where the time-offset component MUST be "Z" (UTC time). For example, "2024-12-21T15:30:00Z".¶
MTA Hooks defines a request-response protocol where the MTA acts as an HTTP client and scanners act as HTTP servers. During mail processing, the MTA constructs a request containing message properties and context information, transmits it to registered scanner endpoints, and processes the response to determine subsequent actions.¶
The protocol architecture consists of three primary components:¶
The MTA, which initiates HTTP requests to scanner endpoints at configured processing stages.¶
Scanner services, which receive requests, perform analysis, and return responses containing actions and modifications.¶
A registration mechanism through which the MTA declares its intent to send specific stages and properties and the scanner returns a registration identifier used on subsequent invocations.¶
+-------+ +---------+ | | 1. Discovery Request | | | |----------------------------->| | | | 2. Discovery Response | | | |<-----------------------------| | | | | | | | 3. Registration Request | | | MTA |----------------------------->| Scanner | | | 4. Registration Response | | | |<-----------------------------| | | | | | | | 5. Hook Request | | | |----------------------------->| | | | 6. Hook Response | | | |<-----------------------------| | +-------+ +---------+
The protocol flow proceeds as follows:¶
The MTA discovers scanner capabilities by requesting the well-known discovery endpoint.¶
The scanner returns a discovery document describing supported stages, actions, and configuration options.¶
The MTA submits a registration request to the scanner specifying the stages, properties, and filters it will deliver.¶
The scanner validates the request, returns a registration identifier, and confirms the negotiated capabilities.¶
During mail processing, the MTA invokes the scanner's hook endpoint with message properties and context.¶
The scanner returns a response containing an action and optional modifications.¶
Requests and responses are serialized using either JSON [RFC8259] or CBOR [RFC8949]. The serialization format is negotiated during registration and indicated via HTTP Content-Type headers.¶
For JSON serialization, the Content-Type header MUST be "application/json". For CBOR serialization, the Content-Type header MUST be "application/cbor".¶
Binary data handling differs between formats. In JSON serialization, binary content such as message body parts MUST be encoded using Base64. In CBOR serialization, binary content SHOULD be transmitted as raw byte strings.¶
MTA Hooks defines processing stages for both inbound and outbound message handling. Scanners subscribe to specific stages during registration and receive invocations only for subscribed stages.¶
Inbound stages correspond to SMTP protocol events during message reception:¶
connect: Invoked when a remote client establishes a connection, before any SMTP commands are exchanged.¶
ehlo: Invoked after the client sends EHLO or HELO command.¶
mail: Invoked after each MAIL FROM command.¶
rcpt: Invoked after each RCPT TO command. This stage may be invoked multiple times per transaction.¶
data: Invoked after the complete message has been received, following the DATA command and message content.¶
Outbound stages correspond to delivery events during message transmission:¶
delivery: Invoked after a delivery attempt completes for all recipients, regardless of success or failure.¶
defer: Invoked only when at least one recipient delivery cannot be completed and requires retry.¶
dsn: Invoked when the MTA generates a Delivery Status Notification of any type.¶
For outbound stages, the hook is invoked once after delivery attempts for all recipients in a given delivery batch have completed. The scanner receives the delivery status for each recipient and may modify per-recipient handling.¶
During inbound processing, the MTA invokes registered hooks as it receives messages from remote SMTP clients. This corresponds to traditional mail filtering scenarios where external services inspect incoming mail for spam, viruses, or policy violations.¶
The inbound flow proceeds through SMTP protocol stages:¶
A remote client connects to the MTA.¶
The MTA invokes hooks registered for the "connect" stage.¶
The client sends EHLO/HELO; the MTA invokes "ehlo" stage hooks.¶
The client sends MAIL FROM; the MTA invokes "mail" stage hooks.¶
The client sends one or more RCPT TO commands; the MTA invokes "rcpt" stage hooks for each.¶
The client sends DATA and message content; the MTA invokes "data" stage hooks.¶
At each stage, scanners may instruct the MTA to accept, reject, or modify the transaction.¶
When multiple scanners are registered for the same stage, the MTA invokes them sequentially in an implementation-defined order. Each scanner's response affects the request seen by subsequent scanners.¶
The scanner chain terminates early when a scanner returns a terminal action:¶
Non-terminal actions ("accept", "quarantine" for inbound; "continue" for outbound) allow the chain to proceed. Each scanner sees the prior scanner's modifications, including any change to the "/action" path, and MAY further modify it.¶
Action precedence within a chain proceeds from least to most restrictive: "accept" is the weakest, "quarantine" is stronger, and the terminal actions ("reject", "discard", "disconnect") are the strongest. By default, the MTA SHOULD reject responses that downgrade the action to a weaker value (for example, setting "/action" from "quarantine" to "accept"). Implementations MAY provide configuration to permit such downgrades for specific trusted scanners, but this MUST NOT be the default.¶
Implementations SHOULD provide configuration options for:¶
Scanner invocation order (priority-based or explicit ordering)¶
Per-scanner trust to permit action downgrades¶
Logging of chain termination events for operational visibility¶
Example chain behavior:¶
During outbound processing, the MTA invokes registered hooks as it delivers messages to remote SMTP servers. This supports use cases including delivery logging, compliance monitoring, and routing decisions.¶
The outbound flow proceeds as follows:¶
The MTA selects a queued message for delivery and identifies the recipients due for delivery at this time.¶
The MTA attempts delivery to all selected recipients.¶
After all attempts in this delivery job complete, the MTA invokes hooks registered for the "delivery" stage.¶
If any recipient requires retry, the MTA invokes "defer" stage hooks.¶
If the MTA generates a DSN, it invokes "dsn" stage hooks before sending.¶
A delivery job represents a single processing cycle where the MTA retrieves a message from the queue and attempts delivery to one or more recipients. The specific batching of recipients into delivery jobs is implementation-defined and may depend on factors such as destination domain, connection reuse, or queue configuration. The "delivery" stage hook is invoked once per delivery job after all recipient attempts within that job have completed.¶
Scanners may modify per-recipient delivery status, suppress DSN generation, or alter retry scheduling.¶
Scanners communicate changes through modifications to the hook request object, expressed as set, add, and delete operations on JSON Pointers [RFC6901]. The complete modification semantics, including operation ordering and error handling, are defined in Section 6.¶
MTAs discover scanner capabilities through a well-known HTTP endpoint. Discovery is OPTIONAL; scanner endpoints MAY alternatively be configured manually.¶
Scanners that support discovery MUST expose a discovery document at the path "/.well-known/mta-hooks". The MTA retrieves this document using an HTTP GET request.¶
The discovery endpoint MUST support JSON serialization. Support for CBOR serialization is OPTIONAL.¶
The discovery document is a JSON or CBOR object containing the following fields:¶
String
The protocol version. This specification defines version "1.0".¶
DiscoveryEndpoints
URLs for protocol operations.¶
String[]
Supported serialization formats. Valid values are "json" and "cbor".¶
DiscoveryCapabilities
Supported protocol capabilities.¶
DiscoveryLimits|null
Operational limits, or null if no specific limits are advertised.¶
String[]|null
Supported protocol extensions. Extension identifiers SHOULD use a reverse domain name prefix for vendor-specific extensions.¶
A DiscoveryEndpoints object has the following properties:¶
String
URL path for submitting registration requests.¶
String
URL path template for deregistration, with "{registration_id}" placeholder.¶
A DiscoveryCapabilities object has the following properties:¶
DirectionCapabilities|null
Inbound processing capabilities, or null if inbound processing is not supported.¶
DirectionCapabilities|null
Outbound processing capabilities, or null if outbound processing is not supported.¶
A DirectionCapabilities object has the following properties:¶
String[]
Supported stages for this processing direction.¶
String[]
Supported actions that scanners may request.¶
String[]
JSON Pointers for properties the MTA can include in hook requests.¶
String[]
JSON Pointers for properties scanners may modify.¶
A DiscoveryLimits object has the following properties:¶
UnsignedInt|null
Maximum message size in bytes the scanner accepts.¶
UnsignedInt|null
Maximum concurrent registrations.¶
UnsignedInt|null
Default timeout in milliseconds for hook invocations.¶
The fetchProperties and updateProperties arrays contain JSON Pointers as defined in [RFC6901]. Each pointer identifies a property within
the hook request structure that the MTA supports including or that scanners may modify. For example, "/envelope/from/address" refers to the sender's email address within the envelope object.¶
{
"version": "1.0",
"endpoints": {
"registration": "/v1/hooks/register",
"deregistration": "/v1/hooks/register/{registration_id}"
},
"serialization": ["json", "cbor"],
"capabilities": {
"inbound": {
"stages": ["connect", "ehlo", "mail", "rcpt", "data"],
"actions": ["accept", "reject", "discard",
"quarantine", "disconnect"],
"fetchProperties": ["/envelope", "/message", "/rawMessage",
"/server", "/tls", "/auth", "/senderAuth",
"/client", "/stage", "/action",
"/timestamp","/response", "/protocol",
"/queue"],
"updateProperties": ["/envelope", "/message", "/rawMessage",
"/action", "/response"]
},
"outbound": {
"stages": ["delivery", "defer", "dsn"],
"actions": ["continue", "cancel"],
"fetchProperties": ["/envelope", "/message", "/rawMessage",
"/server", "/queue", "/stage", "/action",
"/timestamp", "/protocol"],
"updateProperties": ["/envelope/to", "/action", "/message",
"/rawMessage"]
}
},
"limits": {
"maxMessageSize": 52428800,
"maxRegistrations": 64,
"timeoutMs": 30000
},
"extensions": ["x-vendor-feature"]
}
¶
Discovery is OPTIONAL. Administrators MAY configure scanner endpoints manually, including capability restrictions and authentication credentials. Manual configuration may be necessary in environments where the well-known endpoint is not accessible or where policy requires explicit configuration.¶
The MTA registers with each configured scanner to negotiate capabilities and establish a session identifier used on subsequent hook invocations. Registration creates state at the scanner that remains active until explicit deregistration or expiration.¶
The MTA acts as the HTTP client throughout: it discovers scanner capabilities, submits the registration request, manages the lifecycle of the registration, and invokes hooks. The MTA does not expose any HTTP server for scanner-to-MTA communication. Scanner endpoints, credentials, and per-scanner subscription policy are provisioned at the MTA out of band; this specification does not define the provisioning channel.¶
The MTA submits a registration request via HTTP POST to the registration endpoint advertised in the scanner's discovery document, or configured manually. The request body contains a JSON or CBOR object with the following fields:¶
String
Human-readable name identifying the MTA instance, suitable for display in scanner administrative interfaces.¶
String|null
MTA software version string.¶
UnsignedInt|null
Hook invocation timeout the MTA will enforce, in milliseconds. The scanner MAY use this value to size internal queues and processing budgets, but it does not affect MTA behavior.¶
UTCDate|null
Requested registration expiration timestamp. The scanner MAY assign a different expiration based on policy.¶
String
Requested serialization format for hook requests. MUST be a value from the scanner's advertised serialization list.¶
StageSubscription|null
Inbound hook configuration. Omit or set to null if not subscribing to inbound stages.¶
StageSubscription|null
Outbound hook configuration. Omit or set to null if not subscribing to outbound stages.¶
FilterOperator|FilterCondition|null
Filter the MTA will apply locally before invoking the scanner. Disclosed for transparency so the scanner can interpret the message stream it receives. Uses filter syntax from Section 5.5 of [RFC8620].¶
String[String]|null
Arbitrary key-value pairs for operational metadata.¶
A StageSubscription object has the following properties:¶
String[]
Stages to subscribe to. MUST be a subset of the MTA's supported stages for this direction.¶
String[]|null
JSON Pointers specifying message properties to receive. A value of null requests all supported properties.¶
At least one of "inbound" or "outbound" MUST be present and non-null in the registration request.¶
The filter field uses the FilterOperator and FilterCondition syntax defined in Section 5.5 of [RFC8620]. A FilterOperator combines multiple conditions using AND, OR, or NOT logic. A FilterCondition specifies criteria that a message must match.¶
Filter conditions follow Section 4.4.1 of [RFC8621] with the following exclusions. The conditions listed below depend on mailbox state, thread state, or message-arrival timing not applicable to MTA processing, and are NOT supported:¶
inMailbox¶
inMailboxOtherThan¶
before¶
after¶
allInThreadHaveKeyword¶
someInThreadHaveKeyword¶
noneInThreadHaveKeyword¶
hasKeyword¶
notKeyword¶
All other filter conditions defined in Section 4.4.1 of [RFC8621] are permitted by this specification, including text-matching conditions such as "from", "to", "cc", "bcc", "subject", "body", "header", and "text", and the size conditions "minSize" and "maxSize". However, support for specific conditions is determined by the scanner implementation. If the registration request specifies a filter condition that the scanner does not support, the registration MUST be rejected with an UNSUPPORTED_FILTER error.¶
The following additional conditions are defined for envelope filtering:¶
String
Matches if the MAIL FROM address matches the given value. The value MAY include wildcards using the "*" character, which matches zero or more characters.¶
String
Matches if any RCPT TO address matches the given value. The value MAY include wildcards using the "*" character, which matches zero or more characters.¶
Filters apply only to the "data" stage for content-based conditions (those examining message headers or body). For the "mail" and "rcpt" stages, only envelopeFrom and envelopeTo conditions are evaluated; other conditions are ignored for these stages. Messages or envelope commands not matching the filter do not trigger hook invocations.¶
POST /v1/hooks/register HTTP/1.1
Host: scanner.example.com
Content-Type: application/json
Authorization: Bearer eyJhbGciOiJIUzI1NiIs...
{
"name": "Acme MTA mx1",
"version": "2.1.0",
"timeoutMs": 25000,
"expiresAt": "2025-12-21T15:30:00Z",
"serialization": "json",
"inbound": {
"stages": ["data"],
"properties": ["/message", "/envelope", "/senderAuth"]
},
"outbound": {
"stages": ["delivery"],
"properties": null
},
"filter": {
"operator": "OR",
"conditions": [
{"from": "*@external.example.com"},
{"envelopeFrom": "*@partner.example.org"}
]
},
"metadata": {
"operator": "acme-mail",
"environment": "production",
"instance": "mx1"
}
}
¶
Upon successful registration, the scanner returns HTTP status 201 Created with a response body containing:¶
String
Unique identifier for this registration. The identifier MUST consist of ASCII alphanumeric characters plus hyphen (-), underscore (_), and colon (:), with a maximum length of 255 characters.¶
String
Registration status. Values are "active" or "suspended".¶
UTCDate
Timestamp of registration creation.¶
UTCDate|null
Timestamp when registration expires, or null if no expiration is set.¶
String
Absolute or relative URL where the MTA MUST send hook invocations for this registration. A relative URL is resolved against the registration endpoint URL. The scanner MAY return a different path per registration to multiplex tenants.¶
NegotiatedCapabilities
Final negotiated capabilities representing the intersection of the MTA's request and the scanner's support.¶
RegistrationEndpoints
URLs for managing this registration.¶
A NegotiatedCapabilities object has the following properties:¶
String
Confirmed serialization format.¶
NegotiatedSubscription|null
Confirmed inbound configuration, or null if not registered for inbound processing.¶
NegotiatedSubscription|null
Confirmed outbound configuration, or null if not registered for outbound processing.¶
A NegotiatedSubscription object has the following properties:¶
A RegistrationEndpoints object has the following properties:¶
HTTP/1.1 201 Created
Content-Type: application/json
Location: /v1/hooks/register/reg_7a3b9c2e-4d5f-6a7b-8c9d-0e1f2a3b4c5d
{
"registrationId": "reg_7a3b9c2e-4d5f-6a7b-8c9d-0e1f2a3b4c5d",
"status": "active",
"createdAt": "2024-12-21T15:30:00Z",
"expiresAt": "2025-12-21T15:30:00Z",
"hookEndpoint": "/v1/hooks/invoke/reg_7a3b9c2e-4d5f-6a7b-8c9d-0e1f2a3b4c5d",
"negotiated": {
"serialization": "json",
"inbound": {
"stages": ["data"],
"properties": ["/message", "/envelope", "/senderAuth"]
},
"outbound": {
"stages": ["delivery"],
"properties": ["/message", "/envelope", "/queue", "/server"]
}
},
"endpoints": {
"deregistration":
"/v1/hooks/register/reg_7a3b9c2e-4d5f-6a7b-8c9d-0e1f2a3b4c5d",
"status":
"/v1/hooks/register/reg_7a3b9c2e-4d5f-6a7b-8c9d-0e1f2a3b4c5d/status"
}
}
¶
The MTA MUST authenticate to the scanner on every registration, status, and deregistration request. The same credentials are used for hook invocations (Section 5.2). The specific mechanism is out of scope for this specification; implementations SHOULD support at least one of:¶
Bearer tokens via the HTTP Authorization header¶
Mutual TLS with client certificate verification¶
HMAC-based pre-shared key authentication¶
Credentials are issued by the scanner operator to each MTA permitted to register, through an out-of-band provisioning channel. The scanner MUST verify the MTA's identity from the presented credentials and reject unauthenticated or unauthorized requests. See Section 9 for deployment guidance.¶
The MTA MAY query a registration's status via HTTP GET to the status endpoint returned during registration.¶
GET /v1/hooks/register/reg_7a3b9c2e-4d5f-6a7b-8c9d-0e1f2a3b4c5d/status \ HTTP/1.1 Host: scanner.example.com Authorization: Bearer eyJhbGciOiJIUzI1NiIs...¶
The response contains registration status and optional statistics:¶
String
The registration identifier.¶
String
Current status: "active", "suspended", or "deregistered".¶
UTCDate|null
Timestamp of creation.¶
UTCDate|null
Timestamp of expiration.¶
UTCDate|null
Timestamp of most recent hook invocation.¶
RegistrationStatistics|null
Operational statistics.¶
HealthStatus|null
Health check status.¶
A RegistrationStatistics object has the following properties:¶
InvocationCounts
Invocation counts.¶
InvocationCounts
Error counts with the same time period structure as invocations.¶
Number
Average response time in milliseconds.¶
An InvocationCounts object has the following properties:¶
UnsignedInt
Total count since registration.¶
UnsignedInt
Count in past 24 hours.¶
UnsignedInt
Count in past 7 days.¶
UnsignedInt
Count in past 30 days.¶
A HealthStatus object has the following properties:¶
HTTP/1.1 200 OK
Content-Type: application/json
{
"registrationId": "reg_7a3b9c2e-4d5f-6a7b-8c9d-0e1f2a3b4c5d",
"status": "active",
"createdAt": "2024-12-21T15:30:00Z",
"expiresAt": "2025-12-21T15:30:00Z",
"lastInvocation": "2024-12-21T16:42:18Z",
"statistics": {
"invocations": {
"total": 15482,
"last24h": 3241,
"last7d": 10234,
"last30d": 43210
},
"errors": {
"total": 32,
"last24h": 5,
"last7d": 12,
"last30d": 28
},
"averageResponseMs": 45
},
"health": {
"status": "healthy",
"lastCheck": "2024-12-21T16:44:00Z",
"consecutiveFailures": 0
}
}
¶
Registrations MAY have an expiration time set by the scanner based on policy. The MTA MUST re-register before expiration to maintain continuous service. Re-registration follows the same process as initial registration and requires full capability renegotiation; the scanner SHOULD issue a fresh registration identifier on renewal and SHOULD continue to honor hook invocations carrying the prior identifier for a brief grace period to avoid races.¶
The MTA SHOULD monitor its registration status (either by tracking expiresAt locally or by polling the status endpoint) and initiate re-registration before expiration.¶
The MTA deregisters by sending an HTTP DELETE request to the deregistration endpoint.¶
DELETE /v1/hooks/register/reg_7a3b9c2e-4d5f-6a7b-8c9d-0e1f2a3b4c5d \ HTTP/1.1 Host: scanner.example.com Authorization: Bearer eyJhbGciOiJIUzI1NiIs...¶
Upon successful deregistration, the scanner returns HTTP status 200 with confirmation:¶
HTTP/1.1 200 OK
Content-Type: application/json
{
"registrationId": "reg_7a3b9c2e-4d5f-6a7b-8c9d-0e1f2a3b4c5d",
"status": "deregistered",
"deregisteredAt": "2024-12-21T16:45:00Z"
}
¶
After deregistration, the MTA MUST NOT send further hook invocations referencing the deregistered registration identifier.¶
Hook invocations that are in-flight at the time of deregistration MAY complete normally. The scanner SHOULD accept and respond to hook requests that arrive during or shortly after deregistration processing, as network latency may cause requests dispatched before deregistration to arrive afterward.¶
Once deregistration completes, the MTA MUST NOT initiate new hook invocations to the deregistered scanner's hook endpoint. The scanner SHOULD allow a brief grace period (implementation-defined, but typically a few seconds) for in-flight requests before considering the deregistration fully complete.¶
The scanner MAY terminate a registration by setting its status to "deregistered" and returning an error to subsequent MTA requests against the registration. Implementation-specific policies govern when scanners do this, for example after detecting that the MTA has stopped sending hook requests for an extended period. The scanner SHOULD log such terminations and the MTA SHOULD treat any 404 REGISTRATION_NOT_FOUND response on a previously-active registration as a signal to re-register.¶
When processing reaches a stage for which scanners are registered, the MTA constructs a hook request and transmits it to each registered scanner's hook endpoint.¶
Hook requests are transmitted via HTTP POST to the hook endpoint URL returned in the registration response. The Content-Type header indicates the serialization format negotiated during registration.¶
The following request headers apply to hook invocations:¶
REQUIRED. The registration identifier returned during registration. The scanner uses this to correlate the request with negotiated capabilities and to multiplex registrations sharing a hook endpoint host.¶
REQUIRED. A unique identifier for this logical hook invocation. The MTA MUST keep this value stable across retries of the same invocation. Scanners SHOULD deduplicate on this identifier to remain idempotent under retry. The value MUST be a string of at most 128 ASCII characters drawn from the unreserved set defined in [RFC3986].¶
REQUIRED. See Section 5.2.¶
The request body contains a JSON or CBOR object with properties determined by the registration. The following sections describe available properties organized by category.¶
The MTA MUST authenticate every hook invocation using the credentials provisioned for the registration. Scanners MUST verify the credentials and reject any unauthenticated hook request with HTTP 401. Scanners SHOULD also verify that the credentials are bound to the registration identified by X-MTA-Hooks-Registration; a mismatch MUST be rejected with HTTP 403.¶
The same authentication mechanisms supported for registration (Section 4.3) apply to hook invocations.¶
The following properties are available for both inbound and outbound processing:¶
String
The current processing stage.¶
String
The action the MTA will perform if no scanner modifications occur. For inbound processing, values are "accept", "reject", "discard", "quarantine", or "disconnect". For outbound processing, values are "continue" or "cancel".¶
Envelope
The message envelope containing sender and recipient information.¶
Object|null
A structured representation of the email message based on the Email object defined in Section 4 of [RFC8621].¶
String|null
The complete message in Internet Message Format as defined in [RFC5322]. In JSON serialization, the value is Base64-encoded. In CBOR serialization, the value is a raw byte string.¶
UTCDate
Timestamp when the current stage began.¶
ProtocolInfo|null
Protocol information.¶
QueueInfo|null
Queue information.¶
ServerInfo|null
Information about the MTA.¶
An Envelope object has the following properties:¶
EnvelopeAddress
Sender information from MAIL FROM command.¶
EnvelopeAddress[]|DeliveryRecipient[]
Recipient information from RCPT TO commands. For inbound processing, this is an array of EnvelopeAddress objects. For outbound processing, this is an array of DeliveryRecipient objects.¶
An EnvelopeAddress object represents an address in the message envelope and has the following properties:¶
String|null
The email address. For MAIL FROM, this MAY be null to represent the null reverse-path. For RCPT TO, this MUST NOT be null.¶
String[String]
SMTP parameters associated with the address as key-value pairs. Common parameters include ORCPT, ENVID, and other DSN-related parameters defined in [RFC3461].¶
For outbound processing, recipient objects include additional delivery status fields described in Section 5.10.¶
A QueueInfo object has the following properties:¶
String
Unique queue identifier for this message within this MTA. The identifier MUST be unique for the lifetime of the message in the queue and SHOULD remain stable across hook invocations for the same queued message.¶
The message property contains a structured representation of the email message based on the Email object defined in Section 4 of [RFC8621]. The following differences from the JMAP Email object apply:¶
Metadata properties defined in Section 4.1.1 of [RFC8621] are not included, with the exception of the "size" property which MAY be present.¶
The blobId property is replaced by a blob property containing the actual content. In JSON serialization, blob values are Base64-encoded strings. In CBOR serialization, blob values are raw byte strings.¶
Property availability depends on the processing stage and MTA capabilities. At early stages such as "connect" or "ehlo", message properties are not available.¶
The rawMessage property contains the complete message in Internet Message Format as defined in [RFC5322], including all MIME parts
and attachments. In JSON serialization, the value is Base64-encoded. In CBOR serialization, the value is a raw byte string.¶
The rawMessage property represents the entire message as stored or received by the MTA. When present, it provides byte-exact access to the message content, which is necessary for operations such as cryptographic signature verification.¶
Scanners MAY request both message and rawMessage properties. If a scanner's response modifies both properties, only rawMessage modifications are applied; message modifications are ignored.¶
The raw message content MUST NOT appear within the message property as a blob value. The message property contains only the structured parsed representation with individual body part contents available via bodyValues, while rawMessage contains the complete unparsed message.¶
The message property provides a structured, parsed representation suitable for:¶
Header inspection and modification¶
Recipient analysis¶
Content-type aware body part processing¶
Efficient access to specific message components¶
The rawMessage property provides the complete RFC 5322 message suitable for:¶
Cryptographic verification (DKIM signature validation)¶
Archival or compliance logging¶
Processing that requires byte-exact message content¶
Forwarding or re-injection without modification¶
Scanners that need both structured access and raw content SHOULD request both properties. When modifying messages, scanners SHOULD prefer structured modifications via the message property unless byte-exact control is required. Modifications to rawMessage require the scanner to produce a complete, valid RFC 5322 message.¶
A ServerInfo object has the following properties:¶
A ProtocolInfo object has the following properties:¶
String
MTA Hooks protocol version.¶
The following properties are available only during inbound processing:¶
SmtpResponse|null
The SMTP response the MTA would send if no scanner modifications occur.¶
ClientInfo|null
Information about the connecting SMTP client.¶
SenderAuthentication|null
Results of sender authentication checks.¶
SmtpAuthentication|null
SMTP authentication information, if the client authenticated.¶
TlsInfo|null
TLS connection information.¶
An SmtpResponse object represents an SMTP response and has the following properties:¶
A ClientInfo object has the following properties:¶
String
Client IP address.¶
UnsignedInt
Client port number.¶
String|null
PTR record for client IP, if available.¶
String
EHLO or HELO string sent by client.¶
UnsignedInt|null
Autonomous System Number for client IP, if available.¶
String|null
ISO 3166-1 alpha-2 country code for client IP, if available.¶
UnsignedInt|null
Number of concurrent connections from this client.¶
A TlsInfo object has the following properties:¶
String
TLS protocol version (e.g., "TLSv1.3").¶
String
Cipher suite name.¶
UnsignedInt
Cipher key length in bits.¶
String|null
Client certificate issuer, if a client certificate was presented.¶
String|null
Client certificate subject, if a client certificate was presented.¶
A SenderAuthentication object has the following properties:¶
String|null
String|null
String|null
String|null
ARC verification result.¶
String|null
Authentication result values follow the conventions established in the respective specifications.¶
An SmtpAuthentication object has the following properties:¶
The following properties are available only during outbound processing.¶
For outbound processing, the queue property uses an OutboundQueueInfo object, which extends QueueInfo with additional fields:¶
For outbound processing, each recipient in envelope.to is represented as a DeliveryRecipient object.¶
A DeliveryRecipient object extends EnvelopeAddress with delivery status information and has the following properties:¶
String
The recipient email address.¶
String[String]
SMTP parameters associated with the address as key-value pairs.¶
String
The delivery status for this recipient. Values are:¶
"pending": The MTA has not yet attempted delivery for this recipient.¶
"delivered": Delivery succeeded.¶
"deferred": Delivery failed transiently and will be retried per the schedule in nextAttemptAt.¶
"failed": Delivery failed permanently and the MTA will generate a failure DSN.¶
"failed-silent": Delivery is suppressed and the MTA MUST NOT generate any DSN for this recipient. Typically set by a scanner via modification to drop a recipient without notifying the sender.¶
UnsignedInt
The current delivery attempt number for this recipient.¶
SmtpResponse|null
The last SMTP response received for this recipient, or null if no attempt has been made.¶
UTCDate|null
The scheduled time for the next delivery attempt, or null if no retry is scheduled.¶
UTCDate|null
The scheduled time for the next DSN generation, or null if no DSN is scheduled.¶
String|null
The name of the outbound queue handling this recipient, if applicable.¶
For the "dsn" stage, the message and rawMessage properties contain the DSN message that the MTA is about to send. Scanners MAY modify or delete these properties to alter or suppress DSN generation.¶
POST /v1/hooks/invoke/reg_7a3b9c2e-4d5f-6a7b-8c9d-0e1f2a3b4c5d \
HTTP/1.1
Host: scanner.example.com
Content-Type: application/json
Authorization: Bearer eyJhbGciOiJIUzI1NiIs...
X-MTA-Hooks-Registration: reg_7a3b9c2e-4d5f-6a7b-8c9d-0e1f2a3b4c5d
X-MTA-Hooks-Request-Id: 01HZ8K3X7F4Y5N6Q9R2S3T4U5V
{
"stage": "data",
"action": "accept",
"timestamp": "2024-12-21T16:30:00Z",
"response": {
"code": 250,
"enhancedCode": "2.0.0",
"message": "OK"
},
"protocol": {
"version": "1.0"
},
"queue": {
"id": "queue_abc123"
},
"envelope": {
"from": {
"address": "sender@example.org",
"parameters": {}
},
"to": [
{
"address": "recipient@example.com",
"parameters": {}
}
]
},
"message": {
"size": 2048,
"subject": "Meeting Tomorrow",
"from": [
{
"name": "Sender Name",
"email": "sender@example.org"
}
],
"to": [
{
"email": "recipient@example.com"
}
],
"sentAt": "2024-12-21T16:29:00Z",
"messageId": ["<msg123@example.org>"],
"headers": [
{"name": "From", "value": "Sender Name <sender@example.org>"},
{"name": "To", "value": "recipient@example.com"},
{"name": "Subject", "value": "Meeting Tomorrow"},
{"name": "Date", "value": "Sat, 21 Dec 2024 16:29:00 +0000"},
{"name": "Message-ID", "value": "<msg123@example.org>"}
],
"bodyStructure": {
"type": "text/plain",
"charset": "utf-8",
"size": 28
},
"bodyValues": {
"1": {
"value": "Let's meet tomorrow at 10am.",
"isEncodingProblem": false,
"isTruncated": false
}
}
},
"client": {
"ip": "192.0.2.100",
"port": 54321,
"ptr": "mail.example.org",
"ehlo": "mail.example.org",
"activeConnections": 3
},
"server": {
"name": "mx1.example.com",
"ip": "198.51.100.25",
"port": 25
},
"tls": {
"version": "TLSv1.3",
"cipher": "TLS_AES_256_GCM_SHA384",
"cipherBits": 256
},
"senderAuth": {
"spf-mail": "pass",
"dkim": "pass",
"dmarc": "pass"
}
}
¶
POST /v1/hooks/invoke/reg_7a3b9c2e-4d5f-6a7b-8c9d-0e1f2a3b4c5d \
HTTP/1.1
Host: scanner.example.com
Content-Type: application/json
Authorization: Bearer eyJhbGciOiJIUzI1NiIs...
X-MTA-Hooks-Registration: reg_7a3b9c2e-4d5f-6a7b-8c9d-0e1f2a3b4c5d
X-MTA-Hooks-Request-Id: 01HZ8K9P2QABCDEFGH7J8K9L0M
{
"stage": "delivery",
"action": "continue",
"timestamp": "2024-12-21T17:00:00Z",
"protocol": {
"version": "1.0"
},
"queue": {
"id": "queue_def456",
"expiresAt": "2024-12-24T17:00:00Z",
"attempts": 3
},
"envelope": {
"from": {
"address": "notifications@example.com",
"parameters": {}
},
"to": [
{
"address": "user1@recipient.example",
"parameters": {},
"status": "delivered",
"attempt": 1,
"lastResponse": {
"code": 250,
"enhancedCode": "2.0.0",
"message": "Message accepted"
}
},
{
"address": "user2@recipient.example",
"parameters": {},
"status": "deferred",
"attempt": 3,
"lastResponse": {
"code": 451,
"enhancedCode": "4.7.1",
"message": "Try again later"
},
"nextAttemptAt": "2024-12-21T18:00:00Z",
"nextDsnAt": "2024-12-22T17:00:00Z"
}
]
},
"message": {
"subject": "Your order has shipped",
"from": [{"email": "notifications@example.com"}],
"to": [
{"email": "user1@recipient.example"},
{"email": "user2@recipient.example"}
],
"size": 4096
},
"server": {
"name": "smtp-out.example.com",
"ip": "198.51.100.50",
"port": 25
}
}
¶
Scanners respond to hook requests with modifications to the request object. These modifications instruct the MTA how to proceed with message processing.¶
On success, scanners respond with HTTP 200 OK and a body conforming to this section, or with HTTP 204 No Content and an empty body to indicate "no modifications". The response body contains a JSON or CBOR object specifying modifications to apply to the hook request. The object has the following fields:¶
SetOperation[]|null
An array of set operations to apply, or null if no set operations.¶
AddOperation[]|null
An array of add operations to apply, or null if no add operations.¶
DeleteOperation[]|null
An array of delete operations to apply, or null if no delete operations.¶
A SetOperation object has the following properties:¶
String
any
The new value for the property.¶
An AddOperation object has the following properties:¶
String
JSON Pointer to the location where the value should be added.¶
any
The value to add.¶
UnsignedInt|null
For array additions, the zero-based index at which to insert the value. If null or omitted, the value is appended to the array.¶
A DeleteOperation object has the following properties:¶
String
JSON Pointer to the property to remove.¶
Scanners change the MTA's action by including a set operation targeting the "/action" path. The following values are valid for inbound and outbound processing respectively.¶
The following action values are valid:¶
Accept the message for delivery to recipients. Non-terminal; chain continues.¶
Reject the message and return an error response to the sending client. Terminal; chain stops.¶
Accept the message from the client but do not deliver it. The client receives a success response. Terminal; chain stops.¶
Accept the message and place it in quarantine for administrative review. Quarantine location and handling are implementation-defined. Non-terminal; chain continues.¶
Terminate the SMTP connection immediately. Terminal; chain stops.¶
Scanners communicate changes by specifying operations on the hook request object. The response contains JSON Pointer paths identifying properties to modify and the operations to perform. These modifications can alter any aspect of the transaction that the MTA permits, including:¶
The action the MTA should take (accept, reject, quarantine, etc.)¶
The SMTP response to send to the client or expect from the server¶
Message headers and body content¶
Envelope addresses (sender and recipients)¶
Per-recipient delivery status for outbound processing¶
Three modification operations are supported:¶
Replace the value at a specified path with a new value.¶
Insert a value at a specified path. For objects, this adds a new property. For arrays, this inserts an element at the specified index or appends if no index is given.¶
Remove the value at a specified path.¶
Set operations replace values at specified paths.¶
{
"set": [
{
"path": "/action",
"value": "reject"
},
{
"path": "/response",
"value": {
"code": 550,
"enhancedCode": "5.7.1",
"message": "Message rejected due to policy"
}
}
]
}
¶
Add operations insert new values. For arrays, an optional index specifies insertion position.¶
{
"add": [
{
"path": "/message/headers",
"value": {"name": "X-Spam-Score", "value": "5.2"},
"index": 0
},
{
"path": "/envelope/to",
"value": {
"address": "archive@example.com",
"parameters": {}
}
}
]
}
¶
Delete operations remove values at specified paths. When deleting array elements, indices refer to positions in the array at the time each delete operation executes. Because delete operations execute sequentially and earlier deletions cause subsequent elements to shift to lower indices, scanners SHOULD order array deletions from highest to lowest index to avoid unexpected results.¶
For example, to delete elements originally at indices 1 and 3 from an array:¶
{
"delete": [
{"path": "/message/headers/3"},
{"path": "/message/headers/1"}
]
}
¶
Deleting index 3 first leaves the element originally at index 1 still at index 1. If the order were reversed, deleting index 1 first would shift the element originally at index 3 to index 2.¶
The MTA applies modifications in the following order:¶
This ordering allows predictable results when multiple operations affect related paths.¶
To change the action the MTA takes, the scanner sets the "/action" path to the desired value. To modify the SMTP response, the scanner can either set individual response fields (e.g., "/response/code", "/response/message") or replace the entire response object by setting "/response".¶
If a scanner modifies both the "message" and "rawMessage" properties, the "rawMessage" modification takes precedence and "message" modifications are ignored.¶
If a response contains multiple operations targeting the same path or overlapping paths, the MTA applies them in the defined order (set, then add, then delete). The final state reflects all operations applied sequentially. For example, if a response sets "/message/subject" and also deletes "/message/subject", the subject will be deleted (delete operations execute last).¶
Implementations SHOULD NOT submit responses with conflicting operations targeting the same path, as the resulting behavior, while deterministic, may be confusing.¶
If a scanner has no modifications to request, it MUST return either:¶
An empty JSON/CBOR object: {}¶
A response with empty or null modification arrays: {"set": null, "add": null, "delete": null}¶
An HTTP 204 No Content response with no body¶
In all cases, the MTA proceeds with the action specified in the original request. The scanner chain continues to the next registered scanner unless the current action is terminal.¶
MTAs MAY impose limits on the size of modification values. If a modification would cause a header or message to exceed configured size limits, the MTA SHOULD reject that specific modification and log the failure.¶
If a modification cannot be applied (for example, the path references a non-existent property for deletion, or the path is not in the permitted updateProperties list), the MTA SHOULD:¶
Log the error with sufficient detail for debugging¶
Increment modification failure statistics¶
Continue processing remaining modifications in the response¶
The MTA MUST NOT reject the entire response due to a single failed modification unless the failed modification is critical to interpreting the response (such as an invalid action value).¶
A scanner that cannot process a hook request returns an HTTP 4xx or 5xx status with a body that follows the error structure defined in Appendix A. Status code semantics:¶
401 Unauthorized: The MTA's credentials are missing or invalid. The MTA MUST NOT retry without acquiring fresh credentials.¶
403 Forbidden: The credentials are valid but not authorized for this registration or operation. The MTA MUST NOT retry without operator intervention.¶
404 Not Found: The registration referenced by X-MTA-Hooks-Registration is unknown to the scanner. The MTA SHOULD treat the registration as terminated and re-register before sending further hooks.¶
410 Gone: The registration has been deregistered. The MTA MUST stop sending hooks under this registration; the MTA MAY re-register.¶
413 Content Too Large: The request body exceeds the scanner's maxMessageSize. The MTA MUST NOT retry the same payload.¶
422 Unprocessable Content: The request was syntactically valid but referenced unsupported properties or values. Treated as a 4xx; do not retry.¶
429 Too Many Requests: The scanner is rate-limiting. The MTA SHOULD honor the Retry-After header if present.¶
5xx: A transient scanner error. The MTA MAY retry per its retry policy (Section 7.5.3).¶
If the response body is not parseable as the negotiated serialization, or if it conforms to the response schema but contains modifications targeting paths outside the registration's negotiated updateProperties, the MTA MUST treat the response as malformed: it MUST NOT apply any modifications from the response, MUST proceed with the default action carried in the request, MUST log the failure with the request identifier, and MAY count the response toward the scanner's failure statistics for circuit-breaking purposes.¶
HTTP/1.1 200 OK
Content-Type: application/json
{
"add": [
{
"path": "/message/headers",
"value": {"name": "X-Spam-Status", "value": "No"},
"index": 0
},
{
"path": "/message/headers",
"value": {"name": "X-Spam-Score", "value": "1.2"},
"index": 1
}
]
}
¶
HTTP/1.1 200 OK
Content-Type: application/json
{
"set": [
{
"path": "/action",
"value": "reject"
},
{
"path": "/response",
"value": {
"code": 550,
"enhancedCode": "5.7.1",
"message": "Message rejected: virus detected"
}
}
]
}
¶
HTTP/1.1 200 OK
Content-Type: application/json
{
"set": [
{
"path": "/message/subject",
"value": "[EXTERNAL] Original Subject"
}
],
"add": [
{
"path": "/envelope/to",
"value": {
"address": "compliance@example.com",
"parameters": {}
}
}
]
}
¶
For outbound processing, to cancel delivery for a specific recipient:¶
HTTP/1.1 200 OK
Content-Type: application/json
{
"set": [
{
"path": "/envelope/to/1/status",
"value": "failed-silent"
}
]
}
¶
If a scanner has no changes to request, it returns an empty response body or a response with no action or modifications:¶
HTTP/1.1 200 OK
Content-Type: application/json
{}
¶
The MTA proceeds with the default action specified in the request.¶
This section specifies HTTP transport requirements for MTA Hooks communications.¶
Implementations MUST support HTTP/1.1 [RFC9112]. Implementations SHOULD support HTTP/2 [RFC9113] for improved performance through multiplexing. Implementations MAY support HTTP/3 [RFC9114].¶
When multiple HTTP versions are available, implementations SHOULD prefer newer versions for their performance benefits while maintaining fallback to HTTP/1.1.¶
All MTA Hooks communications MUST use TLS. Implementations MUST support TLS 1.2 [RFC5246] and SHOULD support TLS 1.3 [RFC8446].¶
Implementations MUST validate server certificates against trusted certificate authorities. Self-signed certificates SHOULD NOT be accepted in production deployments unless explicitly configured by administrators.¶
Cipher suite selection SHOULD follow current best practices. Implementations SHOULD disable cipher suites known to be weak or compromised.¶
The following HTTP methods are used:¶
For hook requests and responses, the Content-Type header MUST be set to "application/json" for JSON serialization or "application/cbor" for CBOR serialization.¶
The Accept header MAY be used during discovery to indicate preferred serialization format. If the scanner cannot provide the requested format, it SHOULD return the discovery document in JSON format.¶
MTAs SHOULD interpret HTTP status codes as follows:¶
If a scanner does not respond within the configured timeout, the MTA SHOULD proceed with the default action. Timeout handling policy (fail-open vs. fail-closed) is implementation-defined and SHOULD be configurable.¶
For transient errors (5xx status codes, network failures, timeouts), implementations SHOULD implement retry with exponential backoff. A recommended policy is:¶
Maximum 3 retry attempts¶
Initial delay: 100 milliseconds¶
Backoff multiplier: 2¶
Maximum delay: 5 seconds¶
Add random jitter of 0-100 milliseconds¶
The MTA MUST keep the X-MTA-Hooks-Request-Id header value stable across retries of the same logical invocation, so scanners can deduplicate. Implementations MAY provide configuration options to adjust retry parameters.¶
Implementations SHOULD use connection pooling to reduce latency for repeated requests to the same scanner endpoint. HTTP/2 multiplexing, where available, reduces the need for multiple connections.¶
Implementations SHOULD respect HTTP keep-alive semantics and connection limits advertised by scanners.¶
Synchronous hook invocation adds latency to mail processing. Implementations SHOULD consider:¶
Scanners SHOULD design their processing to be idempotent. Network issues or MTA retries may result in duplicate invocations for the same message. Scanners SHOULD handle duplicate requests gracefully.¶
Scanners operate in the critical path of mail delivery. Long response times delay message processing and may cause timeouts. Scanners SHOULD:¶
Scanners SHOULD avoid relying on state from previous invocations. Each hook request contains complete context for processing decisions. Stateless design improves reliability and simplifies horizontal scaling.¶
Large messages present challenges for both MTAs and scanners. Implementations SHOULD consider:¶
Message size limits advertised in discovery documents¶
Truncation policies for oversized messages¶
Memory management for large message bodies¶
Streaming or chunked delivery is not currently specified. For very large messages, implementations MAY arrange out-of-band content retrieval, though this is outside the scope of this specification.¶
For production deployments, scanners SHOULD be deployed with redundancy. Approaches include:¶
Multiple scanner instances behind a load balancer¶
Health checking with automatic failover¶
Geographic distribution for disaster recovery¶
Hook endpoints typically resolve to a load-balanced address; the MTA holds a single endpoint URL per registration.¶
Registration state resides at the scanner. Scanner instances behind a load balancer MUST share registration state (or partition deterministically by registration identifier) so that hook requests can be served regardless of which instance receives them. The MTA SHOULD treat 404 REGISTRATION_NOT_FOUND on a previously-active registration as a signal to re-register rather than as a permanent failure.¶
MTA Hooks places the MTA exclusively in the role of HTTP client. The MTA does not expose any HTTP server to scanners and does not accept inbound registration requests. This containment is deliberate: it eliminates a category of attacks (registration flood, server-side request forgery via callback verification, exposure of MTA management endpoints) that would otherwise threaten the most security-critical component on the mail path.¶
The trust boundary runs in one direction. The scanner operator decides which MTAs may register and provisions credentials accordingly. The MTA admin decides which scanners to call out to and configures them out of band. Mutual trust is established before any protocol traffic flows.¶
Scanner operators issue credentials to MTA operators through an out-of-band channel that this specification does not define. Credential provisioning practices SHOULD include:¶
Per-MTA-instance credentials (avoid shared secrets across multiple MTAs).¶
Credential rotation on a defined cadence.¶
Immediate revocation when an MTA instance is decommissioned or compromised.¶
Storage of credentials at the MTA in protected configuration that is not logged or exported with diagnostics.¶
Scanner-issued credentials SHOULD encode the MTA identity in a way that survives renewal of the underlying secret (for example, a stable client-certificate Subject CN, or a tenant identifier conveyed alongside a rotated bearer token).¶
All MTA Hooks communications MUST use TLS to protect message content and authentication credentials in transit. Implementations MUST validate certificates to prevent man-in-the-middle attacks.¶
For internal network deployments, administrators may choose to use private certificate authorities. However, disabling certificate validation is NOT RECOMMENDED even for internal communications.¶
Email messages frequently contain sensitive personal or business information. Scanners necessarily receive access to message content to perform their functions. Deployments SHOULD consider:¶
Although the registration endpoint is on the scanner, an attacker that obtains valid MTA credentials could flood the scanner with registration churn. Scanners SHOULD:¶
A compromised or misconfigured MTA could overwhelm a scanner with hook requests. Scanners SHOULD:¶
Slow scanner responses can exhaust MTA resources (connection slots, memory, queued mail). MTAs SHOULD:¶
A compromised scanner can attempt to coerce the MTA into mishandling mail by returning malicious modifications. The MTA's defense in depth is to enforce its declared updateProperties strictly, validate every modification (Section 9.7), and reject responses that violate the negotiated capabilities. The MTA SHOULD NOT depend on the scanner to behave honestly.¶
Scanner responses contain modifications applied to message processing. Implementations MUST validate all scanner-provided data:¶
Header names and values MUST be validated to prevent header injection (CR/LF smuggling, malformed encoded-words, header folding abuse).¶
Recipient addresses MUST be syntactically validated and re-checked against MTA policy before being added to the envelope.¶
Body modifications MUST not introduce malformed MIME structure or content that violates declared character sets.¶
Modifications targeting paths outside the registration's negotiated updateProperties MUST be discarded.¶
Email processing inherently involves access to personal communications. Implementations SHOULD minimize data exposure:¶
This document registers the following well-known URI per [RFC8615]:¶
URI suffix: mta-hooks¶
Change controller: IETF¶
Specification document: This document¶
Status: permanent¶
Related information: N/A¶
IANA is requested to create a new registry entitled "MTA Hooks Serialization Formats" with the following initial contents:¶
New registrations require Specification Required per [RFC8126].¶
IANA is requested to create a new registry entitled "MTA Hooks Inbound Actions" with the following initial contents:¶
New registrations require Specification Required per [RFC8126].¶
IANA is requested to create a new registry entitled "MTA Hooks Outbound Actions" with the following initial contents:¶
New registrations require Specification Required per [RFC8126].¶
IANA is requested to create a new registry entitled "MTA Hooks Inbound Stages" with the following initial contents:¶
New registrations require Specification Required per [RFC8126].¶
IANA is requested to create a new registry entitled "MTA Hooks Outbound Stages" with the following initial contents:¶
New registrations require Specification Required per [RFC8126].¶
IANA is requested to create a new registry entitled "MTA Hooks Error Codes" with the initial contents specified in Appendix A.¶
New registrations require Specification Required per [RFC8126].¶
This appendix defines error codes used in MTA Hooks error responses.¶
Error responses use the following structure:¶
{
"error": {
"code": "ERROR_CODE",
"message": "Human-readable error description"
}
}
¶
INVALID_REQUEST: Malformed JSON or CBOR, or missing required fields.¶
CAPABILITY_MISMATCH: Requested capability not supported by the scanner.¶
INVALID_STAGE: One or more requested stages are not valid.¶
INVALID_ACTION: One or more requested actions are not valid.¶
INVALID_MODIFICATION: One or more requested modifications are not valid.¶
NO_STAGES_REQUESTED: Neither inbound nor outbound stages were specified.¶
FILTER_INVALID: Filter configuration is syntactically invalid.¶
MISSING_REQUEST_ID: The X-MTA-Hooks-Request-Id header is missing on a hook invocation.¶
REGISTRATION_NOT_FOUND: No registration exists with the specified identifier.¶
REGISTRATION_LIMIT_REACHED: Maximum number of registrations for this MTA identity exceeded.¶
REGISTRATION_DEREGISTERED: The registration has been deregistered and will not be re-activated.¶
REQUEST_TOO_LARGE: The request body exceeds the scanner's advertised maxMessageSize.¶
RATE_LIMITED: Too many requests; retry after the time specified in the Retry-After header.¶
INTERNAL_ERROR: Unexpected server error during processing.¶
This appendix provides complete request and response examples for common scenarios.¶
This example shows a complete flow for spam filtering during inbound message reception.¶
GET /.well-known/mta-hooks HTTP/1.1 Host: scanner.example.com Accept: application/json¶
HTTP/1.1 200 OK
Content-Type: application/json
{
"version": "1.0",
"endpoints": {
"registration": "/v1/hooks/register",
"deregistration": "/v1/hooks/register/{registration_id}"
},
"serialization": ["json"],
"capabilities": {
"inbound": {
"stages": ["data"],
"actions": ["accept", "reject", "quarantine"],
"fetchProperties": ["/message", "/envelope", "/senderAuth",
"/client"],
"updateProperties": ["/message/headers", "/action", "/response"]
}
},
"limits": {
"maxMessageSize": 26214400,
"timeoutMs": 30000
}
}
¶
POST /v1/hooks/register HTTP/1.1
Host: scanner.example.com
Content-Type: application/json
Authorization: Bearer sk_live_abc123
{
"name": "Acme MTA mx1",
"version": "3.0.1",
"timeoutMs": 20000,
"serialization": "json",
"inbound": {
"stages": ["data"],
"properties": ["/message", "/envelope", "/senderAuth", "/client"]
},
"metadata": {
"operator": "acme-corp"
}
}
¶
HTTP/1.1 201 Created
Content-Type: application/json
Location: /v1/hooks/register/reg_spam_001
{
"registrationId": "reg_spam_001",
"status": "active",
"createdAt": "2024-12-21T10:00:00Z",
"expiresAt": "2025-01-21T10:00:00Z",
"hookEndpoint": "/v1/hooks/invoke/reg_spam_001",
"negotiated": {
"serialization": "json",
"inbound": {
"stages": ["data"],
"properties": ["/message", "/envelope", "/senderAuth", "/client"]
}
},
"endpoints": {
"deregistration": "/v1/hooks/register/reg_spam_001",
"status": "/v1/hooks/register/reg_spam_001/status"
}
}
¶
POST /v1/hooks/invoke/reg_spam_001 HTTP/1.1
Host: scanner.example.com
Content-Type: application/json
Authorization: Bearer sk_live_abc123
X-MTA-Hooks-Registration: reg_spam_001
X-MTA-Hooks-Request-Id: 01HZ8K3X7F4Y5N6Q9R2S3T4U5V
{
"stage": "data",
"action": "accept",
"timestamp": "2024-12-21T10:30:00Z",
"response": {
"code": 250,
"enhancedCode": "2.0.0",
"message": "OK"
},
"envelope": {
"from": {"address": "alice@sender.example", "parameters": {}},
"to": [{"address": "bob@recipient.example", "parameters": {}}]
},
"message": {
"subject": "Quarterly Report",
"from": [{"email": "alice@sender.example", "name": "Alice Smith"}],
"to": [{"email": "bob@recipient.example"}],
"size": 15360,
"bodyValues": {
"1": {
"value": "Please find attached the Q4 report...",
"isEncodingProblem": false,
"isTruncated": false
}
}
},
"senderAuth": {
"spf-mail": "pass",
"dkim": "pass",
"dmarc": "pass"
},
"client": {
"ip": "192.0.2.50",
"ehlo": "mail.sender.example"
}
}
¶
HTTP/1.1 200 OK
Content-Type: application/json
{
"add": [
{
"path": "/message/headers",
"value": {"name": "X-Spam-Status", "value": "No, score=0.5"},
"index": 0
}
]
}
¶
POST /v1/hooks/invoke/reg_spam_001 HTTP/1.1
Host: scanner.example.com
Content-Type: application/json
Authorization: Bearer sk_live_abc123
X-MTA-Hooks-Registration: reg_spam_001
X-MTA-Hooks-Request-Id: 01HZ8KAW6D2E3F4G5H6J7K8L9M
{
"stage": "data",
"action": "accept",
"timestamp": "2024-12-21T10:35:00Z",
"response": {
"code": 250,
"enhancedCode": "2.0.0",
"message": "OK"
},
"envelope": {
"from": {"address": "promo@spammer.invalid", "parameters": {}},
"to": [{"address": "bob@recipient.example", "parameters": {}}]
},
"message": {
"subject": "YOU HAVE WON $1,000,000!!!",
"from": [{"email": "winner@lottery.invalid"}],
"to": [{"email": "bob@recipient.example"}],
"size": 8192
},
"senderAuth": {
"spf-mail": "fail",
"dkim": "none",
"dmarc": "fail"
},
"client": {
"ip": "203.0.113.99",
"ehlo": "totally-legit.invalid"
}
}
¶
HTTP/1.1 200 OK
Content-Type: application/json
{
"set": [
{
"path": "/action",
"value": "reject"
},
{
"path": "/response",
"value": {
"code": 550,
"enhancedCode": "5.7.1",
"message": "Message rejected due to spam content"
}
}
]
}
¶
This example shows outbound hook usage for delivery status logging and compliance.¶
POST /v1/hooks/register HTTP/1.1
Host: logger.example.net
Content-Type: application/json
Authorization: Bearer sk_live_def456
{
"name": "Acme MTA mx1",
"version": "1.0.0",
"timeoutMs": 5000,
"serialization": "json",
"outbound": {
"stages": ["delivery", "dsn"],
"properties": null
}
}
¶
HTTP/1.1 201 Created
Content-Type: application/json
{
"registrationId": "reg_logger_001",
"status": "active",
"createdAt": "2024-12-21T11:00:00Z",
"hookEndpoint": "/v1/hooks/invoke/reg_logger_001",
"negotiated": {
"serialization": "json",
"outbound": {
"stages": ["delivery", "dsn"],
"properties": ["/envelope", "/message", "/queue", "/server"]
}
},
"endpoints": {
"deregistration": "/v1/hooks/register/reg_logger_001",
"status": "/v1/hooks/register/reg_logger_001/status"
}
}
¶
POST /v1/hooks/invoke/reg_logger_001 HTTP/1.1
Host: logger.example.net
Content-Type: application/json
Authorization: Bearer sk_live_def456
X-MTA-Hooks-Registration: reg_logger_001
X-MTA-Hooks-Request-Id: 01HZ8MBN5Q4R3S2T1U0V9W8X7Y
{
"stage": "delivery",
"action": "continue",
"timestamp": "2024-12-21T12:00:00Z",
"queue": {
"id": "q_msg_12345",
"expiresAt": "2024-12-24T12:00:00Z",
"attempts": 1
},
"envelope": {
"from": {"address": "notify@example.com", "parameters": {}},
"to": [
{
"address": "user1@active.example",
"parameters": {},
"status": "delivered",
"attempt": 1,
"lastResponse": {
"code": 250,
"enhancedCode": "2.0.0",
"message": "Delivered"
}
},
{
"address": "user2@slow.example",
"parameters": {},
"status": "deferred",
"attempt": 1,
"lastResponse": {
"code": 451,
"enhancedCode": "4.7.1",
"message": "Greylisted, try again"
},
"nextAttemptAt": "2024-12-21T12:15:00Z"
},
{
"address": "user3@invalid.example",
"parameters": {},
"status": "failed",
"attempt": 1,
"lastResponse": {
"code": 550,
"enhancedCode": "5.1.1",
"message": "User unknown"
}
}
]
},
"message": {
"subject": "System Notification",
"messageId": "<notify-12345@example.com>",
"size": 2048
}
}
¶
HTTP/1.1 204 No Content¶
DELETE /v1/hooks/register/reg_spam_001 HTTP/1.1 Host: scanner.example.com Authorization: Bearer sk_live_abc123¶
HTTP/1.1 200 OK
Content-Type: application/json
{
"registrationId": "reg_spam_001",
"status": "deregistered",
"deregisteredAt": "2024-12-21T18:00:00Z"
}
¶
The authors thank the developers and operators of existing mail filtering systems whose experience informed this design.¶
[[This section to be removed by RFC Editor]]¶
draft-degennaro-mta-hooks-01¶
Inverted the registration model: the MTA is now exclusively the HTTP client. The registration, status, and deregistration endpoints reside at the scanner; the MTA no longer exposes any HTTP server to scanners.¶
Removed the callback URL concept and callback verification handshake. The scanner's hook endpoint is returned in the registration response.¶
Required X-MTA-Hooks-Registration on every hook invocation. Added X-MTA-Hooks-Request-Id for safe deduplication on retry.¶
Specified authentication requirements for hook invocations and credential provisioning practices.¶
Specified the error response contract for hook invocations and the status code semantics.¶
Clarified action precedence in multi-scanner chains and removed the duplicate Multiple Scanner Handling section.¶
Replaced "Modification Order" duplication with a forward reference.¶
Documented the failed-silent recipient status.¶
Corrected the enhanced status code reference from RFC 3461 to RFC 3463.¶
Clarified filter conditions: minSize and maxSize are permitted; the confused reference to Section 4.1.1 of RFC 8621 has been removed.¶
Replaced callback-related error codes (CALLBACK_UNREACHABLE, CALLBACK_VERIFICATION_FAILED, TLS_REQUIRED, TLS_CERTIFICATE_INVALID, INVALID_CALLBACK_URL, CALLBACK_NOT_ALLOWED, ALREADY_REGISTERED) with codes appropriate to the new model (REGISTRATION_MISMATCH, REGISTRATION_DEREGISTERED, REQUEST_TOO_LARGE, UNSUPPORTED_PROPERTY, MISSING_REQUEST_ID, SCANNER_UNAVAILABLE).¶
Rewrote Security Considerations around the new trust model and credential provisioning.¶
draft-degennaro-mta-hooks-00¶
Initial version¶