How to Set Up a Gmail SPF Record

Gmail asks every sender to authenticate with SPF or DKIM. Here is how to build the SPF record, publish it, and check that it passes.

A Gmail SPF record is one of the authentication records Gmail's sender rules ask for. Gmail checks every message sent to its users for authentication. SPF is the DNS record that tells the world which servers may send for your domain. This guide walks through building it, publishing it, and proving it works.

What SPF does and why Gmail requires it

SPF is a TXT record in your DNS. It lists the mail servers allowed to send email as your domain. When a message arrives, Gmail checks whether the sending server is on that list.

Gmail's guidelines say SPF prevents spammers from sending unauthorized messages that appear to be from your domain. Without it, receivers have no list of the servers your domain authorizes.

Gmail's guidelines also say authenticated messages help protect recipients from malicious messages such as spoofing and phishing. That protection is why Gmail performs checks on messages sent to Gmail accounts to verify they are authenticated.

What Gmail's guidelines actually say about SPF

The rules differ by how much you send. Gmail's guidelines say all senders must set up SPF or DKIM email authentication for their sending domains. If you send in bulk, the bar rises. Gmail's guidelines say bulk senders must set up SPF, DKIM, and DMARC for their domain.

Two more lines matter for the record itself. Gmail's guidelines say the SPF record for your domain should include all email senders for your domain. And Gmail's guidelines say if third-party senders are not in your SPF record, their messages are more likely to be marked as spam.

The cost of getting it wrong is spelled out too. Gmail's guidelines say messages that are not authenticated might be marked as spam or rejected with a 5.7.26 error. Gmail's FAQ adds that messages that aren't authenticated with both SPF and DKIM can get temporary or permanent failure codes, or spam foldering.

How an SPF record is built

Every SPF record is a TXT record published on the sending domain. It has a few parts, and each does one job.

The record starts with a version tag. That tag tells receivers this is an SPF record and which version they are reading. It is the same in every record.

After the version tag come the mechanisms. These list the sending servers. Some name servers by IP address. Others pull in a provider's own list with an include. If your newsletter tool or CRM sends as your domain, its include goes here. Each mechanism answers one question: is this server allowed to send for this domain?

The record ends with an all mechanism. This is the policy for every server the record did not list. The strict form tells receivers to fail anything not listed. A softer form lets unlisted servers through with a mark against them. SPF's standard says domains that want receivers to make negative determinations must publish records ending in "-all".

Finding every sender that must be in your record

Before you write the record, take inventory. List every system that puts your domain in the From: header.

Start with your own mail server, if you run one. Then your email service provider. Then your CRM, your newsletter tool, your billing system, your help desk, anything that sends transactional mail. A forgotten sender is a common cause of SPF failure, because that sender's mail arrives from a server the record never named.

Gmail's guidelines say if you use an email service provider, verify that they authenticate your domain's email with SPF and DKIM. Ask the provider what to add to your record. Most publish an include value for exactly this purpose. Do not guess at their settings. Copy what they give you.

Adding the record in your DNS

The record lives in the DNS of the sending domain. That is the domain in your envelope sender, the MAIL FROM address, which DMARC then needs to align with your From: header domain.

Log in to your DNS host. That is usually your registrar, or wherever your domain's nameservers point. Create a TXT record on the domain itself. Paste in the SPF value. Save it.

DNS changes take time to spread. A record you publish today may not be visible everywhere for a while. Wait before you assume something failed.

Common mistakes that make SPF fail

Four errors cover most broken records.

First, a missing sender. Your CRM sends a campaign, the record never listed it, and that mail fails. Fix it by adding the provider's include.

Second, duplicate records. You should publish a single SPF record. If you publish two TXT records that both start with the version tag, SPF's standard says check_host returns permerror. Merge them into a single record.

Third, a record that is too long. DNS has limits on how much one record can hold. A long chain of includes also pushes toward SPF's limit of 10 terms that cause DNS queries, and SPF's standard says exceeding it returns permerror. If your record is huge, look for includes you no longer use and cut them.

Fourth, publishing on the wrong domain. Gmail's guidelines say the authenticating domain must be the same domain that appears in the message From: header. A record on your corporate domain does nothing for mail sent from your marketing subdomain. Gmail's FAQ says the From: header must align with authentication. Check which domain your mail tool actually puts in From:.

How to check your SPF record is working

Start with a DNS lookup tool. Query your domain for TXT records and read what comes back. Confirm there is exactly one SPF record, and that it lists every sender from your inventory.

Then send a test message to a Gmail account. Open the message and show the original, so you can read the headers. Gmail records the SPF result there. A pass means the sending server matched your record.

If the result is a failure, Gmail's error codes tell you which check broke. Gmail's FAQ says error code 4.7.27 means SPF authentication didn't pass. Gmail's FAQ says error code 5.7.27 means the message was blocked because it didn't pass SPF authentication. Both codes point at the SPF record, often at a sender it missed.

Gmail's guidelines also say to use Postmaster Tools to get information about the email you send to Gmail users.

SPF is necessary but not sufficient

SPF alone does not finish the job. Gmail's FAQ says messages must be authenticated with both SPF and DKIM. Gmail's FAQ says bulk senders must set up both SPF and DKIM, but only one needs to be aligned. So a broken SPF record can be rescued by working DKIM, but you should not lean on that.

DMARC sits on top. Gmail's guidelines say DMARC tells receiving servers what to do with messages that don't pass SPF or DKIM. Gmail's guidelines say to pass DMARC authentication, messages must be authenticated by SPF or DKIM, or both. Gmail's guidelines also say to authenticate email with SPF and DKIM that are aligned with each other at the organizational level.

The payoff is simple. Gmail's guidelines say authenticated messages are less likely to be rejected or marked as spam by Gmail. Gmail's FAQ says if senders don't meet the requirements, messages might be rejected or delivered to recipients's spam folders.

Once SPF passes, set up DKIM, then publish a DMARC record. And if mail still bounces after authentication, read the bounce for a blocklist name before assuming SPF is at fault. A dead list like SORBS cannot be the cause, and a live one may name itself in the bounce text.

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
  • What an SPF Record Is and Where It Goes in DNS
  • SPF record syntax, tag by tag
  • What an SPF Record Is and How to Read Yours