Understanding SPF Records
An SPF record is a TXT record on your domain. It lists the servers that are allowed to send email for that domain.
When a mailbox provider receives your email, it checks the sending server against your SPF record. If the server is not listed, SPF fails.
A basic record
v=spf1 include:example-provider.com ~all
v=spf1says this is an SPF record.include:pulls in the servers your provider uses.~allmeans "soft fail" everything else. Mail is marked but not always rejected.-allmeans "hard fail" everything else. Use it only after you are sure every sender is listed.
Most providers tell you exactly which include value to use. Copy it from their DNS setup page.
Common provider examples
These examples are common, but your provider's page is the source of truth.
| Provider | Include value |
|---|---|
| Amazon SES | include:amazonses.com |
| SendGrid | include:sendgrid.net |
| Mailgun | include:mailgun.org |
| Mailjet | include:spf.mailjet.com |
| Postmark | include:spf.mailpostmark.com |
| SparkPost | include:spf.sparkpostmail.com |
| Mandrill | include:spf.mandrillapp.com |
If you send through more than one service, add each include to the same record. Do not create a second SPF record.
Only one SPF record per domain
A domain can have many TXT records, but only one SPF record. If you publish two records that start with v=spf1, SPF breaks.
If you already have an SPF record from your host or another service, edit it. Add the new include inside the existing record.
Watch the lookup limit
SPF allows a maximum of 10 DNS lookups. A lookup is one DNS question the receiving server must ask. Each include, a, mx, ptr, and exists can use one or more lookups.
A record with many includes can exceed the limit and fail even when it looks correct. If you run into this, remove services you no longer use or ask your provider for a solution.
Common mistakes
| Mistake | Result | Fix |
|---|---|---|
Two v=spf1 records | SPF is invalid | Merge them into one record |
| Missing provider include | SPF fails for that provider | Add the include from the provider |
-all too early | Legitimate mail is rejected | Use ~all until every sender is listed |
| Record on the wrong domain | No effect | Put it on the domain used in the From address |
| Extra spaces or line breaks | Invalid record | Publish it as one line |
Check it
dig TXT example.com
Look for one line that starts with v=spf1. If you see two, fix that first.
Next steps
- Add the signature record in DKIM.
- Set a policy in DMARC.
- If mail still goes to the spam folder, read Emails going to spam.