Email Marketing & AutomationMartech Zone AppsMartech Zone Builders

MTA-STS Builder: Require Encrypted Email Delivery and Stop STARTTLS Downgrade Attacks

Every time someone emails your domain, the sending server and your mail server negotiate in the open. The sender asks whether you support encryption, your server says yes, and the two upgrade the connection with STARTTLS. That invitation travels in plaintext, though, and anyone sitting on the network path can erase it. When that happens, most senders shrug and deliver the message unencrypted, because the protocol was designed to prefer delivery over privacy.

MTA-STS closes that gap. It lets you publish a policy that tells Gmail, Microsoft 365, and other supporting senders to deliver mail to your domain only over TLS, only to the MX hosts you list, and only when those hosts present a valid, trusted certificate. If an attacker strips encryption or reroutes your mail to a server they control, a sender that honors your policy refuses to hand the message over instead of leaking it.

The builder below creates both pieces you need: the policy file you host over HTTPS and the TXT record that announces it. It can import your current MX hosts from DNS, generate hosting configuration for a Cloudflare Worker, nginx, or Apache, and check what any domain publishes today.

MTA-STS Builder v1.0.0Last Update: Nov 18, 2026

Enter your domain and the mail servers that receive its email to build an MTA-STS policy file and its _mta-sts TXT record, or check what the domain publishes today.

Optional — The domain that receives mail, the part after the @ in your addresses. Each subdomain that receives mail needs its own policy.
Optional — testing: senders report TLS failures but still deliver. enforce: senders refuse to deliver when TLS or the MX check fails. none: retire a policy.

Check Live Policy Import Current MX

Optional — Every server listed in your MX records must match one line. Use a full host name such as mx1.example.com, or a wildcard such as *.example.com, which matches exactly one label (mx1.example.com, not example.com or a.b.example.com).
Optional — How long senders may cache the policy. Short while testing so changes take effect quickly; weeks or longer at enforce. The maximum is 31557600 seconds (about one year).
Optional — Up to 32 letters and digits. Senders compare it with the id they cached, so publish a new id every time you change the policy file.
Serve this file over HTTPS at the address shown below, with a 200 response, the text/plain content type, and no redirects.

Copy Policy Download mta-sts.txt

The TXT value to publish. The host name is shown below it and is not part of this string. Publish it after the policy file is live.

