MTA-STS: force TLS for email sent to your domain
STARTTLS encrypts email between mail servers, but an attacker on the network can quietly switch it off. MTA-STS tells sending servers to use TLS with a valid certificate or not deliver at all. Here is how to set it up step by step.
Offensly Team··5 min read
When another mail server delivers email to your domain, it looks up your MX records and connects over SMTP. Encryption is optional in SMTP. The sender asks for it with STARTTLS, and if the answer looks like "not supported", most servers send the message in plain text.
That is the weak point. An attacker who sits between the two servers can remove the STARTTLS offer from the conversation or answer with a fake certificate. The sending server usually accepts it and delivers anyway. Nobody gets an error, and the email crosses the network readable.
MTA-STS (Mail Transfer Agent Strict Transport Security, RFC 8461) closes this gap. You publish a policy that says: "deliver to these MX hosts only over TLS with a valid certificate". Senders that support MTA-STS remember the policy and refuse to deliver when the connection does not meet it.
Two parts: a DNS record and a policy file
MTA-STS has two parts, and both must be in place.
| Part | Where it lives | What it does |
|---|---|---|
| DNS record | TXT at _mta-sts.example.com | Announces that a policy exists and gives it a version id |
| Policy file | https://mta-sts.example.com/.well-known/mta-sts.txt | Lists your MX hosts and the mode |
The policy is served over HTTPS on purpose. DNS answers can be forged, but the attacker would also need a valid certificate for mta-sts.example.com to fake the policy.
A sending server fetches the policy once and caches it for max_age seconds. After that, an attacker who strips TLS can no longer trick it, because the sender already knows TLS is required.
The policy has three modes:
none: no policy. Used to retire MTA-STS.testing: senders deliver as before, but report failures (see TLS reports below).enforce: senders do not deliver unless TLS and the certificate check succeed.
What happens to incoming mail without it
Without MTA-STS, email sent to your company can be read or altered in transit, and neither side notices. That matters for invoices, contracts and password resets. The fix costs a DNS record, one small text file on a web server and a few hours of an engineer's time, plus a testing period of a couple of weeks.
How to set it up
1. Check that your MX hosts support TLS
Every host in your MX records must offer STARTTLS with a certificate that is valid, not expired and issued for the MX host name. If one of them does not, fix that first, or enforce mode will block mail to it.
openssl s_client -connect mx1.example.com:25 -starttls smtp -servername mx1.example.comOnly run checks like these against sites you own or are allowed to test.
If you use a hosted mail service, its MX hosts normally meet this already. Check its documentation for the exact MX names.
2. Publish the policy file
Create a host mta-sts.example.com with a valid HTTPS certificate and serve this file at /.well-known/mta-sts.txt with Content-Type: text/plain:
version: STSv1
mode: testing
mx: mx1.example.com
mx: mx2.example.com
max_age: 604800List every MX host. A wildcard such as mx: *.example.net is allowed for one level of subdomain. max_age is in seconds; 604800 is one week. Keep it short while testing.
The file must be served directly. Senders do not follow HTTP redirects when fetching the policy. If you restrict certificate authorities with CAA, make sure the one that issues for mta-sts.example.com is on the list; the article on which CAs to allow in CAA shows the values.
3. Publish the DNS record
_mta-sts.example.com. 3600 IN TXT "v=STSv1; id=20261026T000000"The id is any string of up to 32 letters and digits. A timestamp works well. Senders compare it with the cached value, so you must change it every time you change the policy file. If you rarely edit the zone, the guide to adding DNS records shows where the TXT form sits in common panels.
4. Turn on TLS reports
TLS reporting (TLS-RPT, RFC 8460) makes senders send you a daily summary of successful and failed TLS connections:
_smtp._tls.example.com. 3600 IN TXT "v=TLSRPTv1; rua=mailto:tls-reports@example.com"The reports are JSON files. Read them for a week or two in testing mode. Failures point to an MX host with a bad certificate or a missing entry in the policy.
5. Switch to enforce
When the reports show no failures, change the policy file:
version: STSv1
mode: enforce
mx: mx1.example.com
mx: mx2.example.com
max_age: 1209600Then update the id in the _mta-sts TXT record. A longer max_age (here two weeks) gives better protection; the maximum is 31557600, about one year.
Changing or removing the policy later
When you add or rename an MX host, update the policy file and the id before you switch the MX records. Senders with an old cached policy would otherwise refuse to deliver to the new host.
To remove MTA-STS, publish mode: none with a new id and keep it online for at least the old max_age. Deleting the file and the record at once leaves senders with a cached enforce policy.
How to check it
- Look up the DNS records:
dig +short TXT _mta-sts.example.com
dig +short TXT _smtp._tls.example.com- Fetch the policy and check that it returns status 200,
text/plainand the right MX hosts:
curl -i https://mta-sts.example.com/.well-known/mta-sts.txt- Compare the
mx:lines withdig +short MX example.com. Every MX host must match an entry. - Watch the TLS reports after each change.
MTA-STS protects mail coming to you. Mail you send is protected by SPF, DKIM and DMARC; if those are still on p=none, the path from DMARC p=none to reject is the next step.
MTA-STS only helps when your MX hosts already offer working STARTTLS. The Offensly advanced DNS check tests STARTTLS on your MX hosts, together with DNSSEC, CAA and DANE/TLSA.
Check your own domain in seconds
The free check reads your SPF, DKIM, DMARC and MX records and tells you exactly what to fix. No sign-up.