Workflow Tools Control Yard

Home / Email and M365

MTA-STS and TLS-RPT builder

MTA-STS tells other mail servers to send mail to your domain only over TLS, to your own MX hosts. It takes a TXT record and a policy file on a web server. Build them here, with the TLS-RPT record that asks for reports, or paste one to read it.

Build the records

Mode

1. TXT record at _mta-sts.example.com

2. Policy file, served as plain text at https://mta-sts.example.com/.well-known/mta-sts.txt

3. TXT record at _smtp._tls.example.com

The policy file needs a web server for mta-sts.example.com with a certificate that is valid for that name. Senders fetch the file over HTTPS and accept only a 200 answer: they do not follow redirects.

Check the MX hosts and the records. PowerShell:

Linux or macOS:

To check the policy file, open its address in a browser: it should show the lines of the policy as plain text.

Read a record or a policy

How MTA-STS works

A sender that supports MTA-STS looks up the TXT record _mta-sts at the domain it is sending to. When the record is there, it fetches the policy from https://mta-sts.domain/.well-known/mta-sts.txt and keeps it for up to max_age seconds. While it has the policy, it checks each MX host against the mx lines and checks that the host offers TLS with a certificate valid for its name. The mode says what happens when a check fails:

ModeWhat senders do
enforceSenders deliver only to MX hosts that match an mx line, over TLS, with a certificate that is valid for the host. When none of the MX hosts passes, they keep the message and try again later.
testingSenders that check a policy and find a problem send a TLS report about it, if the domain asks for reports, and deliver the message anyway.
noneSenders treat the domain as having no policy. This is the way out: see Removing MTA-STS below.

An mx line is a host name, or *. and a domain. The wildcard stands for exactly one label: *.example.com matches mail.example.com, but not example.com or foo.bar.example.com. An international name goes in an mx line in its xn-- form.

The TXT record has to be the only one at its name that begins with v=STSv1;, and the id is letters and digits, up to 32: senders that find none or two act as though the domain had no policy. When a sender finds the record but cannot fetch the policy, and has none cached, it delivers as though the domain had no MTA-STS. The lines of the policy may end in CRLF or LF, and senders ignore lines they do not know. RFC 8461 suggests a limit of 64 kilobytes for the file.

Changing the policy

Senders fetch the policy again when the id in the TXT record changes. So change the policy file first, then the id: a sender that sees the new id while the old file is still served caches the old policy again. Until the TTL of the TXT record has passed, some senders still use the old policy, so it should keep working for that time.

Removing MTA-STS

  1. Publish a policy with mode: none and a short max_age, such as one day.
  2. Change the id in the TXT record, so that senders fetch it.
  3. Wait until every policy served before has expired: the time it was last served plus its max_age. Then remove the TXT record and the policy file.

TLS reports

The TXT record _smtp._tls asks senders for SMTP TLS reports: v=TLSRPTv1; and then rua= with one or more mailto: or https: addresses, separated by commas. A report covers one UTC day; it is a JSON file, which senders should compress with gzip, sent by email or with an HTTPS POST. Commas, exclamation marks and semicolons inside an address must be percent-encoded. In testing mode, the reports are how you find out what enforce mode would have stopped.

Sources

More Email and M365 tools