Skip to content
DocumentationAPI reference Build something worth sending.

Guides

SPF record syntax and format

The SPF record format, term by term: v=spf1, include, ip4, ip6, a, mx, the four qualifiers and all, with example records and the mistakes that break one.

An SPF record is a TXT record that lists the servers allowed to send mail for a domain. Receivers read it left to right and stop at the first term that matches the sending IP. This page covers the format, each term, and the mistakes that make a record fail. The rules are in RFC 7208.

The format

v=spf1 [mechanisms] [modifiers] all

A record starts with exactly v=spf1, then terms separated by single spaces. A typical record:

v=spf1 ip4:192.0.2.10 include:_spf.google.com ~all

That reads: pass mail from 192.0.2.10, pass mail from any server Google lists, and soft fail everything else.

Mechanisms

  • ip4:192.0.2.10 or ip4:192.0.2.0/24 matches one IPv4 address or a range. No DNS lookup.
  • ip6:2001:db8::/32 does the same for IPv6. No DNS lookup.
  • include:_spf.example.com checks another domain's SPF record and matches if that record passes. This is how you authorize a provider. One lookup, plus the lookups inside that record.
  • a matches the domain's own A or AAAA address. a:host.example.com uses another name. One lookup.
  • mx matches the servers in the domain's MX records. One lookup toward the limit, and each MX host needs an address lookup of its own.
  • exists: matches if a name resolves. It is mostly used with macros. One lookup.
  • ptr matches on reverse DNS. The RFC says not to use it: it is slow and receivers may skip it.
  • all matches everything. It goes last.

Qualifiers

A qualifier in front of a mechanism sets the result when it matches. With no qualifier the result is pass.

  • + pass, the default. +all lets anyone send as you, so never use it.
  • - fail. -all says nothing else may send.
  • ~ softfail. ~all says other senders are probably not you. Most domains start here.
  • ? neutral. ?all makes no claim either way.

Modifiers

redirect=_spf.example.com hands the whole check to another domain's record, and is used when several domains share one policy. It only applies when the record has no all. exp= names a TXT record with an explanation for rejected mail. Few receivers show it.

Example records

Only your own server sends:

v=spf1 ip4:203.0.113.5 -all

Google Workspace and one other provider:

v=spf1 include:_spf.google.com include:spf.example-provider.com ~all

A domain that never sends mail:

v=spf1 -all

Limits

  • One SPF record per DNS name. A second v=spf1 record is a permerror: see multiple SPF records.
  • At most 10 lookups from include, a, mx, ptr, exists and redirect in one check. See SPF too many DNS lookups.
  • At most two lookups that return nothing. A typo in an include host is the usual cause.
  • One TXT string holds 255 characters. A longer record is split into several quoted strings, which receivers join with no space between them. Put the space inside a string, not at the join.

Mistakes that break a record

  • A version other than v=spf1, such as v=spf2 or spf1, or a space around the equals sign.
  • A colon left out or doubled, as in include_spf.google.com or ip4::192.0.2.1.
  • Terms after all. Receivers stop at all, so anything after it never counts.
  • An IP address written into an include, as in include:192.0.2.1. Use ip4:.
  • Curly quotes pasted from a document into the DNS value.

Paste a record into the draft test on the SPF checker to check the syntax and lookup count before you publish it.

Next steps

↑↓ to navigate↵ to openesc to close