MTA-STS: what it is, how it works and how to set it up

Diagram of MTA-STS with a DNS record, a policy file and encrypted delivery

MTA-STS is a standard that lets your domain tell other mail servers to deliver to you only over an encrypted connection, and only to a server with a valid certificate. You publish one DNS TXT record and one small text file at an HTTPS address. Sending servers that support the standard then refuse to hand your mail to an impostor or to send it in plain text.

The name stands for SMTP MTA Strict Transport Security. It is defined in RFC 8461, published in September 2018. It protects mail arriving at your domain. It does not sign or authenticate the mail you send, which is the job of SPF, DKIM and DMARC.

What is MTA-STS and what problem does it solve?

The standard closes a gap in how mail servers encrypt: without it, encryption between servers is optional and nobody checks who is on the other end. A mail transfer agent (MTA) is the server software that passes email from one host to the next. By default it falls back to plain text when encryption fails.

Encryption between servers normally starts with STARTTLS, the SMTP command from RFC 3207 that upgrades a plain connection to TLS. The receiving server offers it, the sending server accepts, and the session is encrypted. That offer travels in plain text, so an attacker in the path can remove it and the sender carries on unencrypted.

Google's admin help puts the problem in one line: "SMTP alone does not provide security." It adds that when a TLS connection cannot be created, servers often send the message anyway. As of December 2, 2026, that wording is on Google's page About MTA-STS and TLS reporting.

A published policy answers two attacks:

Attack Without a policy With a policy in enforce mode
Downgrade The STARTTLS offer is stripped and the mail goes in plain text The sender delivers over TLS or does not deliver
Impersonation A forged DNS answer points the sender at the attacker's server The MX name has to match the policy, and the certificate has to be valid for that name

How does a sending server use the policy?

A sending server checks DNS for your STS record, fetches your policy file over HTTPS, caches it, and then tests every delivery to your domain against it. The steps come from RFC 8461:

  1. It looks up the TXT record at the _mta-sts label of your domain.
  2. It fetches the policy file from a fixed HTTPS address on your policy host.
  3. It caches the policy for the max_age you set, up to 31557600 seconds, which is about one year.
  4. On each delivery it checks that the MX name matches a line in the policy, that the server offers STARTTLS, and that the certificate is unexpired, chains to a trusted root and names the MX host.
  5. In enforce mode, a host that fails a check gets no mail. The sender treats the failure as temporary and tries again.

Two details of the fetch matter in practice. The sender does not follow HTTP redirects, and only a 200 response counts. The RFC suggests a fetch timeout of one minute and a maximum file size of 64 kilobytes.

The cache is what gives the policy its strength. If an attacker later blocks your DNS record, a sender with an unexpired cached copy still applies it. The RFC advises senders to check for a new version about once a day.

What goes in the TXT record and the policy file?

You publish two things: a TXT record that announces the policy and carries a version id, and a plain text file with four fields. The record is tiny and the file does the work.

_mta-sts.example.com.  3600  IN  TXT  "v=STSv1; id=20261202093000"

The id is 1 to 32 letters or digits. Its only job is to change whenever the file changes, so that senders know to fetch again. A timestamp is the common choice, and the Google and Microsoft instructions both use one.

The file lives at one fixed path on a host named after your domain:

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

version: STSv1
mode: testing
mx: mail.example.com
mx: *.mailhost.example
max_age: 604800
Field Allowed values Notes
version STSv1 The only value. Google's instructions put it on the first line
mode testing, enforce, none What a sender does when a check fails
mx One line per MX host or pattern A wildcard stands for the whole leftmost label only: *.example.com matches mail.example.com, not example.com or a.b.example.com
max_age Seconds, up to 31557600 How long a sender may cache the policy

The web host needs a certificate that is valid for the policy host name and issued by a trusted authority. A self-signed certificate fails. So does a redirect to another host.

Each domain needs its own record and its own file. RFC 8461 says a sender does not look at the parent domain, so if news.example.com receives mail, it needs a separate policy under its own name.

Which mode should you publish first?

Publish testing first, then enforce once the reports are clean. The three modes differ in what a sender does when a check fails.

Mode When a check fails Use it for
testing The sender delivers anyway and can report the failure The first weeks
enforce The sender does not deliver to the failing host and retries Steady state
none The sender treats the domain as having no policy Retiring a policy

