By Ahmet Karaca · Updated · Checked against RFC 8461 (MTA-STS), RFC 8460 (SMTP TLS Reporting), RFC 5321 (SMTP) and RFC 7505 (null MX) on
What MTA-STS does
Mail servers usually encrypt with STARTTLS only when it works, so an attacker on the path can strip the upgrade or pose as your mail server (RFC 8461 §1). MTA-STS lets you publish a policy that tells senders your MX hosts support TLS with a valid certificate and which host names they use. Senders that apply the policy in enforce mode won't deliver over a connection that fails those checks (§5).
A policy needs three pieces, and the generator writes all of them: the policy file, the _mta-sts TXT record that announces it, and optionally the _smtp._tls TXT record for TLS-RPT reports (RFC 8460). For the background, read MTA-STS and TLS-RPT explained.
What the generator produces
The policy file holds one key and value per line: version: STSv1 first, then the mode, one mx: line for each pattern and the max_age in seconds, the same order as the example in RFC 8461 §3.2. The section calls the lines CRLF-separated, and its grammar accepts LF too, so the file uses CRLF line endings, with one after the last line. International host names must be written in their xn-- form.
The file is served at https://mta-sts.yourdomain/.well-known/mta-sts.txt. Senders fetch it over HTTPS and require a certificate valid for the mta-sts host, a 200 status and no redirect (§3.3), and they should check that it is served as text/plain (§3.2). The _mta-sts record then carries v=STSv1 and the id of this version of the policy (§3.1).
Fill from my MX records looks up your MX hosts so you don't miss one. A domain with a null MX (RFC 7505) accepts no mail, so it has nothing for MTA-STS to protect. A domain with no MX records at all receives mail at its own A or AAAA address, the implicit MX of RFC 5321 §5.1, so the domain itself becomes the pattern.
Roll out in testing, then enforce
- Publish the TLS-RPT record, so reports start arriving.
- Host the policy file in
testingmode with anmx:line for every MX host. - Publish the
_mta-stsrecord. RFC 8461 §8.1 says to update the file before the TXT record, so a sender that sees the new id never caches the old file. - Read the TLS reports for a while. In testing mode, senders that implement TLS-RPT report policy failures, and messages may still be delivered (§5).
- When the failures are fixed or explained, generate the file again in
enforcemode and publish it with its new id.
The MTA-STS checker confirms each step from the outside: it fetches the file, parses it the way senders do and compares the mx: lines with your MX records.
If an MX host is missing from the policy
Under enforce, a sender that applies the policy checks that at least one mx: pattern matches the MX host it selected (RFC 8461 §4), and it must not deliver to a host that fails that match (§5). A forgotten backup MX is easy to miss: senders try MX hosts in their usual order, so a problem that only affects a lower-priority host may surface only when the primary fails (§8.4). Before you add or rename an MX host, add its pattern to the policy and publish a new id. Senders keep a cached policy until it expires or they see a new id, for up to 365.25 days with the largest max_age.
Withdrawing a policy
Deleting the record and file isn't enough, because senders keep applying a cached policy until it expires. RFC 8461 §8.3 describes a clean exit instead: publish a new policy with mode: none and a small max_age (its example is one day, 86400 seconds), publish a new TXT record so senders fetch it, and remove the record and the file only after every previously served policy has expired. Choose mode none above to generate that file; it needs no mx: line.