Skip to main content
← Back to all posts
Email Authentication · 12 min read

MTA-STS on Google Workspace and Microsoft 365, without losing mail.

Every guide tells you to list your MX hosts. None tell you which hostnames Google actually uses, why the Microsoft one has a hyphen where your domain has a dot, or what happens to inbound mail when you change providers while a policy is still cached. Those are the three things that bounce mail. Here are all three.

By EmailSheriff · · 12 min read · Practical
5
MX hosts a Google Workspace policy must cover
1
MX host for most Microsoft 365 tenants - and it is unique to you
4 weeks
from first record to safe enforcement
0
web servers you need to run to host the policy

Almost every MTA-STS guide stops at "publish a policy file listing your MX hosts." That is the easy part. The part that loses mail is which hostnames go in the list, and that answer is completely different depending on whether you are on Google Workspace or Microsoft 365, and different again if you have a security gateway in front.

This guide gives you the exact policy file for each, the hosting options that do not require running a web server, and the migration sequence that stops a provider change from bouncing your inbound mail.

1. The short version, if you already know what MTA-STS is

MTA-STS is Mail Transfer Agent Strict Transport Security. It publishes a policy telling every server that delivers mail to you: use validated TLS, only deliver to these MX hosts, and if you cannot, refuse to deliver rather than falling back to plaintext. It closes the STARTTLS downgrade hole that has existed since 1999, and it governs mail arriving at your domain, not mail you send.

Three things to publish:

  1. A TXT record at _mta-sts.yourdomain.com
  2. A policy file at https://mta-sts.yourdomain.com/.well-known/mta-sts.txt
  3. A TLS-RPT record, so you can see whether any of it works

Skip to Google Workspace or Microsoft 365 for the exact files.

Read this before you publish anything

MTA-STS in enforce mode is the only email mechanism where a configuration error stops mail arriving rather than affecting where it lands. SPF, DKIM and DMARC influence placement. A wrong mx: list means senders refuse delivery outright. Start in testing. Every time.

2. MTA-STS for Google Workspace

Google Workspace uses five MX hosts. All five must be covered by your policy, or you risk bouncing mail during failover when Google routes to the lower-priority hosts.

https://mta-sts.yourdomain.com/.well-known/mta-sts.txt
version: STSv1 mode: testing mx: aspmx.l.google.com mx: alt1.aspmx.l.google.com mx: alt2.aspmx.l.google.com mx: alt3.aspmx.l.google.com mx: alt4.aspmx.l.google.com max_age: 86400

Some Workspace tenants, older ones especially, and those provisioned through resellers, also use aspmx2.googlemail.com through aspmx5.googlemail.com. Check your own MX records rather than trusting any list, including this one. Run dig MX yourdomain.com +short, or use our DNS Checker, and put every hostname it returns into the file.

The safer form, which also covers hosts you have not seen yet:

version: STSv1 mode: testing mx: *.l.google.com mx: *.googlemail.com max_age: 86400

Wildcards are legal for the leftmost label only. *.l.google.com matches aspmx.l.google.com and all four alt hosts. This is what we would publish for Workspace, because it survives Google adding a host without telling you.

Google Workspace specifics worth knowing

  • Google does not host the policy file for you. Unlike DKIM, which Workspace generates in the admin console, MTA-STS hosting is entirely your problem. See section 4.
  • Gmail is a compliant sender. Once you enforce, mail from Gmail users to your domain is subject to your policy. Google was among the first large adopters, which cuts both ways.
  • Workspace MX certificates are managed by Google and will validate correctly. You should never see certificate-expired for the MX hosts themselves. If a Workspace domain reports certificate failures, look at the mta-sts subdomain instead.

3. MTA-STS for Microsoft 365

Microsoft 365 is simpler in one way and more dangerous in another. Simpler because each tenant normally has a single MX host. More dangerous because that hostname contains your domain name, so it is unique to you and easy to get wrong when copying from a guide.

Your MX host looks like this
yourdomain-com.mail.protection.outlook.com

Note the hyphen. Microsoft replaces the dot in your domain with a hyphen, so acme.com becomes acme-com.mail.protection.outlook.com. Get that wrong and, in enforce mode, nothing arrives.

https://mta-sts.yourdomain.com/.well-known/mta-sts.txt
version: STSv1 mode: testing mx: yourdomain-com.mail.protection.outlook.com max_age: 86400

The wildcard form, which we prefer because it survives tenant migrations and Microsoft's regional routing changes:

version: STSv1 mode: testing mx: *.mail.protection.outlook.com max_age: 86400