Google recommends starting in testing mode for 2 weeks, with a max_age of 604800 to 1209600 seconds while you test, which is 1 to 2 weeks. It accepts values between 86400 and 31557600 seconds and a file of up to 64 KB. As of December 2, 2026, those figures are in Google's instructions to create a policy.

After enforcement, a longer max_age gives more protection, because a cached policy outlives a longer DNS attack. The trade is that a mistake also lives longer. RFC 8461 expects values of weeks or more.

What does TLS-RPT add?

TLS-RPT is the reporting half: a second TXT record that asks sending servers to mail you a daily summary of TLS successes and failures for your domain. It is defined in RFC 8460, titled SMTP TLS Reporting. Without it, testing mode tells you nothing.

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

Reports are JSON files, usually compressed with gzip, and each one covers a UTC day. Here is a shortened illustration in the RFC 8460 format, not a captured report:

{
  "organization-name": "Sender Mail Service",
  "date-range": {
    "start-datetime": "2026-12-01T00:00:00Z",
    "end-datetime": "2026-12-01T23:59:59Z"
  },
  "policies": [{
    "policy": {
      "policy-type": "sts",
      "policy-domain": "example.com"
    },
    "summary": {
      "total-successful-session-count": 1184,
      "total-failure-session-count": 37
    },
    "failure-details": [{
      "result-type": "certificate-expired",
      "receiving-mx-hostname": "mail.example.com",
      "failed-session-count": 37
    }]
  }]
}

The result-type is the field to act on. RFC 8460 defines these for TLS negotiation and for STS policies:

Result type Meaning Where to look
starttls-not-supported The MX host did not offer STARTTLS Mail server TLS settings
certificate-expired The MX certificate has expired Certificate renewal
certificate-host-mismatch The certificate does not name the MX host Certificate names
certificate-not-trusted The certificate does not chain to a trusted root Issuer and intermediate chain
sts-policy-fetch-error The policy file could not be retrieved The web host and its DNS
sts-policy-invalid The policy file failed validation File syntax and fields
sts-webpki-invalid The policy host's HTTPS certificate could not be verified The web host's certificate

Google's help says external servers send these reports daily, and that you might not receive many until more mail providers support TLS reporting. Its instructions add the reporting record before the STS record, so reports start with the first policy fetch. As of December 2, 2026, both points are in the steps to turn on the two records.

How do Google and Microsoft handle it?

Both check policies when they send, and both let you publish one for a domain they host, but neither hosts the policy file for you. As of December 2, 2026, this is what each one documents.

Google Workspace Microsoft 365 (Exchange Online)
When it sends Gmail messages comply with the enforced policies of external servers Outbound mail is validated against the recipient's policy. Always on, no admin action
When it receives You publish the policy. Senders then connect with TLS 1.2 or higher and expect a valid public certificate Applies when your MX record points directly to Exchange Online
Policy file hosting Your own public web server Any web hosting. Microsoft documents an Azure Static Web App
Example in the docs max_age: 604800, mode testing mx: *.mail.protection.outlook.com, max_age: 604800
Source Google admin help Microsoft Learn

When Exchange Online is the sender and an enforced policy fails, the person who sent the message gets a bounce with one of two codes. The texts below are from the Microsoft Learn page linked above, last updated July 21, 2026.

Code Bounce text Cause
5.4.8 MX hosts of '{domain}' failed MTA-STS validation The destination MX host is not in the domain's policy
5.7.5 Remote certificate failed MTA-STS validation. Reason: {validityStatus} The certificate does not chain to a trusted root, or its name does not match the host

Microsoft adds a caution about wildcards. Its own pattern is safe, it says, because of how Exchange Online assigns host names, and the same may not hold for other mail services. Copy the mx lines from your live MX records and not from an example.

A filtering gateway in front of either platform changes the picture. Senders test the gateway's host names and certificates, because that is where your MX record points. Microsoft's page says to confirm that the gateway provider supports the standard and to follow its instructions.

How do you roll it out without losing mail?

Roll out in the order that keeps mail flowing: certificates first, reporting second, testing third, enforcement last. This is the sequence we follow on a client domain.

1. List every MX host

We start with the live MX records, not the documentation. Backup MX hosts and old gateways count.

dig +short MX example.com

2. Test each host's certificate

