How do you set up MTA-STS?
To set up MTA-STS, you publish a TXT record at _mta-sts.example.com, host a policy file at https://mta-sts.example.com/.well-known/mta-sts.txt that lists your MX hosts, and make sure every MX host presents a valid TLS certificate. Start in testing mode with TLS-RPT reporting, then switch to enforce once reports are clean.
MTA-STS (SMTP MTA Strict Transport Security) is defined in RFC 8461. It tells sending mail servers that your domain expects encrypted, authenticated delivery, so a sender that honours your policy will not quietly fall back to plain text or hand mail to an MX host you never listed. This guide covers the mechanics and the exact setup. If you still need to decide whether a client should have MTA-STS at all, read what is MTA-STS and why businesses should care first. For the wider set of controls, see the email protection pillar.
Key takeaways
- MTA-STS has two parts: a DNS TXT record (
v=STSv1; id=...) that announces a policy exists, and an HTTPS-hosted policy file that holds the rules (version,mode,mx,max_age). - Senders cache the policy for up to
max_ageseconds (maximum 31557600) and only refetch early when theidin DNS changes. Every policy edit needs a newid. - Update the policy file first, then the TXT record. Changing MX records before the policy is the most common way to break inbound mail in
enforcemode. testingmode never blocks mail. Pair it with a TLS-RPT record (_smtp._tls, RFC 8460) so you actually see failures.- MTA-STS protects server-to-server transport for mail sent to your domain. It is not end-to-end encryption and it is not DANE.
How does a sending server discover and apply an MTA-STS policy?
A sending server that supports MTA-STS looks up a TXT record at _mta-sts.<recipient-domain>. If it finds a valid v=STSv1 record, it fetches the policy over HTTPS from the mta-sts subdomain, caches it, and then only delivers to MX hosts that match the policy and present a valid certificate over TLS.
The flow per RFC 8461, step by step:
- TXT lookup. The sender queries
_mta-sts.example.com. Records that do not begin withv=STSv1;are discarded. If exactly one valid record does not remain, the sender treats the domain as having no MTA-STS policy. The record may be a CNAME that leads to the TXT record. - Compare the id. If the sender already holds a cached policy with the same
id, it uses the cache. If theidis new, it fetches the policy. - HTTPS fetch. The sender requests
https://mta-sts.example.com/.well-known/mta-sts.txt. Themta-stshost must present a valid, unexpired certificate for that exact name, chaining to a trusted root. HTTP 3xx redirects must not be followed and only a 200 response counts. The RFC suggests senders apply limits of about one minute and 64 kilobytes. - Cache. The sender caches the policy for up to
max_ageseconds and should refresh it before it expires (the RFC suggests checking about once a day). - Deliver. For each MX host, the sender checks that the name matches an
mxpattern in the policy, that the server offers STARTTLS, and that its certificate is valid for the MX host name. TLS 1.2 or higher is required. - Apply the mode. In
enforce, a failing MX host gets no mail. Intesting, mail is delivered anyway and the failure is reported through TLS-RPT, if both sides support it.
One detail matters for outages: if a valid TXT record exists but the policy cannot be fetched and nothing is cached, RFC 8461 says the sender must continue delivery as though the domain had no MTA-STS. A cached policy, however, is still applied. That is why a broken policy host rarely bounces mail on its own, while a stale cached policy with the wrong MX list does.
What does the MTA-STS TXT record look like?
The TXT record sits at _mta-sts under the policy domain and contains two fields: v=STSv1, which must come first, and id, a string of 1 to 32 letters and digits that changes every time the policy changes. A timestamp works well as the id.
_mta-sts.example.com. 3600 IN TXT "v=STSv1; id=20261119T090000"
The id grammar in RFC 8461 is strictly alphanumeric: 1*32(ALPHA / DIGIT). Dashes, dots, underscores and colons are not allowed, so id=2026-11-19 is invalid. Microsoft's Exchange Online guidance uses the pattern id=20220101080000Z, which is valid because it contains only letters and digits.
What goes in the MTA-STS policy file?
The policy file is a plain-text list of key/value pairs, one per line. It must contain version: STSv1, a mode (enforce, testing or none), at least one mx line for each mail host, and max_age in seconds. Lines are separated by CRLF, and unknown keys are ignored.
A starting policy for a domain with two MX hosts:
version: STSv1
mode: testing
mx: mx1.example.com
mx: mx2.example.com
max_age: 86400
The same domain after a clean testing period:
version: STSv1
mode: enforce
mx: mx1.example.com
mx: mx2.example.com
max_age: 1209600
| Field | Allowed values | Notes from RFC 8461 |
|---|---|---|
version |
STSv1 |
Only version currently defined. |
mode |
enforce, testing, none |
none means the domain is treated as having no active policy. |
mx |
Host name or *. wildcard |
One per line. A wildcard may only be the entire left-most label. Internationalised names in Punycode. |
max_age |
0 to 31557600 seconds | Expected to be weeks or more once stable. 31557600 is about one year. |
How do the three modes behave?
enforce means a compliant sender must not deliver to an MX host that fails name matching, fails certificate validation, or does not offer STARTTLS. testing means the sender may deliver as if nothing failed, but reports failures through TLS-RPT. none withdraws the policy.
Testing mode does not stop a single message, so it is safe to publish on day one. It is only useful if someone reads the reports, which is why the TLS-RPT record belongs in the same change.
How does mx wildcard matching work?
A wildcard in an mx line covers exactly one label on the left. *.example.com matches mail.example.com, but not example.com itself and not foo.bar.example.com. If your MX host names are two labels deep under the suffix, list them explicitly or write the wildcard one level lower.
This trips people up with Microsoft 365. .mail.protection.outlook.com matches example-com.mail.protection.outlook.com. A newer DNSSEC-enabled Exchange Online MX such as contosotest-com.o-v1.mx.microsoft (the example on Microsoft's DANE page) has an extra label, so .mx.microsoft would not match it. Use the exact host name.
Where can you host the MTA-STS policy file?
Any web host that serves https://mta-sts.<domain>/.well-known/mta-sts.txt with a publicly trusted certificate for that host name will do. Static site hosting, object storage behind a CDN, or an existing web server with an extra virtual host are all fine. Microsoft states that Exchange Online cannot host the policy, and Google's guide has you publish it on your own web server.
What the host must get right:
- Certificate for
mta-sts.<domain>. A certificate that covers only the apex orwwwfails. A wildcard certificate for*.example.comcoversmta-sts.example.com. - No redirects. Senders must not follow 3xx responses, so an HTTP-to-HTTPS rule is fine but a redirect from
mta-sts.example.comto another host or path is not. - Content type
text/plain. RFC 8461 says senders should check for it. Some hosts serve unknown files asapplication/octet-streamor wrap them in HTML, so check the header. - Exact path. The file sits under the
.well-knownfolder, and some static hosts skip dot-folders by default. - Availability. Because senders cache the policy, short outages do no harm, but the host must be up when senders refresh.
Microsoft's Exchange Online MTA-STS page walks through one static hosting option on Azure. Google's policy publishing guide states the same requirements: a subdomain starting with mta-sts, a .well-known folder, HTTPS, and a certificate trusted by a third-party root CA.
For an MSP, the useful pattern is one hosting platform for all clients, with one mta-sts host name per client domain pointed at it by CNAME and one policy file per host name. The policy content differs per client, because the mx lines do.
How do you set up MTA-STS step by step?
Check MX certificates, publish TLS-RPT, host the policy in testing mode, publish the _mta-sts TXT record, watch reports, then switch to enforce with a longer max_age and a new id. Each step is reversible until the last one, and even that can be rolled back.
- List the real MX hosts. Run
dig +short MX example.comand write down every host, including backups and gateway hosts. - Check each MX certificate. Every MX host needs a certificate valid for its own name, from a public CA, not expired, over TLS 1.2 or higher (commands below).
- Publish TLS-RPT. Add
_smtp._tls.example.comwith aruaaddress you actually process. - Host the policy file in
mode: testingwith a shortmax_age, such as 86400. - Publish the
_mta-stsTXT record with a freshid. - Verify with
digandcurl, and in the Google Admin console or with your own checks. - Read TLS-RPT reports for a few weeks. The NCSC MTA-STS guidance suggests monitoring for at least a month. Google suggests at least two weeks.
- Switch to enforce. Edit the file to
mode: enforce, raisemax_age(the NCSC recommends at least 1209600, two weeks), then publish a newid.
The TLS-RPT record from RFC 8460:
_smtp._tls.example.com. 3600 IN TXT "v=TLSRPTv1; rua=mailto:tlsrpt@example.com"
Reports arrive as JSON (often gzipped), covering one UTC day each. What they contain and how to read them is covered in TLS-RPT explained, and the split between the two standards is in MTA-STS vs TLS-RPT.
How do you verify an MTA-STS setup from the command line?
Check three things: the TXT record returns one valid v=STSv1 string, the policy URL returns HTTP 200 with text/plain and the right content, and every MX host offers STARTTLS with a certificate that matches its name. dig, curl and openssl cover all three.
# 1. TXT record: expect exactly one v=STSv1 record
dig +short TXT _mta-sts.example.com
# 2. Policy: expect HTTP 200, Content-Type text/plain, no Location header
curl -sSi https://mta-sts.example.com/.well-known/mta-sts.txt
# 3. Line endings and stray characters (CRLF shows as r n)
curl -sS https://mta-sts.example.com/.well-known/mta-sts.txt | od -c | head
# 4. TLS-RPT record
dig +short TXT _smtp._tls.example.com
# 5. MX hosts, then each MX certificate over STARTTLS
dig +short MX example.com
openssl s_client -starttls smtp -connect mx1.example.com:25
-servername mx1.example.com -verify_hostname mx1.example.com </dev/null
In the openssl output, look for Verify return code: 0 (ok). Many cloud networks and home ISPs block outbound port 25, so run that check from a host that can reach it. On Windows, Resolve-DnsName -Name _mta-sts.example.com -Type TXT gives the same TXT answer as dig.
For Google Workspace domains, the Admin console has a check under Apps > Google Workspace > Gmail > Compliance ("Validate your MTA-STS configuration here") and a status view under Security > Security Health > MTA-STS, according to Google's configuration check guide.
What should the mx lines be for Microsoft 365 and Google Workspace?
The mx lines must match whatever your public MX records point to. For a domain that receives mail only through Exchange Online, Microsoft's example policy uses mx: *.mail.protection.outlook.com. For Google Workspace, list the MX values the domain actually uses, such as smtp.google.com.
Microsoft 365. Microsoft's MTA-STS guidance says the *.mail.protection.outlook.com wildcard is suitable only for domains where Exchange Online is the sole receiver, and that domains using more than one provider must list each provider's MX hosts explicitly. If a filtering gateway sits in front of Microsoft 365, your MX points to the gateway, so the mx lines list the gateway's hosts. If the domain moves to the DNSSEC-enabled mx.microsoft endpoint, Microsoft's DANE page says to set the policy to testing, replace the legacy mx row with the new host name, update the id, and only return to enforce after mail flow is verified. Exchange Online also validates MTA-STS on outbound mail automatically. When a destination in enforce mode fails validation, senders get NDR code 5.4.8 (MX not in policy) or 5.7.5 (certificate failed validation).
Google Workspace. Google's MX setup guide gives smtp.google.com as the current MX value and notes that accounts set up before 2023 may still use legacy values beginning with aspmx, which remain supported. Run dig MX and copy what you see into the policy. Google's policy guide requires an mx entry for each MX record, and states that Gmail complies with recipients' enforced MTA-STS policies on outgoing mail.
A Microsoft 365 policy file, once tested:
version: STSv1
mode: enforce
mx: *.mail.protection.outlook.com
max_age: 604800
A Google Workspace policy file for a domain on the current MX value:
version: STSv1
mode: enforce
mx: smtp.google.com
max_age: 1209600
How do you change MX hosts or roll back an MTA-STS policy?
Always edit the policy file first and the TXT record second. Add the new MX host to the policy, publish a new id, wait until senders have had time to refresh, and only then change the MX records. To roll back, set mode: testing or mode: none in the file and publish a new id.
RFC 8461 says recipients "SHOULD also update the HTTPS policy body before updating the TXT record", otherwise a sender can see the new id, fetch the old file and cache it. A safe MX migration in enforce mode:
- Add the new host as an extra
mxline, keeping the old one. Optionally drop totestingfor the duration. - Publish a new
idin the TXT record. - Wait at least the TXT record's TTL, plus margin for senders' refresh cycles.
- Change the MX records.
- Once the old host no longer receives mail, remove its
mxline and publish another newid.
To remove MTA-STS entirely, the RFC's procedure is: publish a policy with mode: none and a short max_age, publish a new id so senders fetch it, wait until previously served policies have expired, then delete the TXT record and the policy host. Deleting the TXT record first leaves senders running on whatever they cached, for up to max_age.
What are the most common MTA-STS setup errors?
Most failures come from a short list: an MX host missing from the policy, a certificate on the MX or mta-sts host that does not match the name, an invalid id, a redirect on the policy URL, or a policy change published without a new id. TLS-RPT reports and the checks above catch all of them.
| Symptom | Likely cause | Fix |
|---|---|---|
| Policy never picked up | id contains dashes or dots, or two v=STSv1 TXT records exist |
One record, alphanumeric id only |
| Fetch fails | Certificate does not cover mta-sts.<domain>, or the URL redirects |
Issue a certificate for the host name, serve the file directly |
| Fetch fails or is rejected | Wrong path or wrong content type | /.well-known/mta-sts.txt, Content-Type: text/plain |
| Mail to a backup MX fails | Backup host not in the mx lines |
Add every MX host, then a new id |
| Wildcard does not match | MX host is two labels deep under the wildcard suffix | List the exact host name |
| Old policy keeps applying | File edited but id unchanged |
Publish a new id |
| Certificate failures in reports | Self-signed or expired MX certificate, or name mismatch | Public CA certificate valid for the MX host name |
| Policy rejected | max_age above 31557600 |
Use a value within the limit |
What does MTA-STS not do?
MTA-STS only protects the hop from a sending mail server to your MX hosts, and only when the sender supports it. It does not encrypt messages end to end, does not protect mail at rest, does not cover the mail your domain sends, and does nothing about spoofing. It is also a separate mechanism from DANE.
- Not end-to-end. Mail is decrypted at each server. Content protection needs S/MIME or a similar message-level tool, as explained in does DKIM encrypt email?
- Inbound only. Your policy protects mail sent to your domain. Mail you send is protected by the recipient's policy, if they have one.
- Trust on first use. The very first fetch is not protected by a prior policy, which is why long
max_agevalues matter once you enforce. - Not DANE. DANE for SMTP pins certificates in DNS using DNSSEC and TLSA records (RFC 7672). MTA-STS relies on the public CA system and HTTPS instead. A domain can publish both.
- Not authentication. SPF, DKIM and DMARC (RFC 9989) prove who sent a message. MTA-STS failures do not show up in DMARC aggregate reports, only in TLS-RPT reports.
How should an MSP roll out MTA-STS across a client portfolio?
Treat MTA-STS as a per-domain change with one shared hosting setup. Inventory every client's MX hosts, fix certificates first, publish TLS-RPT everywhere, run all domains in testing, and move each domain to enforce only when its reports are clean. Record the MX-change dependency in your change process.
A checklist that works across tens or hundreds of domains:
- Inventory. For each domain, record MX hosts, the mail platform (Microsoft 365, Google Workspace, gateway, on-premises), and who controls DNS.
- Exclude parked and non-mail domains or give them a deliberate decision, rather than a template policy listing MX hosts that do not exist.
- Shared hosting. One static host or CDN, a CNAME per client
mta-stshost name, automated certificate renewal, and policy files kept in version control. - Standard
idformat. A UTC timestamp such as20261119T090000, generated by the same script that publishes the file. - TLS-RPT first. A reporting address per client or a shared mailbox you parse, so failures are attributed to the right domain.
- Change control. Add "update MTA-STS policy and
idfirst" to every MX change, gateway onboarding and tenant migration runbook. - Monitoring. Alert on expiring certificates for both the
mta-stshosts and MX hosts, and periodically compare live MX records against themxlines. - UK clients. The NCSC page notes that Mail Check no longer processes TLS reporting, so point
ruaat your own collection rather than a legacy NCSC address.
Clients usually ask why this sits next to their DMARC work. The short answer: DMARC tells receivers whether mail claiming your domain is genuine, and MTA-STS tells senders how to deliver mail to you securely. They answer different questions, and the modern email security stack article shows how they fit together.
FAQ
How long should max_age be?
Start short while testing, for example 86400 seconds (one day), so mistakes expire quickly. Once in enforce mode, use weeks: the NCSC recommends at least 1209600 seconds (two weeks), and RFC 8461 allows up to 31557600 seconds (about one year). Longer values protect better against attacks on the first fetch.
Does the mta-sts subdomain need its own certificate?
It needs a certificate that is valid for mta-sts.yourdomain, issued by a publicly trusted CA. That can be a dedicated certificate or a wildcard certificate covering the parent domain. A certificate for only the apex domain or www fails, and senders then behave as if no policy exists unless they have one cached.
Will testing mode block any email?
No. RFC 8461 says that in testing mode, senders may deliver messages as though there were no MTA-STS validation failure. Senders that support TLS-RPT send a report of the failure instead, provided your domain publishes a _smtp._tls record. That is what makes testing mode safe to deploy first.
Do I need to change the id if I only change max_age?
Yes. Senders only refetch a cached policy early when the id in the TXT record changes. If you edit any part of the file, including mode, mx or max_age, without a new id, senders keep using the cached version until its own max_age runs out.
Can I use MTA-STS and DANE together?
Yes. RFC 8461 says MTA-STS is designed not to interfere with DANE where the two overlap, and that a passing MTA-STS check must never override a failing DANE check. Senders that validate DNSSEC can use your TLSA records, while senders that only support MTA-STS use your policy file.
Final thoughts
Setting up MTA-STS takes one TXT record, one small text file on HTTPS and certificates that match your MX names. The work that matters is operational: keep the mx lines in step with real MX records, change the policy before the DNS, bump the id every time, and read TLS-RPT before enforcing. Do that per client and MTA-STS becomes a routine part of a managed email service rather than a source of surprise bounces.