Microsoft 365 specifics worth knowing

  • Exchange Online Protection honours MTA-STS on outbound. Microsoft is a compliant sender as well as a receiver.
  • Multi-geo and hybrid tenants can have more than one MX host. If you run Exchange hybrid, your on-premises host must be listed too, and its certificate must be valid and match its hostname. This is the most common way a Microsoft deployment loses mail.
  • Tenant migrations change the hostname. Renaming a tenant, or moving a domain between tenants, changes your MX host. Update the policy and the id before the MX change, not after.

If you have a security gateway in front

Mimecast, Proofpoint, Barracuda and similar products replace your MX records with theirs. Your policy must list the gateway's hosts, not Google's or Microsoft's, because the gateway is what senders actually connect to.

# Example: Mimecast, EU region version: STSv1 mode: testing mx: *.mimecast.com max_age: 86400

Read your live MX records. Whatever they point at belongs in the file. This sounds obvious and it is still the mistake we see most, because people configure MTA-STS from a guide about their mail platform rather than from their own DNS.

4. Hosting the policy file without running a web server

You need mta-sts.yourdomain.com serving one small text file over HTTPS with a valid certificate. You do not need a web server, and you should not stand one up for this.

Cloudflare Workers

Free tier, automatic certificate, about six lines. Route mta-sts.yourdomain.com/* to a Worker:

export default { fetch() { return new Response( "version: STSv1\nmode: testing\nmx: *.l.google.com\nmax_age: 86400\n", { headers: { "content-type": "text/plain" } } ); } };

Editing the policy becomes a one-line change with no DNS propagation to wait for.

GitHub Pages

Free, and the certificate renews itself. Create a repository, add .well-known/mta-sts.txt, enable Pages, point a CNAME at it from mta-sts.yourdomain.com, and turn on Enforce HTTPS. GitHub Pages ignores directories starting with an underscore, but .well-known starts with a dot, so it serves fine. Add an empty .nojekyll file if you hit anything strange.

Netlify, Vercel, S3 behind CloudFront

All work. The requirements are identical everywhere: HTTPS with a certificate valid for mta-sts.yourdomain.com, and Content-Type: text/plain. Serving the file as text/html causes some senders to reject it.

The certificate that actually matters

Not your mail servers. The one on mta-sts.yourdomain.com. If it expires, senders silently stop being able to read your policy, and your protection switches off with nothing to alert you. It fails open, which is merciful, but it also means nobody notices for months.

Use a host with automatic renewal. A manually renewed certificate on this subdomain will eventually lapse, and you will not find out from your monitoring.

5. The DNS records

# Announce the policy _mta-sts.yourdomain.com. IN TXT "v=STSv1; id=20260728120000" # The hostname serving the policy file mta-sts.yourdomain.com. IN CNAME yourorg.github.io. # Reporting, so you can see whether any of this works _smtp._tls.yourdomain.com. IN TXT "v=TLSRPTv1; rua=mailto:[email protected]"

The id is an opaque string you change every time you edit the policy. Senders cache your policy for max_age seconds and only re-fetch when the id changes. A timestamp is conventional because it is unique and self-documenting.

Forgetting to change the id is the single reason most people conclude MTA-STS is broken. They edit the policy, nothing happens, and they assume nobody supports it. Senders are simply still serving the cached copy, exactly as designed.

6. The rollout sequence that does not lose mail

WeekDo thisWait for
0Publish TLS-RPT onlyFirst reports, 24–48h
1Fix whatever the reports surfaceZero failures for 7 days
2Publish policy in mode: testing plus the _mta-sts TXTZero sts-* failures
4Switch to enforce, raise max_age, change the idNothing. You are done.

Four weeks feels slow. It is the difference between switching on enforcement with a month of evidence and switching it on with a hope. The only step that can cost you mail is the last one, and by the time you reach it you have watched the system work.

Once enforcing, raise max_age to 604800 or higher. A longer cache means an attacker who blocks access to your policy file cannot strip your protection quickly.

7. Changing mail providers with MTA-STS live

This is the scenario that bites people, and almost no guide covers it.

You are migrating from Google Workspace to Microsoft 365. You update MX records. Mail stops arriving from every compliant sender, because they are still enforcing your cached policy, which lists Google's hosts. Your new Microsoft host is not in it, so they refuse delivery. This continues until max_age expires, which could be a week.

The correct order:

  1. Before touching MX: add the new provider's hosts to the policy alongside the old ones, and change the id.
  2. Wait for max_age to elapse so every cached copy has expired. If max_age is 604800, that is a full week.
  3. Now change your MX records. Both old and new hosts are permitted, so mail flows either way during the cutover.
  4. Once migration is complete and stable, remove the old hosts and change the id again.

If you need to move faster than max_age, drop the policy to mode: testing and change the id first. Testing mode delivers regardless of TLS outcome, so it removes the risk entirely while you migrate. Return to enforce afterwards.

8. Verifying it works

Three checks, in order.

Is the TXT record live?
dig +short TXT _mta-sts.yourdomain.com # "v=STSv1; id=20260728120000"
Is the policy readable, over HTTPS, as text/plain?
curl -sI https://mta-sts.yourdomain.com/.well-known/mta-sts.txt | head -3 # HTTP/2 200 # content-type: text/plain curl -s https://mta-sts.yourdomain.com/.well-known/mta-sts.txt

If curl reports a certificate problem, senders will hit the same one and ignore your policy entirely.

Does the certificate match the hostname?
openssl s_client -connect mta-sts.yourdomain.com:443 \ -servername mta-sts.yourdomain.com </dev/null 2>/dev/null \ | openssl x509 -noout -subject -dates

Then confirm from the outside. Our Deliverability Score checks MTA-STS, TLS-RPT, SPF, DKIM, DMARC, reverse DNS and blacklists in one pass, so you can see what a sending server sees rather than what your own network sees.

9. Frequently asked questions

How do I set up MTA-STS on Google Workspace?

Publish a policy file at https://mta-sts.yourdomain.com/.well-known/mta-sts.txt listing all five Google MX hosts.aspmx.l.google.com and alt1 through alt4, or use the wildcard mx: *.l.google.com. Add a TXT record at _mta-sts.yourdomain.com containing v=STSv1; id= and a timestamp. Google does not host the policy file for you, so you need a static HTTPS host such as Cloudflare Workers or GitHub Pages. Start in mode: testing.

What is the Microsoft 365 MX host for my MTA-STS policy?

It follows the pattern yourdomain-com.mail.protection.outlook.com, with the dot in your domain replaced by a hyphen. Because it is tenant-specific, always read it from your live MX records rather than copying from a guide. The wildcard mx: *.mail.protection.outlook.com is safer and survives tenant or regional changes. Hybrid Exchange deployments must also list their on-premises hosts.

Can I use a wildcard in an MTA-STS policy?

Yes, for the leftmost label only. mx: *.l.google.com is valid and matches every Google MX host. You cannot wildcard in the middle of a hostname. Wildcards are the safer choice for hosted mail platforms, because they survive the provider adding hosts you were never told about.

Where should I host the MTA-STS policy file?

Anywhere that serves static files over HTTPS with an automatically renewing certificate. Cloudflare Workers, GitHub Pages, Netlify, Vercel and S3 behind CloudFront all work and all have free tiers. The requirements are a valid certificate for mta-sts.yourdomain.com and Content-Type: text/plain. Avoid anything with manual certificate renewal, because a lapsed certificate silently disables your policy with no alert.

Why is my MTA-STS policy not updating?

Almost certainly because you edited the policy file but did not change the id value in the _mta-sts TXT record. Senders cache your policy for max_age seconds and only re-fetch when the id changes. Set the id to a new timestamp and senders will pick up the edit on their next check.

How do I change mail providers without MTA-STS bouncing my mail?

Add the new provider's MX hosts to your policy alongside the existing ones and change the id before you touch MX records. Wait for max_age to elapse so every cached copy expires, then switch MX. Remove the old hosts once the migration is stable. If you need to move faster, drop to mode: testing first, it delivers regardless of TLS outcome, removing the risk during the cutover.

Does MTA-STS improve my email deliverability?

Not directly. MTA-STS governs mail arriving at your domain, not mail you send, so it has no effect on whether your campaigns reach the inbox. Its value is privacy and integrity for inbound mail, a concrete control for compliance audits under GDPR Article 32, and a small positive posture signal alongside SPF, DKIM and DMARC. We weight it at two points out of fifteen in our infrastructure score, deliberately low.

Check your MTA-STS policy from the outside

The Deliverability Score checks MTA-STS, TLS-RPT, SPF, DKIM, DMARC, PTR and blacklists in one pass, so you see exactly what a sending server sees, before you enforce.

Run a free check →
+ Related tools
Deliverability Score
Checks MTA-STS, TLS-RPT, SPF, DKIM, DMARC, PTR and blacklists in one pass.
DNS Checker
Read your live MX records - the list your policy has to match exactly.
CRM DNS Verifier
Platform-specific DNS checks for HubSpot, Salesforce, Mailchimp, Zoho and more.