We check that every host offers STARTTLS and presents a certificate that is unexpired, trusted and issued for that host name:

openssl s_client -starttls smtp -connect mail.example.com:25 -verify_hostname mail.example.com

A host that fails here would fail under enforcement. Fix it before anything is published.

3. Publish the reporting record

Add the TLS-RPT record with a dedicated mailbox, not a person's inbox. Reports are machine mail and they arrive every day.

4. Host the policy in testing mode

Put the file on the policy host with mode: testing and max_age: 604800. Then fetch it the way a sender would:

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

We look for a 200 status, a text/plain content type and no redirect.

5. Publish the TXT record and read the reports

Add the STS record with a first id. Read the reports for two weeks and clear every failure type that appears, one MX host at a time.

6. Switch to enforce

Change mode to enforce in the file first. Then change the id in the TXT record, so that senders fetch the new version. Raise max_age once a few weeks pass without failures.

7. Write the change rule down

From then on the policy is part of every mail migration. Add a new MX host to the file and change the id before the MX record changes, and remove the old host only after the old record is gone. In our work this is the step we plan for hardest, since the change often comes months later and from a different team.

What goes wrong after enforcement?

Failures after enforcement come from a mismatch between what the policy says and what your mail servers present. A sender that supports the standard then holds your mail and retries.

What changed What senders see Fix
A new MX host was added and the policy was not The MX name matches no mx line. Exchange Online returns 5.4.8 Add the host to the file, change the id
A certificate expired on an MX host certificate-expired Renew it
A certificate does not name the MX host certificate-host-mismatch Reissue it with the right names
The policy web host is down or its certificate lapsed sts-policy-fetch-error or sts-webpki-invalid Restore the web host
The file was edited and the id was not changed Senders keep the cached copy Change the id

RFC 8461 tells senders to treat a failed delivery as temporary and to check for an updated policy before giving up. A fix made in time means delayed mail, not lost mail. The sender's retry schedule sets the deadline, and that schedule is not yours to control.

A broken web host has an uneven effect. Senders that hold an unexpired cached copy keep applying it. A sender with no cached copy that cannot fetch the file proceeds as if no policy existed.

What does it not protect against?

The standard leaves four gaps open, and RFC 8461 names the first two itself. None of them is a reason to skip it, but each one sets what you can claim about it.

  • First contact. A sender that has never cached your policy can be kept from discovering it by an attacker who blocks DNS. Protection begins after the first good fetch.
  • A valid certificate in the wrong hands. An attacker who obtains a trusted certificate for your MX name passes the checks.
  • Senders that do not support it. They deliver as before. Microsoft's page says the same of mail arriving at Exchange Online: such senders still deliver, without the extra protection.
  • Anything beyond the connection. TLS covers one hop between two servers. It is not end-to-end encryption of the message.

DANE is the stricter alternative. It publishes certificate data in DNS and depends on DNSSEC, which is why it resists the first contact attack. RFC 8461 says a policy never overrides a failed DANE validation, so the two can run side by side.

Does a policy change where your own mail lands?

A policy governs mail arriving at your domain, so its effect is on the security of your inbound mail. In the Google and Microsoft pages cited here, we found no statement that links it to inbox placement for the mail you send.

What Google does ask of senders is TLS on the sending side. Its email sender guidelines list a TLS connection for transmitting email among the requirements for all senders, in effect since February 1, 2024. That is a rule about your outbound connections. A policy for your own domain is a separate, inbound control.

If your problem is mail going to spam, start with authentication and reputation, not here. Our guide to why emails go to spam covers the causes in order. You can also run the DMARC checker or the free domain check to see what receivers see today.

How do you turn it off safely?

Retire a policy in stages, never by deleting the TXT record first. Senders with a cached enforce policy keep applying it until it expires, even when the record is gone. RFC 8461 gives the order:

  1. Publish a new file with mode: none and a small max_age, such as 86400 seconds, which is one day.
  2. Change the id in the TXT record so that senders fetch the new file.
  3. Wait until every policy you served before has expired. That is the old max_age, counted from the day of the change.
  4. Remove the TXT record and the policy host.

The same logic applies to a move between mail providers. Keep the policy accurate through the move, or step down to testing before it, and return to enforce once the reports for the new hosts are clean.

Drafted with AI assistance from our own records and client work, then reviewed and approved by Kunal Arora. See our editorial policy.