Copy TXT Record

    The policy needs its own mta-sts subdomain with a valid HTTPS certificate for that name. Pick where you will serve it to get a ready-made configuration.
    • Create the mta-sts subdomain in DNS (an A, AAAA, or CNAME record) and point it at the host that serves the file.
    • The HTTPS certificate must be valid for mta-sts.example.com and chain to a public certificate authority. A self-signed or mismatched certificate makes senders ignore the policy.
    • Static hosts such as GitHub Pages, Netlify, or Cloudflare Pages work too: publish the file at /.well-known/mta-sts.txt, attach the custom domain, and make sure the host does not skip dot-folders or redirect the path.

    Copy Configuration

    Was this helpful?

    What MTA-STS Does

    MTA-STS is an IETF standard published in 2018 as RFC 8461. It’s a receiving-domain policy: you publish it to protect mail coming into your domain. The policy makes three promises to every sender that checks it:

    • Encryption is mandatory. Your mail servers support TLS, so a sender should never fall back to plaintext.
    • These are my real mail servers. Only hosts that match the mx: patterns in your policy are legitimate destinations, which defeats forged MX answers.
    • The certificates are real. Each MX host presents a certificate from a public certificate authority that is valid for its own host name, so a sender can tell your server from an impostor.

    MTA-STS doesn’t authenticate who sent a message. That’s the job of SPF, DKIM, and DMARC. MTA-STS protects the transport between servers, so the message can’t be read or altered in transit and can’t be diverted to the wrong server. The two layers complement each other: one proves the mail is yours, the other keeps it private on the way to you.

    The Problem: STARTTLS Downgrade and Man-in-the-Middle Attacks

    Server-to-server email runs over SMTP, a protocol older than the web. Encryption was bolted on later through STARTTLS, which is opportunistic: a sender connects in plaintext, looks for 250 STARTTLS in the receiving server’s capabilities, and upgrades if it sees it. If the capability is missing, or the certificate looks wrong, nearly every server delivers anyway.

    That design leaves two openings for a MITM attacker:

    • STARTTLS stripping. A device on the network path deletes or corrupts the STARTTLS capability. The sender believes your server doesn’t support encryption and sends the message in cleartext, where it can be read or copied.
    • MX and certificate spoofing. An attacker who can poison DNS answers points your MX at their own server. Because opportunistic TLS doesn’t verify certificates, the sender happily encrypts the message to the attacker.

    These aren’t theoretical. Researchers measuring mail delivered to Gmail found network devices actively stripping encryption at national scale.

    In an analysis of mail delivered to Gmail, researchers found seven countries where more than 20% of inbound messages arrived in cleartext because of network attackers. In the most severe case, 96% of messages sent from Tunisia to Gmail were downgraded to cleartext.

    Zakir Durumeric et al., Neither Snow Nor Rain Nor MITM… An Empirical Analysis of Email Delivery Security, ACM Internet Measurement Conference

    Nothing in plain SMTP tells the sender that something went wrong. MTA-STS gives senders that missing signal: a policy, fetched over authenticated HTTPS and cached, that says encryption with a valid certificate is required for your domain.

    Why MTA-STS Matters Now

    For years, the largest mailbox providers have been turning transport encryption from a courtesy into an expectation, and MTA-STS is how a receiving domain holds senders to it.

    • Gmail enforces it. Google announced in April 2019 that Gmail would become the first major email provider to follow MTA-STS and TLS-RPT, honoring the policies of domains it sends to (Google Security Blog).
    • Microsoft enforces it. Exchange Online validates MTA-STS for all outbound messages and describes the check as always on, like other core SMTP features. Protecting your own inbound mail still requires you to publish a policy (Microsoft Learn).
    • TLS is now a sender requirement. Google added use a TLS connection for transmitting email to its Gmail sender guidelines in December 2023. Encryption is the baseline senders already meet, and MTA-STS lets you require it on the receiving side too.
    • Government guidance recommends it. The UK government’s TLS-RPT and MTA-STS guidance walks departments from reporting through testing to enforce, and NIST’s SP 800-177 Rev. 1 recommends that receiving domains signal TLS with DANE, MTA-STS, or both.

    Receiving domains should implement protocols to signal TLS usage to clients. Receivers should implement DANE, MTA-STS (or both) for all mail servers listed in the domain’s MX Resource Record set.

    NIST, SP 800-177 Rev. 1, Trustworthy Email, Security Recommendation 5-3, 2019

    For marketers, the stakes are practical. Password resets, invoices, contracts, lead notifications, and customer replies all land in your domain’s inboxes. A policy keeps that traffic encrypted, gives your security and compliance teams evidence that inbound mail is protected in transit, and, paired with TLS reporting, surfaces delivery problems you’d otherwise never see. MTA-STS doesn’t directly change inbox placement for the mail you send. It protects the mail you receive.

    Adoption is still low, which means most domains, including many of your competitors and partners, are leaving this protection on the table.

    MTA-STS adoption across the top 1 million domains grew from 2,975 domains (0.3%) in 2024 to 5,155 (0.5%) in 2025 and 7,377 (0.7%) in 2026. Among domains that publish a policy, about 54% use enforce and about 45% use testing.

    Freddie Leeman, URIports, MTA-STS Adoption: Three Years of Steady Growth, January 6, 2026

    In a survey of 117 email operators, 94.7% were aware of MTA-STS, yet operators cited operational complexity (48.8%) and a preference for DANE (45.4%) as reasons for not deploying it.

    Md. Ishtiaq Ashiq, Tobias Fiebig, and Taejoong Chung, Unraveling the Complexities of MTA-STS Deployment and Management in Securing Email, ACM Internet Measurement Conference, 2025

    How MTA-STS Works, Step by Step

    Here’s what a supporting sender does when it has a message for you@example.com:

    1. Looks up the policy record. The sender queries the TXT record at _mta-sts.example.com. If it finds v=STSv1; id=…, the domain participates.
    2. Fetches the policy over HTTPS. The sender downloads https://mta-sts.example.com/.well-known/mta-sts.txt. The web server’s certificate must be valid for mta-sts.example.com, the response must be a 200, and redirects are never followed.
    3. Caches the policy. The sender stores the policy for up to max_age seconds and remembers the id. It only refetches when the id in DNS changes or the cache is about to expire.
    4. Resolves your MX hosts. The sender looks up your MX records as usual and keeps only the hosts that match an mx: pattern in the policy.
    5. Requires TLS with a valid certificate. For each matching host, the sender insists on STARTTLS and checks that the server’s certificate chains to a trusted public authority and is valid for that MX host name.
    6. Applies the mode. In enforce, a host that fails the checks gets no mail; the sender tries the next valid MX and otherwise keeps the message queued and retries. Before it gives up for good, it checks DNS for a newer policy id, so you can fix a mistake on the fly. In testing, the sender delivers anyway and records the failure for TLS reporting.

    Because the policy is cached, an attacker who later strips STARTTLS or spoofs your MX can’t talk a sender out of encryption. The sender already knows your rules. The trade-off is trust on first use: protection begins after a sender’s first successful policy fetch, which is why a longer max_age makes the policy more resilient.

    A detail that trips up subdomains: senders never fall back to the parent domain. Mail to user@mail.example.com uses only the policy for mail.example.com, so every domain that receives mail needs its own record and policy host.

    The Two Pieces You Publish

    The _mta-sts TXT Record

    The DNS record signals that a policy exists and identifies its current version:

    Host: _mta-sts.example.com
    Type: TXT
    Value: v=STSv1; id=20261118T120000Z;
    • v=STSv1 must come first.
    • id is 1 to 32 letters and numbers. Change it every time you change the policy file, or senders keep using their cached copy until max_age runs out. A timestamp works well, which is what the builder generates.
    • Publish exactly one record. Two MTA-STS TXT records make the policy invalid. A CNAME to a provider’s record is allowed if a hosted service manages it for you.

    The Policy File

    The policy is a plain text file served at a fixed path on a fixed host:

    https://mta-sts.example.com/.well-known/mta-sts.txt
    
    version: STSv1
    mode: testing
    mx: mx1.example.com
    mx: mx2.example.com
    mx: *.mail.example.net
    max_age: 604800
    FieldRequiredWhat It Does
    versionYesMust be STSv1.
    modeYesenforce, testing, or none.
    mxYes, except with noneOne line per allowed MX host or wildcard pattern. Repeat the field for each host.
    max_ageYesHow many seconds senders may cache the policy, up to 31557600 (about one year).

    Lines end with CRLF, the file should be served as text/plain, and anything after a field you don’t need, such as stray HTML from a web server error page, breaks parsing. The builder outputs the exact format and lets you download a ready-to-host mta-sts.txt.

    Policy Modes: None, Testing, and Enforce

    ModeWhat Senders DoWhen to Use It
    testingDeliver even when TLS or certificate checks fail, and report the failure through TLS-RPTEvery new deployment, for at least a few weeks of reports
    enforceRefuse delivery to any MX that isn’t listed or fails TLS, and keep the message queued for retryAfter reports show every legitimate sender connects cleanly
    noneTreat the domain as having no policyRetiring MTA-STS cleanly, so cached policies expire instead of blocking mail

    Removing MTA-STS takes the same care as adding it. Publish mode: none with a new id, wait at least the old max_age so every cached enforce policy expires, and only then delete the TXT record and policy host. Deleting everything at once leaves senders holding an enforce policy for servers that may no longer match it.

    How MX Patterns Match

    Each mx: line is either an exact host name or a wildcard that replaces the single left-most label:

    • mx: mx1.example.com matches only mx1.example.com.
    • mx: *.mail.example.net matches a.mail.example.net but not mail.example.net and not b.a.mail.example.net.
    • Patterns like mail.*.example.com or *example.com are invalid. The builder flags them before you publish.

    Every live MX must match a pattern, and every MX server’s certificate must be valid for its own host name. For Google Workspace, Microsoft 365, and other hosted mail, the provider’s MX hosts already carry valid certificates, so your job is listing them correctly. Use the builder’s MX import to pull your current hosts, then decide whether to list them individually or with a wildcard. The UK government’s guidance prefers fully qualified host names over wildcards, because a broad wildcard trusts any server under that name.

    Choosing a max_age

    The max_age value controls how long senders trust their cached copy. RFC 8461 expects it to be in the range of weeks or longer, because a short cache gives an attacker more chances to interfere during refresh.

    • Testing: one day (86400) is common, so mistakes age out quickly. The UK government suggests 86401 seconds.
    • Early enforce: one to two weeks (604800 to 1209600) while you gain confidence.
    • Mature enforce: several weeks to a year. Longer caches resist attack better but make MX changes slower to roll out.

    Gmail and Google publish a one-day max_age on their own enforce policies, which the builder’s live checker flags as shorter than the RFC’s guidance. Large providers can refresh quickly and change MX infrastructure often; most businesses benefit from a longer cache once they’re confident.

    Hosting the Policy File

    The policy host is where most deployments fail. Senders require all of the following:

    • A DNS record (A, AAAA, or CNAME) for mta-sts.yourdomain. The TXT record alone isn’t enough.
    • A valid HTTPS certificate for mta-sts.yourdomain from a public authority. Self-signed, expired, or mismatched certificates all fail.
    • A 200 response at /.well-known/mta-sts.txt with no redirects. A redirect from HTTP to HTTPS on a different host, or to a CDN path, breaks the fetch.
    • The file body only, ideally as text/plain.

    You have several good options, and the builder generates configuration for the first three:

    • Cloudflare Worker: if your DNS is on Cloudflare, a small Worker on a custom domain serves the policy with an automatic certificate and no server to maintain.
    • nginx or Apache: add a virtual host for mta-sts.yourdomain with a certificate such as Let’s Encrypt and serve the file from the well-known path.
    • Static hosting: GitHub Pages, Netlify, and similar hosts work with a custom domain, as long as they publish dot-folders such as .well-known and don’t redirect.
    • Hosted MTA-STS: providers such as URIports host the policy for you behind a CNAME and monitor it, which removes the certificate and uptime burden.

    Here’s a minimal nginx server block, similar to what the builder produces:

    server {
        listen 443 ssl;
        server_name mta-sts.example.com;
    
        ssl_certificate     /etc/letsencrypt/live/mta-sts.example.com/fullchain.pem;
        ssl_certificate_key /etc/letsencrypt/live/mta-sts.example.com/privkey.pem;
    
        location = /.well-known/mta-sts.txt {
            default_type text/plain;
            return 200 "version: STSv1\r\nmode: testing\r\nmx: mx1.example.com\r\nmax_age: 86400\r\n";
        }
    
        location / {
            return 404;
        }
    }

    Research shows why the hosting choice matters: domains that run their own policy servers misconfigure them far more often than domains that use a provider, and the most common failures are the hosting basics.

    Of 68,000 domains with an MTA-STS record, 29.6% were incorrectly configured, and 3.2% of those misconfigured domains should encounter delivery failures from senders that support MTA-STS. Self-managed policy servers were misconfigured 37.8% of the time, compared with 4.9% for third-party managed servers.

    Md. Ishtiaq Ashiq, Tobias Fiebig, and Taejoong Chung, Unraveling the Complexities of MTA-STS Deployment and Management in Securing Email, ACM Internet Measurement Conference, 2025

    Among invalid MTA-STS configurations in the top 1 million domains in January 2026, the most common problems were missing A or AAAA records for the policy host (34%), HTTPS certificate problems (25%), TLS or certificate validation failures (6%), expired certificates (6%), and MX hosts missing from the policy (5%).

    Freddie Leeman, URIports, MTA-STS Adoption: Three Years of Steady Growth, January 6, 2026

    Deploying MTA-STS From Testing to Enforce

    1. Inventory your mail servers. List every MX host for the domain and confirm each one supports STARTTLS with a valid public certificate for its own name. Hosted providers handle this; self-hosted and gateway servers need checking.
    2. Turn on reporting first. Publish a TLS-RPT record so senders tell you about failures. The TLS-RPT Builder creates it in a minute.
    3. Host the policy in testing mode. Build the file above with mode: testing and a one-day max_age, host it, and confirm the URL returns the file over HTTPS with no redirects.
    4. Publish the TXT record. Add _mta-sts with a fresh id. Publish the policy file before the TXT record, because senders only go looking for the file once they see the record.
    5. Read at least two weeks of reports. Look for certificate errors, unlisted MX hosts, and policy fetch errors. Fix every legitimate failure.
    6. Switch to enforce. Change the mode, raise max_age to at least a week, and update the id in DNS so senders pick up the change.
    7. Keep watching. Expiring certificates on the policy host or an MX are the most common way an enforced domain starts losing mail.

    When you change mail providers or add an MX later, update the policy in this order: add the new host to the policy, publish it with a new id, wait for the old max_age to pass, then change your MX records. Removing a host works the same way in reverse.

    How MTA-STS and TLS-RPT Work Together

    MTA-STS tells senders what to require. TLS-RPT tells you what happened when they tried. With a TLS-RPT record at _smtp._tls, senders such as Google and Microsoft email or post a daily JSON report summarizing successful and failed TLS sessions to your servers, including the reason for each failure, such as an expired certificate, a host missing from your policy, or a policy file they couldn’t fetch.

    Without reports, testing mode is blind: failures are logged on the sender’s side and you never see them. With reports, you have the evidence to move to enforce safely and an early warning when something breaks later. The TLS-RPT Builder explains the report format and builds the record.

    MTA-STS vs. DANE

    DANE for SMTP, defined in RFC 7672, solves the same problem with a different trust model. Instead of an HTTPS-hosted policy and public certificate authorities, DANE publishes TLSA records that pin each MX server’s certificate or key, signed with DNSSEC.

    MTA-STSDANE
    Where the policy livesTXT record plus a policy file on an HTTPS hostTLSA records on each MX host
    Requires DNSSECNoYes, for your domain and your MX hosts
    Certificate trustPublic certificate authoritiesThe certificate or key you pin in DNS; self-signed can work
    Testing modeYes, per domainNo; partial rollout means publishing TLSA for only some MX hosts
    Protection startsAfter a sender’s first successful policy fetchImmediately, because DNSSEC can prove a record exists or doesn’t
    Sender supportGmail and Microsoft Exchange Online, among othersMail software such as Postfix, and providers that validate DNSSEC
    Failure reportingTLS-RPTTLS-RPT

    You don’t have to choose. RFC 8461 says senders that implement both must not let an MTA-STS pass override a failing DANE check, and NIST recommends DANE, MTA-STS, or both. If your DNS provider and mail host support DNSSEC and DANE, publishing both covers senders that support either. If DNSSEC isn’t practical, MTA-STS is the one you can deploy today with nothing more than a TXT record and a small web host.

    Common MTA-STS Mistakes

    • No DNS record for the policy host. The TXT record exists, but mta-sts.yourdomain doesn’t resolve, so no sender can fetch the policy.
    • A bad certificate on the policy host. Expired, self-signed, or issued for a different name. The builder’s live check tests this exactly as a sender would.
    • Redirects. A web server or CDN that redirects the well-known path, even to HTTPS on the same host, makes the policy unreadable.
    • Unlisted MX hosts. Adding a backup MX or a security gateway without updating the policy blocks mail to it under enforce.
    • Forgetting to change the id. Edit the policy without updating the TXT id and senders keep using the old version until it expires.
    • Invalid wildcards. A wildcard only replaces the left-most label, and it never matches the bare parent name.
    • Jumping straight to enforce. Without a testing period and TLS reports, the first sign of a problem is lost mail.
    • Expecting parent-domain coverage. Subdomains that receive mail need their own record and policy.
    • Pulling the policy abruptly. Deleting an enforce policy instead of moving to none first leaves senders holding cached rules.

    Key Takeaways

    • STARTTLS is opportunistic, so an attacker can strip it or spoof your MX and most senders will deliver in cleartext or to the wrong server.
    • MTA-STS tells supporting senders, including Gmail and Exchange Online, to require TLS with a valid certificate for your listed MX hosts.
    • You publish two things: a _mta-sts TXT record with an id and a policy file at https://mta-sts.yourdomain/.well-known/mta-sts.txt.
    • Start in testing with TLS-RPT reports, fix every failure, then move to enforce and lengthen max_age.
    • Most broken deployments fail on hosting basics: no DNS for the policy host, bad certificates, redirects, or MX hosts missing from the policy.

    Frequently Asked Questions

    Is MTA-STS Required by Gmail or Microsoft?

    No. Gmail and Microsoft Exchange Online honor MTA-STS policies when they send to your domain, and Gmail requires senders to use TLS, but neither requires your domain to publish an MTA-STS policy. Publishing one is how you make encrypted delivery to your domain mandatory.

    Does MTA-STS Improve Email Deliverability?

    Not for the mail you send. MTA-STS protects mail sent to your domain. It can make inbound delivery stricter, which is why you start in testing mode and read TLS reports before you enforce.

    Do I Need My Own Web Server to Host the Policy?

    No. A Cloudflare Worker, a static host that supports a custom domain and the .well-known folder, or a hosted MTA-STS provider all work. The host needs a valid HTTPS certificate for the mta-sts subdomain and must return the file without redirects.

    What Happens to Mail if My Policy Host Goes Down?

    Senders that already cached your policy keep using it until max_age expires, so a short outage doesn’t change delivery. If senders can’t fetch a new policy and the cached one expires, they treat the domain as having no policy and fall back to opportunistic TLS rather than rejecting mail.

    How Often Should I Change the id?

    Every time you edit the policy file. The id doesn’t need to follow a format beyond 1 to 32 letters and numbers, so a timestamp makes changes easy to track.

    Can I Use MTA-STS With Google Workspace or Microsoft 365?

    Yes. Both providers present valid certificates on their MX hosts. You list their MX host names in your policy, host the policy file yourself or through a provider, and publish the TXT record in your DNS.

    Does MTA-STS Protect Subdomains?

    Only the exact domain the policy is published for. Mail to a subdomain uses that subdomain’s own record and policy host, and senders never fall back to the parent domain.

    Should I Use MTA-STS or DANE?

    Use MTA-STS if DNSSEC isn’t available for your domain and MX hosts, since it works with public certificates and a simple web host. Use DANE if you already run DNSSEC. Many domains publish both so senders that support either one are covered.

    Related Email Authentication Guides

    Check your domain with the builder first. If nothing is published, set up TLS reporting, host a testing policy, and give the reports a couple of weeks. You’ll know exactly which servers are ready before you ask the world’s largest senders to enforce it.

    Related Articles