☎ +17089411327 ✉ support@goix.net Client Area
24/7 SupportDedicated Technical Support
Maximum ROIUse our SMTP earn Maximum ROI
100% UptimeOur Server 100% Uptime Based
How to Set Up an SPF Record: A Step-by-Step Guide for Mail Servers

How to Set Up an SPF Record: A Step-by-Step Guide for Mail Servers

Sender Policy Framework, usually shortened to SPF, is one of the core building blocks of modern email authentication, alongside DKIM and DMARC. It is also the one that causes the most quiet, confusing failures. A missing SPF record can leave your domain open to spoofing. A broken record can be almost as bad, because receiving servers may treat your legitimate mail as unauthenticated and file it in spam.

This guide walks through the whole process: taking stock of everything that sends mail for your domain, writing the record, publishing it in DNS, counting your DNS lookups, and testing the result. It is written for people who run their own mail server or a dedicated sending service, but the same principles apply to any domain that sends email. If you send from a dedicated SMTP email server, getting SPF right matters especially, because your sending IP addresses are yours alone and your record should reflect that precisely.

What SPF Is and What It Actually Does

SPF is a DNS-based authentication system. The domain owner publishes a policy in DNS listing which servers are authorised to send email using that domain in the envelope sender address, also called the return path or MAIL FROM address. When a receiving server accepts a message, it looks up the SPF policy for that envelope domain and compares the connecting server's IP address against the authorised list.

Be clear about what SPF does not do. It does not check the visible From header your readers see, although DMARC later ties the envelope domain and the visible domain together through alignment. It does not encrypt anything, sign message content, or prove that a message is welcome.

SPF also breaks in a predictable way when mail is forwarded. If someone forwards your message, the forwarding server becomes the connecting server, and its IP is unlikely to be in your record. This is a known design trade-off, and one reason DKIM matters: a valid DKIM signature usually survives forwarding.

Before You Write Anything: Inventory Your Senders

Most SPF problems start before anyone touches DNS, with an incomplete list of senders. If you publish a record that forgets a service, that service's mail will fail authentication as soon as the record propagates.

List every system that sends for your domain

The list is usually longer than people expect. Common categories include:

  • Your main mail server or dedicated SMTP server, sending direct user mail and application mail.
  • Your website and applications, including contact forms, password resets, and order confirmations.
  • Transactional services used for receipts, alerts, or delivery notifications.
  • Marketing platforms, newsletter tools, and CRM systems that send campaigns on your behalf.
  • Help desk, billing, monitoring, and invoicing systems, which often send through a vendor.
  • Third-party tools team members signed up for individually, such as survey or scheduling tools.

For each sender, record three things: the envelope domain it uses, the IP addresses or hostnames it sends from, and any SPF include value the provider publishes. Providers that send for many customers almost always give you an include mechanism rather than IP addresses, because their ranges change.

Check what is published today

Look at your current DNS before changing anything. You may already have a record, perhaps created years ago or automatically by a hosting panel, and leftover entries for services you no longer use. Note what exists and whether anyone still relies on it.

SPF Syntax: Reading a Record Piece by Piece

An SPF record is a DNS TXT record beginning with a version tag, followed by terms separated by spaces. A typical record looks like this:

v=spf1 ip4:203.0.113.25 include:_spf.example-provider.com -all

Every part has a job. Reading a record left to right is the easiest way to understand it, and writing one in the same order helps you avoid mistakes.

The version tag

Every record starts with v=spf1. This is not optional and must be first. It tells the receiver that this TXT record is an SPF policy rather than other text that happens to live in DNS.

Mechanisms

After the version tag come mechanisms, tested in order from left to right. The first mechanism that matches the connecting IP determines the result, so order matters.

  • ip4 and ip6: Authorise a specific IP address or a range in CIDR notation, such as ip4:203.0.113.25 or ip4:198.51.100.0/24. These are the most direct mechanisms and cost no extra DNS lookups.
  • a: Authorises the IP addresses in the A or AAAA records of a domain. Convenient, but it costs a lookup and can authorise more than you intend if the hostname points to shared infrastructure.
  • mx: Authorises the servers in the domain's MX records. This made sense when the same servers handled inbound and outbound mail, but it is less precise for modern setups and also costs lookups.
  • include: Imports another domain's policy, typically a provider's, such as include:_spf.example-provider.com. Necessary and powerful, but each include adds to your lookup count.
  • exists: Checks whether a domain name resolves at all. It has specialised uses and is rarely needed in ordinary records.
  • redirect: A modifier that points evaluation to another domain's policy entirely. It replaces rather than supplements the rest of the record, so use it deliberately.

Qualifiers and the all mechanism

Each mechanism can carry a qualifier, a single character that says what result to return when it matches:

  • + means Pass. It is the default when no qualifier is written, so it is usually omitted.
  • - means Fail. The server is explicitly not authorised.
  • ~ means SoftFail. The server is probably not authorised, but the statement is not firm.
  • ? means Neutral. The domain makes no statement, which offers little protection.

The final term in most records is all, which matches every remaining IP address. It is your default for anything not authorised earlier. Ending in -all is strict: anything not listed fails. Ending in ~all is transitional, often used while still discovering senders.

Worked Examples of SPF Records

Examples make the syntax concrete. The addresses below use documentation ranges reserved for examples, so copy the structure and substitute your own real addresses.

Example 1: A single dedicated mail server

v=spf1 ip4:203.0.113.25 -all

This is the cleanest possible record: one IP may send for the domain, and everything else fails. If your dedicated server has a second sending IP, add it explicitly: v=spf1 ip4:203.0.113.25 ip4:203.0.113.26 -all.

Example 2: A mail server plus one provider

