MTA-STS Setup to Enforce TLS on Your Inbound Email
Your mail server probably accepts TLS, but nothing stops a sending server from quietly falling back to plain text when someone strips the STARTTLS offer in transit.

Your mail server probably accepts TLS, but nothing stops a sending server from quietly falling back to plain text when someone strips the STARTTLS offer in transit. An MTA-STS setup closes that gap by publishing a policy that tells other servers: deliver to me over verified TLS, or do not deliver at all. It takes about an hour, costs nothing beyond a tiny static file, and it is one of the few email records that protects the messages you receive rather than the ones you send.
Below: the DNS record, the policy file, hosting rules, the rollout order I use, and TLS-RPT reporting.
What MTA-STS setup actually changes
SMTP between servers was designed without encryption. STARTTLS was bolted on later as an optional upgrade: the receiving server advertises it, the sender may use it. The weakness is the word "may". If an attacker on the path removes the STARTTLS line from the server greeting, most senders shrug and deliver in clear text. They also rarely check that the certificate matches the hostname, so a forged certificate often works too.
MTA-STS (Mail Transfer Agent Strict Transport Security, RFC 8461) fixes both problems for senders that support it. Gmail, Microsoft 365, Yahoo and most large providers do. When one of them is about to deliver to your domain, it looks up your policy, caches it, and from then on requires:
- a TLS connection, with no downgrade to plain text;
- a certificate valid for the MX hostname, signed by a public authority;
- an MX hostname that matches a pattern in your policy.
If any of those fail and your policy is in enforce mode, the sender queues the message and retries instead of handing it over insecurely. That is the whole point, and also the main risk, which is why the rollout below starts in testing mode.
The three pieces you need to publish
An MTA-STS setup is three small artifacts. None of them touch your mail server configuration directly.
| Piece | Where it lives | Example value |
|---|---|---|
| Policy discovery record | TXT at _mta-sts.yourdomain.com | v=STSv1; id=20261107a |
| Policy file | https://mta-sts.yourdomain.com/.well-known/mta-sts.txt | version, mode, mx, max_age lines |
| Reporting record (TLS-RPT) | TXT at _smtp._tls.yourdomain.com | v=TLSRPTv1; rua=mailto:[email protected] |
The id in the discovery record is just a version string. Senders compare it with what they cached, and only refetch the policy when it changes. A date plus a letter works well because you will bump it every time you edit the file.
Writing the policy file
The policy is a plain text file with one key per line. A testing version for a domain with two MX hosts looks like this:
version: STSv1
mode: testing
mx: mx1.yourdomain.com
mx: mx2.yourdomain.com
max_age: 86400
If you use a hosted provider, list their MX names instead. For Google Workspace that means entries such as aspmx.l.google.com, or a wildcard like *.google.com if you prefer to cover the whole set. Wildcards match one label only, so a wildcard on your provider's domain covers mx1 directly under it but not a host two levels down. Check your actual MX records with dig mx yourdomain.com +short before writing the list, because a single missing host means rejected mail once you enforce.
max_age is in seconds. Start with 86400 (one day) in testing. In enforce mode, most guides suggest 604800 (one week) or more; the RFC allows up to 31557600, about a year.
Hosting the file correctly
This is where most setups fail. The file must be served over HTTPS on the exact hostname mta-sts.yourdomain.com, with a valid public certificate for that name, at the path /.well-known/mta-sts.txt, with a 200 response and a text/plain content type. Redirects are not allowed. A redirect from the mta-sts subdomain to your main site will make senders treat the policy as missing.
Any static host is fine. On a small VPS running Caddy, a site block for the subdomain takes four lines and gets a certificate automatically. Mine is 112 bytes.
Turning on TLS-RPT so you see failures
Without reporting, you are guessing. TLS-RPT (RFC 8460) asks senders to email you a daily JSON summary of every TLS session they attempted with your domain: how many succeeded, how many failed and why. Publish the TXT record from the table above, point it at a mailbox you actually read, and within 24 to 48 hours reports from Google and Microsoft will start arriving as gzipped attachments.
A report with zero failures over a week of testing mode is your signal that enforcing is safe. Failures usually fall into three types: certificate-host-mismatch (your MX certificate does not cover the MX name), sts-policy-fetch-error (the HTTPS file is unreachable or redirected) and validation-failure (an MX host is missing from the policy). If you already parse DMARC reports, the workflow in our guide to reading DMARC aggregate reports without a paid tool adapts easily; TLS reports are simpler JSON and a short jq query is enough.
Why I would not start with DANE instead
A common piece of advice in self hosting forums is to skip MTA-STS and deploy DANE, because DANE uses DNSSEC-signed TLSA records instead of trusting the public certificate authority system. On paper DANE is stronger, and if your DNS host already signs your zone and you run your own MX, it is worth doing as well.
But as a first step for most small domains, I disagree. DANE requires DNSSEC across the whole chain, and many registrars and DNS hosts still make DNSSEC fiddly or fragile. A broken DNSSEC signature does not just hurt mail; it can take the entire domain offline for validating resolvers. DANE also needs your TLSA records updated in sync with every certificate rotation, which Let's Encrypt does every 60 to 90 days. If you use a hosted mail provider, you usually cannot publish DANE for their MX hosts at all, while MTA-STS works fine. Start where the senders are.
A rollout order that will not lose mail
- Check your MX certificates first. Run openssl s_client -starttls smtp -connect mx1.yourdomain.com:25 and confirm the certificate is publicly trusted and names the MX host. Self-signed certificates must be replaced before anything else.
- Publish TLS-RPT. Do it a few days early so you have a baseline.
- Host the policy file in testing mode. Fetch it with curl -I and confirm a 200 and text/plain.
- Publish the _mta-sts TXT record. Use a low TTL such as 300 seconds while you are working.
- Wait at least seven days. Read every TLS-RPT report. Fix anything flagged.
- Switch to enforce. Change mode, raise max_age to 604800, and bump the id in the TXT record so senders refetch.
When you later change MX providers, reverse the order: switch the policy back to testing, bump the id, wait out the old max_age, then move the MX records. Skipping that wait is the classic way to have a week of mail bounce. For more on why delivery problems show up far from their cause, see how email deliverability works, and if you are still sorting out SPF and DKIM, start with email authentication records explained.
Frequently asked questions
Does MTA-STS improve deliverability of the email I send?
No. MTA-STS protects mail coming into your domain by telling other servers how to connect to you. It does not affect spam scoring of your outgoing messages. For outbound reputation, SPF, DKIM, DMARC and a correct PTR record matter much more.
What happens if my MTA-STS policy file goes offline?
Senders that already cached your policy keep using it until max_age expires, so short outages are harmless. A sender with no cached copy treats a missing file as no policy and delivers with ordinary opportunistic TLS. Mail only bounces if the file is gone and the cached enforce policy no longer matches your real MX hosts.
Can I use MTA-STS with Google Workspace or Microsoft 365?
Yes. You publish the TXT records and host the policy file yourself, listing the provider's MX hostnames in the mx lines. The provider's certificates already meet the requirements.
More in Email Infrastructure
Email Infrastructure
One Click Unsubscribe Headers and the Bulk Sender Rules
I send a monthly note to the people who play on the servers I run. It is not marketing.
Email Infrastructure
Why Email Forwarding Breaks SPF and What ARC Fixes
A reader wrote to me in October about invoices that reached half his list and vanished for the rest.
Email Infrastructure
Warming Up a New Sending Domain Without Hitting Spam
You moved the newsletter to a fresh domain on a Monday, sent 8,000 messages on Tuesday, and by Wednesday Gmail was deferring...