Skip to content
AdminKit

How do you publish and test MTA-STS for your domain?

MTA-STS lets your domain require that incoming mail only be delivered over TLS with a valid, matching certificate, closing a silent-downgrade gap that ordinary opportunistic STARTTLS leaves open; publish the DNS record plus an HTTPS policy file, then confirm your mail hosts actually resolve with AdminKit's live MX lookup tool before you tighten enforcement.

By AdminKit team, Netbase JSC · Updated

Key takeaways

  • MTA-STS takes two published pieces: a _mta-sts TXT record that carries a policy id, and a plain-text policy file served over HTTPS at https://mta-sts.<domain>/.well-known/mta-sts.txt.
  • Start in mode: testing with TLS-RPT published, read the daily reports, and switch to mode: enforce only once every MX host passes.
  • Every policy change needs a new id in the TXT record. Update the policy file first, then the TXT record, or senders can cache the old file under the new id.
  • Most failures come from three places: an mx line that doesn’t match a real MX host, an MX certificate that doesn’t name that host, or a policy host that doesn’t answer with a valid certificate and a plain 200 response.

What does MTA-STS actually require?

MTA-STS, defined in RFC 8461, lets a domain publish a policy declaring that incoming mail must be delivered over TLS with a valid, matching certificate — and whether a connection that can’t meet that bar should be deferred or rejected. Without it, mail between two TLS-capable servers is usually encrypted only opportunistically, and an attacker in the network path can often force a downgrade to plaintext without either side noticing. NIST’s guidance on trustworthy email (SP 800-177) names this same opportunistic-downgrade gap as a reason to deploy a strict transport mechanism like MTA-STS or DANE rather than relying on STARTTLS alone.

Publishing it takes two pieces: a _mta-sts.<domain> DNS TXT record declaring a policy version ID, and an HTTPS-hosted file at https://mta-sts.<domain>/.well-known/mta-sts.txt listing the mode (none, testing or enforce) and the exact MX hostnames the policy covers. RFC 8461 §3 explains the split: the TXT record lets a sender check with one DNS lookup whether the policy it cached is still current, without an HTTPS request on every message.

RFC 7672 defines DANE for SMTP, a separate mechanism that reaches a similar strict-TLS guarantee via DNSSEC-signed TLSA records instead of a hosted policy file — the two aren’t mutually exclusive, and some domains deploy both. RFC 8461 §2 says a sender must not let a passing MTA-STS check override a failing DANE check; see verifying DANE/TLSA for a mail server for that side.

Step 1: which MX hosts must the policy list?

Every host in your live MX records must match at least one mx line in the policy — a policy that misses a host you added will break delivery to it once enforced. AdminKit’s MX lookup resolves your domain’s MX records and priorities, then checks that up to 5 of the listed hosts actually resolve to an A/AAAA address, so you can see at a glance whether your real mail infrastructure matches what you’re about to write into the MTA-STS policy’s host list.

Matching follows RFC 8461 §4.1, and the wildcard rule is stricter than many people expect:

mx pattern in the policyMX hostMatch?
mail.example.commail.example.comYes, exact name
*.example.commail.example.comYes, the wildcard covers one left-most label
*.example.comexample.comNo, the wildcard needs a label in its place
*.example.commx1.eu.example.comNo, the wildcard never spans two labels
mail.example.commail.example.com.cdn.example.netNo, patterns match whole names only

Prefer exact names where you can. RFC 8461 §10.4 warns that *.example.com makes any host in your domain with a valid CA-signed certificate an acceptable MX from the policy’s point of view. Microsoft’s Exchange Online MTA-STS documentation uses *.mail.protection.outlook.com for its customers but warns this is specific to Exchange Online, not general guidance.

Each MX host must also present a certificate that is unexpired, chains to a trusted root, and carries the MX hostname as a DNS name in its subject alternative name (RFC 8461 §4.2). RFC 8461 §7.2 requires TLS 1.2 or later on MTAs that support MTA-STS.

Step 2: how do you write and host the policy file?

Write the policy as plain key: value lines and serve it from a dedicated HTTPS host. An example for example.com during rollout:

version: STSv1
mode: testing
mx: mail.example.com
mx: mail2.example.com
max_age: 86400

RFC 8461 §3.2 sets the rules for the file:

  • version must be STSv1, and mode must be enforce, testing or none.
  • Each MX pattern gets its own mx: line. At least one is required unless the mode is none.
  • max_age is in seconds, with a ceiling of 31557600 (about one year). The RFC expects production values “in the range of weeks or greater”; its own example uses 604800, one week.
  • Internationalized MX names must be written as Punycode A-labels, not Unicode.
  • Lines end in LF or CRLF, and senders should check that the response’s media type is text/plain.

