MTA-STS setup: enforce TLS for inbound mail

· 5 min read

SPF, DKIM and DMARC protect you from someone sending in your name. They do not protect mail on its way to you from being intercepted in plain text. That is the gap MTA-STS closes, and TLS-RPT tells you whether it works. Both take about an hour to set up if you know the pitfalls.

Create an MTA-STS policy

The problem: STARTTLS is only an offer

SMTP between mail servers is historically unencrypted. STARTTLS lets the sending server upgrade to TLS, but only if the receiving server offers it and both agree. If the handshake fails or the offer is missing, the sender continues in plain text. This is called opportunistic, and it means encryption happens as long as nobody interferes.

An attacker on the network path can exploit exactly that. They strip the STARTTLS offer from the server response and the sender falls back to plain text. Or they tamper with the DNS answer to the MX query and redirect mail to their own server with a valid certificate for their own domain. With classic STARTTLS, the sending server verifies neither the certificate name nor the origin of the MX record.

How MTA-STS works

MTA-STS (RFC 8461) lets the receiving domain publish a policy: these MX hosts are valid, they must offer TLS with a valid certificate, and this rule applies for the given time. Sending servers that support MTA-STS fetch the policy once, cache it and abort delivery if a later connection violates it. A downgrade to plain text is no longer possible.

The policy has two parts. A TXT record at _mta-sts.your-domain.com signals that a policy exists and carries an id that changes with every update. The policy itself is a text file served over HTTPS at mta-sts.your-domain.com/.well-known/mta-sts.txt. The certificate of that host must be valid and issued for the name mta-sts.your-domain.com, otherwise the policy is ignored.

DNS
_mta-sts.example.com.  IN TXT  "v=STSv1; id=20260911120000"

https://mta-sts.example.com/.well-known/mta-sts.txt

version: STSv1
mode: enforce
mx: mail1.example.com
mx: mail2.example.com
max_age: 604800

The fields: mode is none, testing or enforce. mx lines name the permitted hosts; wildcards such as *.mail.protection.outlook.com are allowed for the leftmost label. max_age states in seconds how long senders may cache the policy; one to four weeks is common, one year is the maximum. The file must be served with Content-Type text/plain.

TLS-RPT: reports about failures

Without a feedback channel you do not know whether senders read your policy and whether connections fail. TLS-RPT (RFC 8460) is that channel: a TXT record at _smtp._tls.your-domain.com names an address to which supporting senders mail a daily JSON report. It lists how many connections succeeded and which ones were aborted with which error, for example an expired certificate or an MX host not in the policy.

Google, Microsoft and other large senders deliver these reports. Set up TLS-RPT before MTA-STS so you already receive data in testing mode.

DNS
_smtp._tls.example.com.  IN TXT  "v=TLSRPTv1; rua=mailto:tlsrpt@example.com"

Rollout in three stages

The most important advice: never start with enforce. In testing mode senders check the policy and report violations via TLS-RPT but still deliver. Only when the reports show no errors for at least one to two weeks do you switch.

  1. Create the TLS-RPT record and set up a mailbox or reporting service for the reports.
  2. Determine all MX hosts of the domain and verify that each presents a valid certificate for its hostname. The MX checker shows both.
  3. Publish the policy file with mode: testing and a short max_age of one day at mta-sts.your-domain.com over HTTPS with a valid certificate.
  4. Create the _mta-sts TXT record with an id, for example a timestamp.
  5. Read the reports for two weeks. If errors appear, correct the MX list or the certificates.
  6. Set mode to enforce and max_age to at least one week, and change the id in the TXT record.

The most common mistakes

Almost every MTA-STS problem has one of a handful of causes, and all of them are harmless in testing mode but delivery-critical in enforce mode.

  • The mx lines do not match the real MX hosts: one typo or a forgotten backup MX, and senders refuse delivery to that host.
  • The policy is served over HTTP, via a redirect or with Content-Type text/html: senders ignore it or treat it as invalid.
  • The certificate on mta-sts.your-domain.com has expired or only covers the main domain: the policy is no longer fetched, cached policies stay valid until max_age.
  • The id was not changed after an update: senders keep the old policy in their cache and never notice the new one.
  • MX migration without a policy update: the new hosts are not in the policy, and senders in enforce mode stop delivering.

Google Workspace and Microsoft 365

With hosted mail providers you list their MX hosts. For Google Workspace these are, depending on the setup, smtp.google.com or the older hosts aspmx.l.google.com and alt1 to alt4.aspmx.l.google.com; the lines mx: smtp.google.com, mx: aspmx.l.google.com and mx: *.aspmx.l.google.com cover both. For Microsoft 365 the MX is tenant-tld.mail.protection.outlook.com, and the matching line is mx: *.mail.protection.outlook.com.

You still have to host the policy file yourself because it must live under your domain. Static hosting, a Cloudflare Worker or a Pages project with automatic certificates is enough. After every provider change, verify that the policy still matches the MX records.

MTA-STS and DANE

DANE solves the same problem in a different way: instead of an HTTPS file, the domain publishes TLSA records in DNS, secured by DNSSEC, which bind the certificate directly to the MX host. DANE is technically cleaner but requires DNSSEC for the domain and the MX host, and Google does not evaluate it. Microsoft has supported DANE for inbound mail for a few years now.

The two do not exclude each other. If you already have DNSSEC, you can run DANE and MTA-STS in parallel. For domains on Google Workspace and for most agency clients, MTA-STS is the pragmatic first step.

Frequently asked questions

Do I need MTA-STS if my mail is hosted at Google or Microsoft?
The providers offer TLS but do not force third parties to use it for your domain. MTA-STS is your domain's declaration that senders must demand TLS. For clients with confidential communication it is cheap protection that takes an hour to set up.
Does enforce block mail from senders without MTA-STS support?
No. Senders that do not know MTA-STS ignore the policy and send as before. The policy only affects senders that fetch it, and those then refuse plain text or wrong hosts.
What happens if the policy host goes down?
Senders keep the last fetched policy until max_age expires. A short outage is harmless. A permanent outage means new senders find no policy and deliver without protection, which is why the mta-sts host belongs in your monitoring.
Check now

Free MTA-STS check: DNS record, policy file, mode, max_age and whether your MX servers are covered. Shows whether inbound mail enforces TLS.

DomainWarn monitors MX records, the certificates of the mail hosts and the availability of the MTA-STS policy for every client domain and alerts you when the policy no longer matches the MX hosts.

Monitor this domain continuously14-day free trial, no credit card.

More guides