SMTP and submission
The proxy handles SMTP in two ways, depending on who is sending.
Message submission by authenticated clients is handled like the other interactive protocols. The proxy conducts the session until authentication, identifies the account, and routes it.
Mail transfer between servers, inbound SMTP and LMTP, is handled differently. These sessions are not authenticated and carry no account to route on, so they are passed as an uninterpreted stream to one fixed destination.
Submission
Section titled “Submission”A submission listener serves clients that send mail, usually on port 587 with STARTTLS, or on port 465 with implicit TLS. On connection, the proxy sends a 220 greeting with server.hostname, or with the local address of the connection when no host name is set. Before authentication, it answers EHLO, HELO, NOOP, RSET, STARTTLS and QUIT itself. LHLO belongs to LMTP, and is refused with 502 5.5.1. The EHLO response lists the ehlo keywords of [capabilities.submission], the available AUTH mechanisms and, on a STARTTLS listener before the upgrade, STARTTLS.
The proxy accepts AUTH with PLAIN, LOGIN, OAUTHBEARER or XOAUTH2, with the initial response either on the command line or after a 334 continuation. Offering LOGIN keeps clients working that support only that mechanism, and the proxy replays it as PLAIN, as described under Authentication replay. Until the connection is encrypted, cleartext mechanisms are refused with 538 5.7.11 Encryption required for requested authentication mechanism, unless allow_plain_auth_without_tls is set.
Errors the proxy detects itself are answered with the reply codes of RFC 4954, so that clients can tell them apart:
| Reply | Cause |
|---|---|
504 5.5.4 | The mechanism is unknown, or not in the sasl list |
501 5.5.2 | The response is not valid Base64 |
501 5.7.0 | The client cancelled the exchange with * |
535 5.7.8 | The credentials are malformed, so no account can be derived from them |
500 5.5.6 | An authentication line is too long |
500 5.5.2 | A command line cannot be parsed |
503 5.5.1 | Any other command before authentication |
A rejection by the backend is relayed as the backend sent it, or replaced by a generic 535 when the destination sets hide_auth_errors.
Once the destination is resolved, the proxy connects to its submission endpoint, reads the 220 greeting, and sends its own EHLO. On a STARTTLS endpoint, it then upgrades the connection and sends EHLO again.
When the destination uses XCLIENT forwarding and the backend advertises XCLIENT, the proxy announces the client with an XCLIENT command. The command carries those of the following attributes that the backend lists: the client’s address and port, the proxy’s address and port, the client’s HELO name, the protocol and the transport security. The proxy then sends EHLO again, so that the session reflects the announced client.
Finally, the proxy replays the authentication, relays the result, and joins the connections. The initial response is sent on the AUTH line, unless that would make the line longer than 512 octets (RFC 4954); it is then sent after the backend’s empty 334 challenge, so large OAuth tokens work with backends that enforce the limit. From then on, client and backend exchange MAIL, RCPT and DATA directly.
SMTP and LMTP pass-through
Section titled “SMTP and LMTP pass-through”An smtp or lmtp listener handles unauthenticated mail transfer: inbound mail from other servers on port 25, or local delivery over LMTP. These sessions have no login, so they are not routed per account. The proxy passes the whole session, byte for byte, to the destination named by routing.smtp_passthrough_destination, without interpreting the SMTP dialogue:
[routing]default_destination = "legacy"smtp_passthrough_destination = "stalwart"Because the proxy does not interpret the session, it cannot answer a STARTTLS command itself. Pass-through listeners therefore use plain or implicit, and starttls is rejected at startup with listener.<name>.tls: a pass-through (smtp) listener cannot use tls=starttls (the proxy bridges raw and does not terminate STARTTLS); use plain or implicit.
A plain listener does not mean unencrypted mail. The proxy passes the sending server’s STARTTLS negotiation to the backend unchanged, so TLS is established between the sending server and the backend, with the backend’s certificate. An implicit listener, by contrast, terminates TLS at the proxy and passes the decrypted session on.
The pass-through destination must declare the smtp protocol, and also the lmtp protocol when an LMTP listener exists. The default destination, by contrast, need not declare either. These rules are checked at startup and on every configuration change, with these errors:
routing.smtp_passthrough_destination: smtp/lmtp listener configured but routing.smtp_passthrough_destination is unsetrouting.smtp_passthrough_destination: destination "<name>" must declare the smtp protocolrouting.smtp_passthrough_destination: destination "<name>" must declare lmtp (an lmtp listener exists)
On the backend side, an implicit endpoint wraps the connection in TLS. plain and starttls both pass it unencrypted, leaving STARTTLS to the two ends.
Of the forwarding modes, only proxy has an effect. The connection starts with a PROXY header, which tells the backend the sending server’s address for its own checks. xclient sends nothing on a pass-through connection.
When the backend cannot be reached, the proxy closes the client’s connection without an SMTP reply, and the sending server retries later. The failure is logged only at debug level (connection ended), and it counts towards the destination’s circuit breaker. Pass-through sessions are otherwise not logged one by one.