Host it at https://mta-sts.<domain>/.well-known/mta-sts.txt (a well-known URI) over a valid HTTPS certificate — the file itself is only trustworthy if the connection serving it is. RFC 8461 §3.3 adds three host requirements that trip people up. The certificate must be valid for the mta-sts name itself, such as mta-sts.example.com. The policy only counts if the server answers 200 OK, because senders must not follow redirects. And senders must not use HTTP caching for the fetch. The RFC suggests senders time out after one minute and accept up to 64 kilobytes.

AdminKit’s MTA-STS policy generator builds the policy body and the matching TXT record from your mode, MX patterns, max_age and id in your browser. You still host the file and publish the record yourself. Before relying on the host, run the SSL/TLS check against mta-sts.<domain> to confirm the certificate’s names and expiry date.

Step 3: what goes in the _mta-sts TXT record?

Publish the matching DNS TXT record at _mta-sts.<domain> with a policy ID that changes any time you update the file, so sending servers know to re-fetch it:

_mta-sts.example.com.  TXT  "v=STSv1; id=20261110000000Z"

Under RFC 8461 §3.1 the record must start with v=STSv1, and id is 1–32 letters or digits with no implied ordering. A UTC timestamp, as in the RFC’s own example, is an easy way to keep it unique. If a resolver returns more than one record starting with v=STSv1, senders treat the domain as having no policy at all, so replace the old record rather than adding a second one. The record may also be a CNAME to a TXT record your mail provider maintains (§8.2).

Step 4: add TLS-RPT for visibility

Publish a TLS-RPT record alongside it, defined in RFC 8460, naming an address to receive aggregate reports of TLS delivery failures:

_smtp._tls.example.com. TXT "v=TLSRPTv1;rua=mailto:tls-reports@example.com"

Without this, a strict MTA-STS policy gives you no way to notice a legitimate sender silently failing to deliver — you’d only hear about it if someone complained. RFC 8461 §5 ties testing mode to TLS-RPT directly: in that mode, senders that implement TLS-RPT send reports about policy failures, and deliver the message anyway. AdminKit’s TLS-RPT generator builds this record and the TLS-RPT check confirms it is published with an rua destination. For what the reports contain, see BIMI, MTA-STS and TLS-RPT explained.

Step 5: how long should you test before you enforce?

Long enough for the reports to show every MX host passing. Start with mode: testing, which asks compliant sending servers to report what would have happened without actually blocking delivery. Google Workspace’s MTA-STS policy instructions recommend starting in testing mode for 2 weeks and fixing what the daily reports show before changing to enforce mode. Review the TLS-RPT reports for at least one full reporting cycle, confirm every legitimate sending source lines up with the MX list in your policy (re-running the MX lookup above if you change mail providers or add a host), then move to mode: enforce.

StagePolicy fileTXT idWhat to watch
Testingmode: testing, short max_age such as 86400New valueTLS-RPT reports for sts-* and certificate failures on any MX
Enforcemode: enforce, same mx linesNew valueFailure counts in reports; delivery delays from any sender
Steady statemode: enforce, max_age of weeks, e.g. 604800New valueRe-check after every MX or certificate change
Removalmode: none, small max_age such as one dayNew valueRemove the TXT record and file only after old policies expire

Two things about the switch matter. First, update the policy file before the TXT record: RFC 8461 §8.1 says this avoids senders seeing the new id and caching the old file. Second, senders keep using a cached policy until both pieces change and the TXT record’s TTL has passed, so old MX hosts must keep working during that window; DNS propagation and TTL explains the caching.

max_age cuts both ways: RFC 8461 §10.2 prefers long values because a cached policy resists DNS blocking, but a mistake in an enforced policy also stays cached that long. When an enforced policy blocks delivery, §5 requires senders to check for a new id before failing the message permanently, so publishing a corrected policy with a new id is the fix.

To leave MTA-STS, RFC 8461 §8.3 suggests publishing mode: none with a small max_age, publishing a new id, and removing the TXT record and policy host only after every previously served policy has expired.

Which MTA-STS failures are most common, and how do you fix them?

Most failures appear in TLS-RPT reports under the result types defined in RFC 8460 §4.3, or, once enforced, as deferred mail from senders. Microsoft documents the NDR codes Exchange Online returns when an outbound message fails a recipient domain’s enforced policy: 5.4.8 when the MX host isn’t in the policy, and 5.7.5 when the MX certificate fails validation.

