Skip to main content

Outgoing Gateways

An account holder can send a mail domain's outgoing mail through a smarthost of their own, the Third-Party Outgoing Mail Gateway of the domain's Mail service, instead of straight to each recipient. What they set and why is in the account docs. This page is what the server does with it.

The panel writes the gateway into the domain's mail-domains intent, and elpan-mail-out's transformer turns it into Postfix maps and, for a gateway with a client certificate, a transport of its own (Server configuration). The man page elpan-mail-out-confgen(8) has every detail.

The files​

All under /var/lib/elpan/mail-out/config/, owned by the transformer, and each map with its .lmdb beside it:

FileWhat it holds
sender_dependent_relayhost@<domain> and the gateway's next hops, [<hop>]:25 each, in the order the account holder gave them. One row per domain with an outgoing gateway.
sasl_passwd@<domain> and <user>:<password>, for a gateway with credentials. 0600, and a secret.
sender_dependent_default_transport@<domain>, the domain's client certificate transport and the same next hops: gwc-<hash>:[<hop>]:25,.... One row per domain whose gateway has a client certificate.
client-certs/<host>/rsa-keycert, ecc-keycertThe certificates of a host a gateway names as its client certificate: the private key, then the chain, leaf first, one file per key type the host has. 0600 in 0700 directories, root only, and secrets.
master.cf.d/50-gwc-<hash>.cfThe transport gwc-<hash> for one such host: an smtp service whose smtp_tls_chain_files names the host's files, at smtp_tls_security_level=encrypt. A comment in it names the host.

<hash> is the first ten hex digits of the SHA-256 of the host's name: a transport's name is a socket path, and a host name can be too long for one.

The main configuration asks the maps in this order: transport_maps first (the server's own routes, such as the bounce host), then sender_dependent_default_transport_maps, then sender_dependent_relayhost_maps. A domain with a client certificate is routed by its row in sender_dependent_default_transport, transport and next hops at once; a domain with a gateway and no certificate by its row in sender_dependent_relayhost, as before.

The client certificate​

Some gateways recognize their senders by a TLS client certificate rather than by IP address, and the server's addresses are shared: Microsoft 365's inbound connector from an organization's own server is the common case. For those, the account holder picks one of their own hosts with a certificate as the gateway's Client Certificate, usually the domain's mail.<domain>.

  • Only that gateway sees it. The row is keyed on the envelope sender's domain, and its next hops are the account holder's gateway, so the certificate goes out only with that domain's mail and only to its gateway. Forwarded mail and bounces have the server's own envelope sender and never match.
  • Only over TLS. The transport is at encrypt: a gateway that offers no TLS gets no mail, which waits in the queue, rather than mail sent in clear to a destination that would refuse it anyway.
  • Renewals need nothing. A renewed certificate is a new keycert file, and the transformer reloads elpan-mail-out, which starts its smtp processes again with the new key.
  • No certificate document, no route. The panel marks a host whose certificates a gateway presents (relayClient in its certificates intent). If a domain names a host the transformer has no certificates for, it refuses the domain, which keeps its last good rows, rather than install a transport Postfix would defer the mail on. The refusal is on the Configuration screen.

The panel takes any of the account's hosts with a certificate, and shows the account holder whether it is usable: issued by a certificate authority, not expired, and covering the host's name. A temporary self-signed one is taken too, so that the gateway can be set up while the real certificate is being issued; Microsoft refuses mail sent with it (550 5.7.64 TenantAttribution), and it bounces.

Checking a domain's route​

As root:

postconf -c /var/lib/elpan/mail-out/config -M | grep gwc-
postmap -q @example.com lmdb:/var/lib/elpan/mail-out/config/sender_dependent_default_transport
postmap -q @example.com lmdb:/var/lib/elpan/mail-out/config/sender_dependent_relayhost

The first lists the client certificate transports, the second the route of a domain with a client certificate, the third the route of a domain with a gateway. A message to a gateway that offers no TLS waits in the queue, and System › Outgoing Mail Queue shows the TLS failure as the reason (Outgoing Mail Queue). A refusal comes back to the sender as a bounce: 550 5.7.64 TenantAttribution from Microsoft is a connector that doesn't match, or a certificate it doesn't accept.