Why Self-Host MTA-STS and SMTP DANE?
SMTP email delivery has a fundamental vulnerability: the initial connection between mail servers typically negotiates TLS opportunistically. An attacker performing a man-in-the-middle (MITM) attack can strip the TLS upgrade during the SMTP handshake (a “STARTTLS downgrade attack”) and intercept email in plaintext. This has been demonstrated against major providers and is a well-documented risk.
MTA-STS (Mail Transfer Agent Strict Transport Security) and SMTP DANE (DNS-based Authentication of Named Entities) solve this problem by allowing domain owners to publish policies that mandate encrypted email delivery. When both sender and receiver implement these protocols, email traffic between your servers and theirs is guaranteed to be encrypted — and if encryption fails, the message is rejected rather than delivered insecurely.
For anyone running a self-hosted mail server with Postfix, Stalwart, Haraka, or any other MTA, implementing MTA-STS and DANE is one of the highest-impact security improvements you can make. If you’re setting up a mail server from scratch, check out our complete email server guide with Postfix, Dovecot, and Rspamd first, then return here to add MTA-STS and DANE hardening. It ensures your outbound mail is always encrypted in transit and that inbound mail from other MTA-STS/DANE-supporting servers reaches you over verified TLS connections.
MTA-STS vs SMTP DANE: How They Compare
MTA-STS and DANE achieve similar goals through different mechanisms. Understanding the distinction is key to choosing the right approach for your infrastructure.
| Feature | MTA-STS | SMTP DANE |
|---|---|---|
| Mechanism | HTTPS policy file + DNS TXT record | DNS TLSA record |
| Requires | Valid TLS certificate on mta-sts.yourdomain.com | DNSSEC-signed zone |
| Policy Location | https://mta-sts.yourdomain.com/.well-known/mta-sts.txt | TLSA record in DNS zone |
| Trust Model | TLS certificate authority (CA) | DNSSEC chain of trust |
| Deployment Complexity | Low to moderate | Moderate (requires DNSSEC) |
| Policy Flexibility | Enforce, Testing, None modes | Certificate matching (SPKI, cert) |
| Adoption | Growing (Gmail, Yahoo, Microsoft support) | Established (Postfix, Exim support) |
| Fallback | DNS TXT record indicates policy exists | DNSSEC validation required |
| Best For | Domains with TLS certificates and web hosting | Domains with DNSSEC-enabled DNS |
MTA-STS Explained
MTA-STS works by publishing two pieces of information:
- A DNS TXT record at
_mta-sts.yourdomain.comindicating that a policy exists - An HTTPS-hosted policy file at
https://mta-sts.yourdomain.com/.well-known/mta-sts.txtspecifying which MX hosts require TLS and what the minimum TLS version is
When a sending MTA looks up your domain, it checks for the MTA-STS DNS record. If found, it fetches the policy file over HTTPS and enforces TLS requirements for delivery.
SMTP DANE Explained
DANE takes a different approach. It uses DNS TLSA records to publish the expected TLS certificate (or public key) for your mail server. The sending MTA validates:
- DNSSEC-signed DNS response for the TLSA record
- TLS certificate presented by the receiving server matches the TLSA record
- If validation fails, delivery is rejected
DANE does not require a separate HTTPS endpoint — everything is published directly in DNS. However, it requires your DNS zone to be DNSSEC-signed, which adds operational complexity.
Deploying MTA-STS: Step-by-Step
Step 1: Create the MTA-STS DNS TXT Record
Add the following TXT record to your DNS zone:
| |
The id field is a policy version identifier. Increment it (e.g., 2026042802) whenever you update the policy file. Use a timestamp or sequential number.
Step 2: Set Up the MTA-STS Subdomain
You need a subdomain mta-sts.yourdomain.com that serves the policy file over HTTPS. This requires:
- A DNS A/AAAA record for
mta-sts.example.com - A valid TLS certificate covering
mta-sts.example.com(a wildcard cert for*.example.comworks)
For automated TLS certificate provisioning, see our cert-manager vs Lego vs ACME.sh guide to set up Let’s Encrypt certificates.
Create the DNS record:
| |
Step 3: Create the MTA-STS Policy File
The policy file must be served at https://mta-sts.yourdomain.com/.well-known/mta-sts.txt:
| |
Policy fields explained:
version: AlwaysSTSv1mode:enforce— reject delivery if TLS requirements cannot be met (use this in production)testing— log failures but do not reject (use during deployment)none— disable policy (for emergency rollback)
mx: Each MX hostname that requires TLS enforcementmax_age: Cache duration in seconds (recommended: 86400 = 24 hours, max: 604800 = 7 days)
Step 4: Serve the Policy File via Nginx
Here’s a minimal Nginx configuration to serve the MTA-STS policy file:
| |
Create the directory and policy file:
| |
Step 5: Serve via Caddy (Simpler Alternative)
Caddy handles TLS automatically and provides a simpler configuration:
| |
With a Docker Compose deployment:
| |
Step 6: Validate Your MTA-STS Deployment
Use the MTA-STS Validator or test with curl:
| |
Step 7: Configure Your MTA for MTA-STS
Postfix MTA-STS Configuration
Postfix 3.4+ supports MTA-STS via the smtp_tls_security_level setting. For Postfix 3.6+:
| |
Stalwart Mail Server
Stalwart has built-in MTA-STS support. For a comparison of Stalwart with other SMTP relay options, see our Postal vs Stalwart vs Haraka guide. Enable MTA-STS in the configuration:
| |
Deploy via Docker Compose:
| |
Deploying SMTP DANE: Step-by-Step
Step 1: Enable DNSSEC on Your Zone
DANE requires DNSSEC. If your DNS provider doesn’t support DNSSEC, consider switching to one that does (Cloudflare, Amazon Route 53, or self-hosted PowerDNS).
For PowerDNS with DNSSEC:
| |
Step 2: Obtain Your Mail Server TLS Certificate Hash
Generate the SHA256 hash of your mail server’s TLS public key:
| |
This produces a base64-encoded SHA256 hash, for example: dQw4W9XgX9Kj7LmN3OpQ5RsT8UvW2XyZ4AbC6DeFgHi=
Step 3: Create the TLSA DNS Record
Add a TLSA record to your DNS zone for your MX hostname:
| |
TLSA record format: usage selector matching-type certificate-association-data
usage(3): DANE-EE (Domain Issued Certificate) — validates the exact certificateselector(0): Full certificate (use1for SubjectPublicKeyInfo only)matching-type(1): SHA256 hash (use0for exact match,2for SHA512)certificate-association-data: The base64-encoded hash from step 2
Step 4: Verify DANE Records
| |
Step 5: Configure Postfix for DANE
| |
Step 6: Deploy DNSSEC with Docker
For self-hosted DNSSEC management with PowerDNS:
| |
MTA-STS vs DANE: Which Should You Deploy?
In an ideal world, you would deploy both. They complement each other and provide defense in depth. However, here’s how to decide:
Choose MTA-STS if:
- You already have TLS certificates for your mail server
- You don’t have DNSSEC on your DNS zone
- You want a simpler deployment path
- Your audience includes Gmail, Yahoo, and Microsoft 365 users
Choose DANE if:
- Your DNS zone is already DNSSEC-signed
- You want certificate validation without a CA dependency
- You need fine-grained control over which certificates are accepted
- You prefer a purely DNS-based solution
Deploy Both for Maximum Protection
The two protocols are not mutually exclusive. MTA-STS provides a policy-based approach that works without DNSSEC, while DANE provides cryptographic certificate validation via DNSSEC. When both are deployed:
- Receivers that support MTA-STS will enforce TLS based on your published policy
- Receivers that support DANE will validate your certificate against DNS records
- If one validation mechanism fails, the other may still succeed
Monitoring and TLS Reporting
Both MTA-STS and DANE support TLS reporting (RFC 8460), which sends aggregate reports about TLS connection failures to a designated email address.
Set Up TLS-RPT DNS Record
| |
Process TLS Reports
TLS reports are JSON-formatted aggregate reports sent daily. You can process them with:
| |
For self-hosted report processing, consider deploying a simple Python service that receives and stores reports:
| |
Troubleshooting Common Issues
MTA-STS Policy Not Found
| |
DANE TLSA Record Validation Fails
| |
Policy Not Being Cached
| |
FAQ
What is MTA-STS and why do I need it?
MTA-STS (Mail Transfer Agent Strict Transport Security) is a protocol that lets domain owners publish a policy requiring email servers to use TLS encryption when sending mail to their domain. Without MTA-STS, SMTP connections default to opportunistic TLS, meaning an attacker can perform a STARTTLS downgrade attack and intercept email in plaintext. MTA-STS prevents this by mandating TLS and rejecting delivery if encryption cannot be established.
Do I need DNSSEC for MTA-STS?
No. MTA-STS does not require DNSSEC. It uses a DNS TXT record to indicate that a policy exists, but the policy itself is fetched over HTTPS using standard TLS certificate validation. This makes MTA-STS simpler to deploy than DANE, which does require DNSSEC.
What’s the difference between MTA-STS and DANE?
MTA-STS uses an HTTPS-hosted policy file to specify TLS requirements, while DANE uses DNS TLSA records to validate the exact certificate or public key of the receiving server. MTA-STS requires a valid TLS certificate on a subdomain; DANE requires DNSSEC. Both prevent STARTTLS downgrade attacks but use different trust models.
Can I use both MTA-STS and DANE together?
Yes, and it’s recommended. They provide complementary protection: MTA-STS enforces TLS policy via HTTPS, while DANE validates certificates via DNSSEC. Deploying both gives you defense in depth — if one mechanism has an issue, the other may still protect your email delivery.
How do I test if my MTA-STS deployment is working?
Use online validators like Hardenize (hardenize.com) or MTA-STS.info to check your deployment. You can also test manually by verifying the DNS TXT record exists (dig TXT _mta-sts.yourdomain.com) and the policy file is accessible over HTTPS (curl https://mta-sts.yourdomain.com/.well-known/mta-sts.txt). Major email providers like Gmail and Yahoo will automatically begin enforcing your policy once deployed.
How often should I update my MTA-STS policy?
Update your MTA-STS policy whenever you change MX records, add or remove mail servers, or change TLS certificate configurations. Always increment the id field in the DNS TXT record when you update the policy file — this signals to sending servers that they should re-fetch the policy. Start in testing mode and switch to enforce after confirming no legitimate mail is being rejected.
What happens if a sending server doesn’t support MTA-STS or DANE?
Nothing changes for non-supporting servers. They will deliver email using opportunistic TLS (or plaintext if TLS is unavailable), exactly as they do today. MTA-STS and DANE are strictly additive — they only affect servers that implement these protocols. As adoption grows, an increasing percentage of your inbound email will be verified as encrypted.
Is MTA-STS supported by major email providers?
Yes. Gmail has supported MTA-STS since 2019. Yahoo, Microsoft 365, and many other providers also support it. As of 2026, the majority of email traffic between major providers already uses MTA-STS enforcement. DANE is widely supported by Postfix and Exim installations, though adoption among large consumer providers is more limited.