SymptomLikely causeFix
sts-policy-fetch-error in reportsPolicy host unreachable, slow, redirecting, or not answering 200Serve the file directly at the exact URL with 200 OK; no redirect
sts-webpki-invalid in reportsCertificate on mta-sts.<domain> expired or not valid for that nameIssue a certificate that covers mta-sts.<domain>
sts-policy-invalid in reportsSyntax error, missing mx or max_age, wrong versionRebuild the file; one key: value per line
NDR 5.4.8 from Exchange OnlineMX host not matched by any mx lineAdd the exact host, or fix a wildcard that skips a label
certificate-host-mismatch or NDR 5.7.5MX certificate doesn’t name the MX hostReissue the MX certificate with the hostname in its SAN
Policy change ignoredid not changed, or TXT updated before the filePublish the file first, then a new id

RFC 8461 §8.4 adds one subtle case: senders try MX hosts in priority order, so a broken backup MX may only show up when the primary is down. Check every MX host, not just the first.

What can you check with AdminKit, and what is still manual?

AdminKit’s MTA-STS check fetches and validates the policy for you — DNS record, mode (enforce/testing/none), MX list and max_age — alongside MX lookup, SPF check and DMARC check for the rest of your mail setup. It reports a record whose policy file can’t be fetched as “published but broken” rather than “not published”. It does not open a live TLS connection to one of your MX hosts, so a TLS client against each host remains the practical way to confirm the certificate and STARTTLS support match the published policy. Run it from a machine you control, against your own MX hosts only:

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

Check that the certificate chain verifies and that mail.example.com appears among its names. Does your mail server enforce STARTTLS? covers reading that output. See SPF, DKIM and DMARC explained for how MTA-STS’s transport-security guarantee fits alongside those three, separate mail-authentication layers.

Other exposure checks worth running

If you’re reviewing DNS hygiene more broadly, see is your DNS resolver an open resolver and how to find a dangling CNAME — a dangling mta-sts CNAME is worth ruling out too; for a ports-focused check, see how to check if port 123 (NTP) is exposed. This guide sits in AdminKit’s email authentication cluster alongside the live tools and glossary terms that back it.

This guide is general information, not a security audit of your specific network — see our disclaimer for what AdminKit's guidance does and does not commit to.

Frequently asked questions

What does publishing MTA-STS actually involve?

Two pieces: a DNS TXT record at `_mta-sts.<domain>` declaring a policy ID, and an HTTPS-hosted policy file at `https://mta-sts.<domain>/.well-known/mta-sts.txt` listing your domain's allowed MX hosts and a mode — none, testing, or enforce. Both must be in place and match your real mail setup before enforcement has any effect.

Why start in testing mode instead of enforce?

Testing mode asks sending servers to report what *would* happen under your policy without actually blocking non-compliant delivery, so a mismatch between your published MX list and your real mail servers surfaces as a report instead of bounced or delayed mail. Move to enforce only once reports confirm the policy matches reality.

What does AdminKit's MX lookup check here, and what doesn't it check?

AdminKit's MX lookup (/tools/mx-lookup/) is live and resolves your domain's MX records and priorities, then checks that up to 5 of the listed mail hosts actually resolve to an A/AAAA address — exactly the host list your MTA-STS policy file needs to match. It does not fetch or parse the MTA-STS policy file itself, and it does not open a live TLS connection to test whether a host actually enforces TLS; both of those still need to be checked separately, as shown below.

Do I need TLS-RPT too, or is MTA-STS enough on its own?

MTA-STS works without TLS-RPT, but without it you have no visibility into legitimate senders whose mail is silently being deferred or rejected because they couldn't meet your TLS requirement — you'd only find out from a sender complaining. TLS-RPT (a separate DNS TXT record) gives you that visibility, which is why the two are normally deployed together.

When do I need to change the id in the _mta-sts TXT record?

Every time the policy file changes. RFC 8461 §3.1 says the id must uniquely identify one version of the policy, and senders compare it with the id of the policy they cached to decide whether to fetch again. Update the policy file first and the TXT record second (RFC 8461 §8.1), so a sender that sees the new id fetches the new file.

Want AdminKit to watch this for you?

Free checks tell you the state today. Protective DNS and monitoring tell you when it changes.

Huy Nguyen (David), Founder and CEO of Netbase JSC

Talk to an expert

Huy Nguyen (David), Founder & CEO, Netbase JSC

Ask whether this fix applies to your setup, or get a second pair of eyes on your DNS and mail records.