Your primary mail relay went down at 02:14 on a Tuesday. The DNS shows two MX records pointing at two different hosts. You assume mail kept flowing through the secondary. You wake up to a queue of 14,000 deferred messages on the secondary, none delivered to mailboxes, and a customer support ticket about a missing password reset from a finance director who has been trying since dawn. The two-MX topology was never wrong — it was misunderstood. A secondary MX is not a hot standby. It is a parking lot.
What’s happening
The MX record set is not a load balancer. It is a list of hosts that originating sending MTAs should try in priority order. When a sender’s MTA hits your primary and gets a connection refused or 4xx temporary failure, it walks down the list and tries the next preference value. The receiving secondary accepts the message and writes it to its own queue. What happens next is the part operators forget: the secondary must itself forward to the primary once the primary comes back. If the secondary is not configured as a relay for your domain — if it accepts the mail but has no transport route to ship it onward — it sits in queue until the secondary’s maximal_queue_lifetime expires (Postfix default: 5 days), at which point it bounces back to the sender.
Two failure modes show up constantly in inherited environments:
- Same-priority MX across hosts. People write
10 mx1.example.com.and10 mx2.example.com.thinking it gives round-robin redundancy. It gives you round-robin until either host falls over, at which point half your sending peers still try the dead one first because their resolver pinned an order. With same priority, a senders’ MTA shuffles randomly, so you cannot reason about delivery ordering during a partial outage. Use distinct priorities (10and20) unless you genuinely run anycast or a load balancer in front of both. - Secondary that doesn’t relay. The secondary listens on port 25, accepts mail with a 250 OK because it has the domain in
mydestinationorrelay_domains, then has norelay_transportfor the domain pointing back at the primary. Mail piles up. Senders see successful delivery to your secondary and never retry the primary, because they got a 250.
The correct topology: two hosts, two different priority values, both with relay_domains listing your accepted domains, both with transport_maps that route those domains back to your internal primary (not the public MX hostname). The internal hop avoids loops and lets you take the public primary out of rotation while the secondary still relays. Some shops add a third MX at priority 30 on a different network/region just for the case where both primary hosts are unreachable for reasons outside the data center.
How to verify
Inspect the published record set and what’s actually happening at the MTA level:
# 1. What does DNS say?
dig +short MX example.com
# Should show two distinct priorities, e.g.:
# 10 mx1.example.com.
# 20 mx2.example.com.
# 2. Can the secondary actually relay back to the primary?
postconf -n | grep -E 'relay_domains|transport_maps'
postmap -q "example.com" /etc/postfix/transport
# Should output something like:
# smtp:[mx1-internal.example.com]:25
# 3. Is mail sitting in queue?
mailq | tail
postqueue -p | head -50
# 4. Test the failover by hand from an external host
swaks --to test@example.com --server mx2.example.com -tls
# Then watch mx2's maillog for delivery to mx1
tail -f /var/log/maillog | grep "relay=mx1"
If mailq on the secondary shows messages older than the primary’s last outage window, you have a transport gap. If transport_maps returns nothing for your domain on the secondary, the secondary is accepting mail it can’t deliver — fix this before the next failover.
The fix
Three changes, in order:
- Set distinct MX priorities. Lower number wins.
10 mx1is primary,20 mx2is secondary. Do not run both at priority 10 unless mx1 and mx2 sit behind the same anycast IP or load balancer. - Configure the secondary as a real relay. In
/etc/postfix/main.cf:
Andrelay_domains = example.com, anotherdomain.example transport_maps = hash:/etc/postfix/transport smtpd_relay_restrictions = permit_mynetworks, reject_unauth_destination/etc/postfix/transport:
Thenexample.com smtp:[mx1-internal.example.com]:25postmap /etc/postfix/transport && systemctl reload postfix. The brackets disable MX lookup so the secondary doesn’t loop back to itself through public DNS. - Set sane queue lifetimes. On the secondary specifically,
maximal_queue_lifetime = 1dandbounce_queue_lifetime = 1d. A secondary holding mail for five days while you scramble to restore the primary is not helping anyone — earlier visibility on bounces lets senders retry from their side or escalate. On the primary keep the default 5 days.
A separate, less obvious choice: do you want the secondary to perform recipient validation? If the secondary’s relay_recipient_maps is empty, it accepts mail for any address in relay_domains, including ones that don’t exist. The primary then bounces them later — backscatter. Either keep relay_recipient_maps populated and synced with the primary, or use reject_unverified_recipient to probe the primary at SMTP time. Both add complexity; the simpler path is a maintained relay_recipient_maps hash file pushed from the primary nightly.
If your secondary MX is on the same hypervisor cluster, the same upstream switch, or the same cloud region as the primary, the “redundancy” is theatre. Different region, different provider, different ASN is the minimum bar for an MX that survives the failure modes you’re actually worried about.
For mail topologies designed and operated with this discipline — failover that works the first time, not the second — see Cloud Compute under environment management, or tell us about your sending setup.