v=spf1 ip4:203.0.113.25 include:_spf.example-provider.com -all

Your own server is authorised directly, and a provider is authorised through its published include. If the provider changes its sending ranges, it updates its own record and your mail keeps passing without you editing DNS.

Example 3: Multiple services and an IPv6 address

v=spf1 ip4:203.0.113.25 ip6:2001:db8::25 include:_spf.example-provider.com include:spf.example-helpdesk.com -all

This record authorises your server on both address families and two external services. Notice what is absent: there is no a and no mx, because the explicit addresses already cover the server.

Example 4: A subdomain with its own policy

Subdomains that send mail need their own SPF records. If alerts.example.com sends through a monitoring platform, that subdomain gets its own TXT record, such as v=spf1 include:spf.example-monitoring.com -all. The root domain's record does not cover subdomains automatically.

Step by Step: Publishing Your Record in DNS

With your inventory complete and your record drafted, publishing is a careful, mechanical process. Take it in order and do not rush verification.

Step 1: Draft the complete record first

Write the full record in a text editor before opening your DNS console. Assemble it from your inventory: version tag first, then your own IP mechanisms, then each provider's include, then the final -all.

Step 2: Open the DNS zone for the exact domain

Sign in to wherever your DNS is hosted, which may be your registrar, a DNS provider, or a hosting panel, and open the zone for the envelope domain. Be careful to edit the right name. A record for the root domain goes at the apex, often shown as @ or left blank, while a subdomain record goes at that subdomain's name.

Step 3: Add or edit the TXT record

If no SPF record exists, create a new TXT record containing your full policy as a single value. If one already exists, edit that record rather than adding a second one. A domain must have exactly one SPF record. Two records do not combine; they cause a permanent error, often called a PermError, and receivers may treat all your mail as unauthenticated.

Step 4: Watch out for quoting and splitting quirks

Some DNS interfaces wrap TXT values in quotation marks automatically; others require you to add them. Follow your provider's convention and check the published result afterwards rather than assuming the console display is what the world sees. Very long records can also be split into multiple character strings by some systems.

Step 5: Save, wait, and verify from outside

Save the record and allow time for propagation according to the previous time-to-live value. Then verify from outside your provider's console, using the testing methods below.

The 10-Lookup Limit and How to Count It

SPF has a hard limit that surprises many administrators: evaluating a record may cause at most ten DNS lookups for mechanisms that require them. The mechanisms that count are include, a, mx, exists, and redirect, plus lookups triggered inside included policies.

Counting is not as simple as counting the includes in your own record, because includes nest. One include can contain further includes and a or mx mechanisms of its own, and all of them count against your ten. A record with four innocent-looking includes can exceed the limit once each provider's policy expands.

To stay safely under the limit, keep a running count whenever you add a sender, using a checking tool that reports the total lookup count, not just syntax. If your count climbs, look for savings in this order. First, remove senders you no longer use; dead includes are pure cost. Second, replace a and mx mechanisms with explicit IP mechanisms where addresses are stable, especially for your own server.

Common SPF Errors and How to Fix Them

Publishing more than one SPF record

This is the most damaging simple mistake. It often happens when a new service tells someone to add a TXT record and they create a second one instead of editing the existing record.

Syntax mistakes that invalidate the whole record

Small typing errors have outsized effects. Watch for a missing version tag, a misspelled mechanism, a space inside an IP address, a colon in the wrong place, or an include domain that does not itself publish an SPF record.

Authorising too much

Broad mechanisms feel safe because nothing breaks, but they quietly weaken your policy. A large network range copied just in case, an a mechanism pointing at a shared web server, or a leftover +all or ?all ending can authorise infrastructure you do not control.

Forgetting the record when things change

SPF fails later, not just at setup. A server migration changes your sending IP. A new help desk starts sending notifications. A marketing tool is replaced. Each change needs a matching SPF update, ideally in the same change window.

Testing Your SPF Record Properly

Never consider the job finished until you have tested from the receiver's point of view. Testing has two layers: checking the published record, and checking real messages.

Query DNS directly

On Linux or macOS, run dig TXT example.com and look for the SPF policy in the answer. On Windows, nslookup -type=TXT example.com does the same job. Confirm that exactly one record starts with v=spf1, that the text matches what you drafted character for character, and that no extra record has appeared.

Use an SPF validation tool

Run the domain through a reputable SPF checker. A good tool parses the record, expands the includes, reports the total DNS lookup count, and flags PermErrors, duplicate records, overly broad mechanisms, and includes that point nowhere.

Send real test messages

Send actual mail from each authorised source to an external mailbox you control, and inspect the authentication results in the message headers. Look for the Authentication-Results header and confirm SPF reports a pass for the correct domain. Test every stream, not just your main one: the forgotten billing system is precisely the one that will fail in production.

Maintaining SPF Over Time

Treat your SPF record as living configuration, not a one-time project. Keep a short internal note of what each mechanism is for and which team or service requested it. Review the record a few times a year and whenever a sending service changes. Keep the lookup count comfortably below ten, so a provider expanding its own policy does not push you over the limit without warning.

Getting SPF Right on Infrastructure You Control

SPF rewards precision. The more directly you control your sending infrastructure, the more precise your record can be: a short list of your own IP addresses, a small number of deliberate includes, a lookup count with room to spare, and a firm -all at the end.

If you are ready to send from infrastructure built for this job, take a look at our dedicated SMTP email server plans: you get your own sending IPs, full support for SPF, DKIM, DMARC, and matching reverse DNS, and a setup where your authentication records can stay short, strict, and entirely under your control. Set up your SPF record properly, put it on a server that deserves it, and your mail will arrive with the authentication it needs to be trusted.

← Back to blog