What an SPF Record Is and How to Read Yours

An SPF record is one DNS TXT record that lists which servers may send mail for your domain. Here is what one looks like, how to find it, and the rules it must follow.

An SPF record is a short text entry in DNS that lists the mail servers allowed to send for your domain. It is one record, and it answers one question: is this server allowed to send as us? Mailbox providers check it before they decide what to do with your mail. Gmail's guidelines say SPF prevents spammers from sending unauthorized messages that appear to be from your domain. Here is what the record is, what it looks like, and how to find one for any domain.

What an SPF record is

The SPF record is one string of text in the RDATA of a single DNS TXT resource record. In plain terms, it lives in DNS as a TXT record, published at the domain it speaks for. The record for example.com sits at example.com itself, not in a subdomain under it. Each SPF record is placed in the DNS tree at the owner name it belongs to.

A domain name must not have multiple records that would make an authorization check select more than one record. Each domain gets exactly one SPF record. With two in place, a receiver has no way to pick the right one.

Example SPF records

A simple record looks like this:

v=spf1 ip4:203.0.113.10 -all

Read it left to right. The v=spf1 part names the version and must come first. The ip4: mechanism authorizes one IPv4 address. The -all at the end says everything else fails.

A record that also covers a mail provider looks like this:

v=spf1 ip4:203.0.113.10 include:_spf.mailprovider.com -all

The include: mechanism pulls in another domain's record and lets its senders pass too. Gmail's guidelines say every sender that sends mail for your domain belongs in its SPF record. Mail sent through outside services that your SPF record leaves out has a higher chance of landing in the spam folder.

The qualifier before a mechanism matters. + means pass, - means fail, ~ means soft fail, and ? means no opinion. A record ending in ~all gives a softfail, which SPF's standard calls a weak statement that the host is probably not authorized. SPF's standard says domains that want receivers to make negative determinations must publish records ending in "-all".

How to find the SPF record for a domain

Any DNS lookup tool will do it. Query the domain for TXT records and find the entry beginning with v=spf1. Command-line tools work too. A TXT query against the domain returns every text record published there, and only one of them should start with v=spf1.

An SPF surveyor or lookup tool goes one step further. It follows the include: mechanisms and counts the DNS lookups your record forces, then tells you whether the record fits the limits. Use one before you publish changes.

If a lookup returns no v=spf1 string, the domain has no SPF record. That means receivers get no list of approved senders, so nothing vouches for the mail. Gmail's guidelines say messages that are not authenticated might be marked as spam or rejected with a 5.7.26 error. A missing record is worth fixing, not just watching.

SPF record syntax and rules

The SPF specification sets a few hard rules.

SPF records must be published as a DNS TXT resource record only. Use of other DNS resource record types was supported in SPF's experimental phase but has been discontinued. If an old checklist tells you to publish an SPF-type record, skip that line.

The character content of the SPF record is encoded as US-ASCII. No special characters, no accents.

If a published record holds multiple character strings, the record must be treated as if those strings are joined together with no spaces added. DNS tools sometimes split long records into strings. That is fine, as long as the join puts nothing between them.

Since TXT records have many uses, other TXT records published there for other purposes might cause problems with size limits. Keep the SPF record lean. The SPF spec asks record publishers to make a record need as little DNS data as possible to evaluate. Each include: costs extra lookups, and going over the limit breaks the record by itself.

The spec advises against publishing SPF under a wildcard, and anyone who does should be careful with it.

SPF and MX

The mx mechanism in an SPF record authorizes the mail servers listed in that domain's MX records. A record like v=spf1 mx -all says: if a server is one of our MX hosts, it may send our mail.

This is not the same thing as the MX record itself. The MX record says where incoming mail for the domain should be delivered. The mx mechanism borrows that list for outgoing mail. SPF's standard says it is better to use less resource-intensive mechanisms like ip4 and ip6 over a, or a over mx.

Where SPF sits next to DKIM and DMARC

SPF is one of the two underlying authentication mechanisms that DMARC builds on. The other is DKIM. DMARC's standard says SPF and DKIM provide domain-level authentication but are not directly associated with the Author Domain. For the SPF side, DMARC's standard says DMARC relies solely on SPF validation of the MAIL FROM identity.

A message needs alignment between the Author Domain and an Authenticated Identifier to achieve a DMARC pass. Relaxed alignment means the two share the same Organizational Domain. Strict alignment means the Author Domain is identical to the Authenticated Identifier. A message passes the DMARC check if one or more Authenticated Identifiers align with the Author Domain. It fails if none exist or none align.

Gmail's FAQ says bulk senders must set up both SPF and DKIM, but only one needs to be aligned. So publishing SPF alone is not the end of the story. Google Workspace Help says you must turn on SPF or DKIM for your domain before you can use DMARC. Set up both, then publish the DMARC policy.

Common mistakes

The mistakes that break SPF records repeat themselves.

Two v=spf1 records at one domain. The spec forbids it, and SPF's standard says check_host returns permerror when more than one record remains. Merge them into a single record.

Forgetting a sender. Any tool, CRM, or billing system that sends as your domain needs to be in the record, or its mail will look unauthorized.

Too many includes. Each one costs DNS lookups. Trim the list to senders you still use.

A wildcard TXT record that answers for subdomains. The spec discourages wildcards for publishing SPF.

A record that never gets checked. Run a surveyor after every change, and read the bounce text when mail fails. Gmail's FAQ says error code 5.7.27 means the message was blocked because it didn't pass SPF authentication. That bounce is telling you the record and the real sending servers disagree. Fix the record, and the mail and the DNS agree again.

Sources

Filed

More filed under SPF and DKIM

  • How to find all DNS records for a domain
  • How to Set Up a DKIM Record for Your Domain
  • How to Set Up a DKIM Email Record
  • What a DKIM record is and what each part does
  • Why Your Email Failed SPF and What to Do
  • Can a Domain Have Multiple SPF Records?
  • What It Means When a Domain Has No SPF Record
  • How to Set Up an SPF Record for Your Domain
  • What SPF Email Authentication Checks and Why It Matters
  • How to Set Up a Gmail SPF Record
  • What an SPF Record Is and Where It Goes in DNS
  • SPF record syntax, tag by tag