Why does adding a second v=spf1 TXT record at the same domain break SPF for all of its mail, and how do you fix it?
answer
- one name, one policy
- the receiver refuses to choose
- other TXT strings are harmless
- merge, then recheck budget and size
basics
~20 sRFC 7208 allows one record beginning v=spf1 per name; when a receiver selects two, the check returns permerror for every message from that domain. The fix is to merge both into one record with a single all at the end.
solid answer
~40 sA receiver fetches the domain's `TXT` records, discards every string that does not begin with exactly `v=spf1`, and if more than one record remains, `check_host()` returns `permerror` (RFC 7208 section 4.5); section 3.2 says a name MUST NOT publish records that select more than one. It does not pick the first or newest, so when someone adds a vendor's suggested record through the DNS control panel, the existing servers lose their `pass` too. Verification tokens and other TXT text are harmless because they never start with `v=spf1`. The fix is to merge: one `v=spf1`, the union of the mechanisms, one `all` with a deliberately chosen qualifier, then recheck the merged record against the 10-lookup limit and the size guidance, and put the name under change control.
code
dns · 5 lines; two SPF records at one name -> permerror for every message
example.com. 3600 IN TXT "v=spf1 ip4:192.0.2.0/24 mx -all"
example.com. 3600 IN TXT "v=spf1 include:spf.example.net ~all"
; ignored by SPF selection: does not begin with v=spf1
example.com. 3600 IN TXT "site-verification=4f1c9e..."go deeper
Remember the rule: one record beginning v=spf1 per name, and two of them make SPF return permerror for every message.
Walk through selection: TXT lookup, discard strings not starting v=spf1, permerror if more than one remains, and why verification tokens never count.
Show the repair: merge into one record, choose the qualifier on all on purpose, recheck lookups and size, publish in one change, and verify against cached answers.
Treat this as a governance failure: decide who owns the domain's SPF record, how outside services are onboarded, and which check blocks a second record before it ships.
## The rule: one SPF record per name RFC 7208 (April 2014) states the rule twice. Section 3.2 is addressed to publishers: a domain name **MUST NOT** have multiple records that would cause an authorization check to select more than one record. Section 4.5 tells receivers what happens when a publisher breaks it: after discarding every `TXT` string that does not begin with exactly `v=spf1`, **if more than one record remains, `check_host()` produces `permerror`**. Three consequences follow, and each is a common interview probe: - **The error covers the whole name.** Every message whose `MAIL FROM` domain is that name gets `permerror`, including mail from servers that both records authorise. - **The receiver does not choose.** It does not take the first record, the newest, or the most permissive. A publisher does not control the order of records in a DNS answer anyway. - **Other `TXT` strings are harmless to selection.** A domain-verification token, or any text that does not start with `v=spf1`, is discarded before counting. "One SPF record per name" is not "one TXT record per name". | What is published at example.com | SPF records selected | Outcome of selection | |---|---|---| | Two TXT records, each beginning `v=spf1` | 2 | `permerror` | | One TXT record of two strings, the first beginning `v=spf1` | 1 | evaluated normally | | One `v=spf1` record plus a verification token | 1 | evaluated normally | | No string beginning `v=spf1` | 0 | `none` | ## How the second record appears The usual story: example.com has published `v=spf1 ip4:192.0.2.0/24 mx -all` for years. A marketing team signs up for an outside sending service whose onboarding page says "add this SPF record", and someone adds it as a new `TXT` record through the DNS hosting control panel. DNS itself allows several TXT records at one name, so the panel accepts it without complaint and nothing visibly breaks at the moment of the change. Within one TTL, receivers start recording `spf=permerror` for the domain, and mail from the company's own servers, which passed yesterday, no longer does. A lookup of the name's TXT records shows the cause at once: two strings that each begin `v=spf1`. ## What a receiver does with permerror RFC 7208 section 2.6.7 says `permerror` means the published records "could not be correctly interpreted" and that the condition "definitely requires DNS operator intervention". What a receiver does next is local policy, covered with SPF results. A receiver that rejects during the SMTP transaction SHOULD use reply code `550` with enhanced status code `5.5.2` (section 8.7); RFC 7372 (September 2014) later registered `X.7.24`, "SPF validation error", for use in place of `5.5.2`. Other receivers accept the message and annotate the failure. Either way the domain has lost what SPF gave it, for every one of its senders, until the record is fixed. ## The fix: merge, never add 1. **Inventory** every sender both records describe: the existing servers and the new service. 2. **Build one record**: one `v=spf1` at the start, the union of the mechanisms in the middle, one `all` at the end. When the two records disagree on the qualifier on `all` (one ends `-all`, the vendor's suggestion `~all`), the merged record can carry only one. Decide it on purpose rather than inheriting whichever was pasted last. 3. **Recheck the merged record.** Each added `include` spends lookups under SPF's 10-lookup limit, and a long record has to respect the 512-octet and 450-octet size guidance. 4. **Publish in one change**: replace the original record's value with the merged value and delete the second record together, so no window holds two records or none. 5. **Verify** by querying the name's TXT records and counting the strings that begin `v=spf1`. Expect old answers to linger in resolvers' caches until the TTL runs out. ```dns ; before: two SPF records at one name example.com. 3600 IN TXT "v=spf1 ip4:192.0.2.0/24 mx -all" example.com. 3600 IN TXT "v=spf1 include:spf.example.net ~all" ; after: one record, one all example.com. 3600 IN TXT "v=spf1 ip4:192.0.2.0/24 mx include:spf.example.net -all" ``` ## Keeping it from happening again - **Change control on the name.** Treat the apex TXT records as owned by whoever runs mail, not as a panel anyone with DNS access edits. - **A pre-publish check** that counts strings beginning `v=spf1` at every name and refuses a second one. - **An envelope subdomain per outside sender**, where the service supports it, so its policy lives at its own name instead of being merged into the apex record.
- Does a verification token at the same name cause the same problem?No. Selection discards every TXT string that does not begin with exactly `v=spf1`, so a token never counts as an SPF record. It does share the TXT answer, though, so a crowd of tokens can push the answer past RFC 7208's 512-octet and 450-octet size guidance.
- Two records exist, but both are identical copies. Is that still permerror?Yes. RFC 7208 counts selected records, not distinct policies: more than one record beginning `v=spf1` gives `permerror` regardless of their content. Delete the duplicate.
- How would you notice this before receivers did?Check the name after every DNS change: query its TXT records and count the strings that begin `v=spf1`. In operation, a sudden run of `spf=permerror` in the results receivers record for the domain is the signal, and a pre-publish check that refuses a second SPF record stops it at the source.
Like a door supervisor handed two different guest lists for the same event: rather than guess which one is current, they check nobody against either list and call the organiser. No guest can be confirmed until only one list remains.
- The receiver uses the first or the newest SPF record it finds.
- Two SPF records are merged automatically by the receiver.
- A domain may hold only one TXT record, so verification tokens break SPF.
- Two SPF records give temperror, so the mail is simply retried later.
- Identical duplicate SPF records are harmless because they say the same thing.