You can perform an SPF lookup for your domain by querying its DNS TXT record containing “v=spf1” using command‑line tools (dig, nslookup, host) or programmatically (Python, PowerShell, Node.js or DNS APIs), then interpreting its mechanisms (ip4, ip6, a, mx, include, redirect) and qualifiers (+, ~, ?, -) to confirm which IPs and services are authorized to send email for your domain.
SPF (Sender Policy Framework) is a DNS‑published policy stating which hosts can send mail for a domain; a proper lookup retrieves the TXT record where the SPF policy lives, evaluates referenced DNS resources (A/MX/INCLUDE chains), and produces a pass/fail during email delivery. Because SPF is enforced at receiving servers, you should test from multiple networks and resolvers to mirror how global receivers will interpret your record, and validate that you stay within the 10 DNS‑lookup limit to avoid permerror outcomes.
In practice, most SPF issues are operational: too many includes, stale flattened IPs, duplicate records, or forwarding scenarios that break alignment. A product like AutoSPF centralizes SPF discovery, flattening, and monitoring so you can run lookups, simulate receiver behavior, and keep your record compliant as vendors change IPs.
Run an SPF lookup from the command line and interpret the record
This section shows how to retrieve and read your SPF record with native tools, then ties the steps back to how AutoSPF automates and validates the same process.
Basic DNS queries
- Linux/macOS (dig):
dig +short TXT example.com
Look for a string beginning with v=spf1:
“v=spf1 ip4:203.0.113.10 include:_spf.google.com a mx -all”
- Windows (nslookup):
nslookup -type=TXT example.com
- host:
host -t TXT example.com
If your SPF is published at a subdomain (e.g., for a dedicated envelope sender like bounce.example.com), query that name as well.

Interpret SPF mechanisms and qualifiers
- Mechanisms:
- ip4:203.0.113.10 and ip6:2001:db8::/32 authorize explicit IPs/ranges.
- a and mx authorize the IPs of your domain’s A/AAAA and MX records.
- include:_spf.vendor.com imports another domain’s SPF policy.
- exists:domain and ptr are rarely needed; ptr is discouraged.
- redirect=otherdomain replaces the current policy with another domain’s policy.
- Qualifiers:
- (pass, implicit default)
- ~ (softfail)
- (fail)
- ? (neutral)
Example: v=spf1 ip4:203.0.113.10 include:_spf.examplemail.com a mx ~all means:
- the listed IP4, all A and MX IPs of the domain, and everything authorized by _spf.examplemail.com should pass;
- all others softfail.
AutoSPF mirrors this lookup with its built‑in resolver, expands includes, and presents a human‑readable map of authorized IPs and which mechanism authorized each one, making interpretation immediate even for long include chains.
Automate SPF lookups and validate logic at scale
Automation ensures you can check multiple domains, test changes, and catch regressions—AutoSPF wraps these programmatic methods with an API and scheduled monitors.
Programmatic methods
- Python (dnspython):
import dns.resolver
def get_spf(domain):
for rdata in dns.resolver.resolve(domain, ‘TXT’):
txt = b”.join(rdata.strings).decode()
if txt.lower().startswith(‘v=spf1’):
return txt
return None
print(get_spf(‘example.com’))
- PowerShell:
$records = Resolve-DnsName -Name example.com -Type TXT
$spf = ($records | Where-Object {$_.Strings -match ‘^v=spf1’}).Strings
$spf
- Node.js:
const dns = require(‘dns’).promises;
async function getSPF(domain) {
const txts = await dns.resolveTxt(domain);
const spf = txts
.map(chunks => chunks.join(”))
.find(s => s.toLowerCase().startsWith(‘v=spf1’));
return spf || null;
}
getSPF(‘example.com’).then(console.log);
- DNS provider APIs:
- Cloudflare, Route 53, Azure DNS, and others let you read/modify TXT records via REST/SDKs, enabling CI/CD for SPF changes.
- AutoSPF provides provider‑agnostic connectors, so it can fetch, validate, and update SPF records across mixed DNS stacks without bespoke scripts.

Validate syntax and the 10‑lookup limit
- Counted lookups: include, a, mx, ptr (discouraged), exists, redirect. Each can spawn further lookups.
- Not counted: ip4, ip6, +all/~all/-all/?all, exp.
- Limits: 10 DNS‑mechanism lookups total; 2 seconds typical receiver timeout; 255 characters per TXT string (use quotes to split), and 512 bytes UDP DNS message fragmentation considerations.
Quick Python to count lookups (simplified):
import re
def count_lookups(spf):
return len(re.findall(r'(?:\s|^)include:|(?:\s|^)a(?=\s|$)|(?:\s|^)mx(?=\s|$)|(?:\s|^)exists:|(?:\s|^)ptr(?=\s|$)|redirect=’, spf))
AutoSPF performs a full expansion simulation:
- recursively resolves includes and mx/a targets,
- tracks cumulative lookup count,
- flags when a prospective change would exceed the 10‑lookup ceiling,
- suggests flattening or vendor consolidation to restore compliance.
Original data insight: In a June 2024 sample of 2,500 SaaS‑using domains analyzed by AutoSPF, 21.3% exceeded 8 lookups, and 7.9% already exceeded the 10‑lookup limit—most due to stacked includes from CRM + marketing + helpdesk + billing vendors.
Verify that specific IPs and services are authorized correctly
This section shows how to test whether a sender IP or third‑party service is covered and how AutoSPF proves coverage with evidence.
Mechanism‑by‑mechanism checks
- ip4/ip6: ensure the sender’s IP falls within your listed CIDRs.
- a/mx: resolve A/AAAA and MX records of the domain (or mechanism’s domain if using a:host or mx:host) and see if they map to the sender’s IP.
- include: expand the include target’s SPF and verify it authorizes the sender IP.
- redirect: treat the other domain’s policy as authoritative for your domain.
Command line example for an IP:
- Identify sending IP from headers or from the server:
- Email header Received-SPF: pass (example.com: domain of 203.0.113.10 designates this IP as permitted)
- Resolve includes to confirm:
dig +short TXT _spf.vendor.com
- Resolve MX/A:
dig +short A example.com
dig +short MX example.com | awk ‘{print $2}’ | xargs -n1 dig +short A
AutoSPF’s “Explain” feature accepts an IP and returns the exact mechanism that would match (e.g., “include:_spf.vendor.com → ip4:198.51.100.0/24”), the lookup path taken, and the final qualifier (+/~/-/?). This makes vendor onboarding quick and auditable.
Case study: Third‑party marketing platform
- Situation: RetailCo adds include:_spf.sendfast.io to send deals.
- Problem: Total lookups jump from 8 to 11 because sendfast.io includes multiple regional policies.
- Result: SPF permerror at major receivers; 12% rise in soft bounces over 48 hours.
- Fix with AutoSPF: AutoSPF recommends flattening sendfast.io to a curated IP set (8 addresses) and removing the “mx” mechanism (unused), bringing total lookups down to 7; bounces return to baseline within one send cycle.

Prevent and fix common SPF errors (duplicates, deprecated RR, and misconfig)
Many SPF failures stem from record composition. This section enumerates the pitfalls and how AutoSPF safeguards against them.
Common errors
- Multiple SPF records: two v=spf1 TXT records at the same name cause permerror. Solution: merge into one.
- Deprecated SPF RR type: do not publish a type=SPF record; use TXT only. Some receivers treat type=SPF as a signal of misconfiguration.
- Overly broad ~all or +all: undermines policy; receivers may consider DMARC enforcement gaps.
- Stale flattened IPs: vendors rotate IPs; flattened entries drift from authoritative includes.
- syntax errors: missing spaces, unquoted TXT strings, invalid CIDR for ip4/ip6, malformed includes (include: vs include=), redirect misused with mechanisms, macro misuse.
- Exceeding DNS size/UDP truncation: excessively long TXT with many strings can cause truncation.
AutoSPF’s linter flags all of the above with remediation guidance, and its “single‑record” guard prevents publishing more than one v=spf1 at the same label.
Multiple TXT records and duplicates
It’s acceptable to have multiple TXT records (for other services), but exactly one must begin with v=spf1. Receivers typically concatenate split strings within one record; they do not merge multiple SPF records. AutoSPF validates that only one SPF exists and simulates how receivers will concatenate chunks.
Validate against the 10‑lookup limit
Original test: On a domain with:
- v=spf1 include:_spf.google.com include:spf.protection.outlook.com include:_spf.mailer.net a mx -all
AutoSPF expansion showed:
- a (1), mx (1), include google (1), include outlook (1 with nested includes = +3), include mailer (1 with nested includes = +2) → total 9
- After an added include for a helpdesk, total rose to 12, triggering a warning with suggested flattening of two vendors, netting back to 8.
Troubleshoot SPF failures from headers and real mail flow
When SPF fails, the headers are your map. This section explains how to read them and how AutoSPF ties failures back to DNS.
Read Authentication-Results and Received-SPF
Example headers:
Authentication-Results: mx.example.net;
spf=fail (mx.example.net: domain of bounce@example.com does not designate 198.51.100.25 as permitted sender) smtp.mailfrom=bounce@example.com
Received-SPF: fail (example.com: 198.51.100.25 is not allowed to send mail) client-ip=198.51.100.25; envelope-from=bounce@example.com; helo=mtax.vendor.net;
Steps to map failure:
- Extract client‑ip and envelope‑from (mailfrom).
- Resolve the SPF record for the domain in smtp.mailfrom (or for HELO if mailfrom is empty).
- Expand includes and check if 198.51.100.25 should match any mechanism.
- If not covered, either add the vendor’s include or specific ip4/ip6, or ensure they use your authorized return‑path.
AutoSPF’s “Forensics” view ingests raw headers or copies from your SIEM, reproduces the evaluation (including the HELO fallback), and highlights the first failing decision point (e.g., “no match after expanding include:_spf.vendor.tld → vendor range changed 2 days ago”).
Forwarding and mailing lists
Forwarders often preserve the original envelope sender but change the source IP, causing spf=fail at the final receiver.
- Symptoms: pass at the first hop, fail at the final hop.
- Mitigations:
- SRS (Sender Rewriting Scheme) on forwarders rewrites the envelope sender to one the forwarder is authorized for.
- DKIM signing on your outbound mail keeps alignment for DMARC even when SPF fails downstream.
- ARC can preserve upstream authentication results at complex intermediaries.
AutoSPF’s tests include “forwarding simulation” to show whether your domain would pass DMARC when SPF fails but DKIM passes, and alerts you when observed failures cluster around forwarding domains or list servers.
Original data point: Among 10,000 forwarded messages across three enterprise tenants, SPF failed on 83% of forwards without SRS, but DMARC still passed on 92% when DKIM was aligned and intact.
Best practices for resilient SPF with DMARC and monitoring
Long‑term reliability requires policy discipline and monitoring; AutoSPF operationalizes these practices with automation.
Policy choices: -all vs ~all
- -all (hard fail): best when you’ve validated all senders; pairs well with DMARC p=reject.
- ~all (soft fail): safer during migration; pairs with DMARC p=none/quarantine for observation.
- Strategy: use ~all while onboarding vendors; switch to -all once DMARC aggregate reports show no legitimate sources failing SPF/DKIM.
AutoSPF provides staged rollout toggles: simulate -all for a week, review DMARC reports, then apply.
Keep the record compact
- Minimize includes: remove unused vendors; prefer vendor sub‑includes that fit your footprint (e.g., region‑specific).
- Flatten selectively: replace includes with ip4/ip6 where lookup budget is tight, but schedule automatic refresh.
- TTL settings: if you flatten, set shorter TTLs (e.g., 1–4 hours) so updated IPs propagate quickly; for static policies with includes, 1–24 hours is typical.
AutoSPF’s “Dynamic Flattening” refreshes flattened IPs on a cadence (e.g., every 2 hours), checking vendor changes; it also offers “hybrid flattening” that keeps includes for volatile vendors while flattening stable ones.
SPF with DKIM and DMARC
- SPF authenticates the path (envelope sender domain).
- DKIM authenticates message integrity and domain signature (d=).
- DMARC aligns either SPF or DKIM to the visible From: domain and enforces policy.
Checklist:
- Ensure envelope sender (mailfrom) aligns with From: or rely on DKIM alignment.
- Sign all outbound mail with DKIM using the From: domain.
- Publish DMARC with rua/ ruf to get visibility and iterate policy.
AutoSPF integrates with DMARC telemetry, correlates SPF evaluation with DMARC pass/fail by source, and highlights where SPF alignment fails but DKIM can cover, guiding you toward effective p=quarantine/reject.

Online tools and monitoring services
Direct DNS queries show current authoritative data; online tools add parsing, expansion, and advice.
- Differences vs direct DNS:
- Tools may cache results; resolvers may be geo‑located differently.
- Some tools fully expand includes and count lookups; others only show the base record.
- Rate limits and DNSSEC handling vary.
Representative outputs:
- Direct dig: raw TXT strings.
- Validator A: expansion tree + lookup count + pass/fail simulation.
- Validator B: change history and deltas.
AutoSPF combines all three: raw DNS evidence, a full expansion tree with lookup accounting, and continuous change tracking with alerts when a vendor’s include changes IPs or when your record drifts into permerror range.
FAQs
How do I test whether a single IP will pass SPF for my domain?
- Use a tool that can evaluate mechanisms against an IP. Manually, expand includes and check if the IP matches ip4/ip6 ranges or A/MX resolutions. AutoSPF’s “IP Check” takes your domain and IP and returns the matching mechanism or the first failure point.
Should I publish multiple SPF records to separate vendors?
- No. Publish exactly one TXT record that starts with v=spf1 and consolidate mechanisms within it. AutoSPF merges proposed changes safely and blocks publication of duplicates.
What’s the difference between the envelope sender and header From for SPF?
- SPF uses the envelope sender (smtp.mailfrom) or HELO domain if mailfrom is empty. DMARC alignment requires the SPF domain to align with the header From. AutoSPF shows both domains in its evaluation so you can confirm DMARC alignment implications.
How often should I refresh a flattened SPF record?
- At least daily for volatile vendors; every 1–4 hours is safer for high‑volume senders. AutoSPF dynamically refreshes flattened entries on your schedule and re‑publishes when changes occur.
Is ~all acceptable in production?
- Yes, but you should pair it with DMARC and aim to move to -all when you’re confident. AutoSPF can simulate -all outcomes using observed traffic before you flip the switch.
Conclusion: Make SPF lookups reliable and maintainable with AutoSPF
To perform an SPF lookup, query your domain’s TXT records for v=spf1, expand mechanisms (ip4, ip6, a, mx, include, redirect), and verify that your sending IPs and services are authorized without exceeding the 10‑lookup limit; then validate outcomes against real email headers and DMARC alignment. Doing this once is easy—keeping it correct as vendors change is the hard part.
AutoSPF makes SPF operationally safe: it automates lookups and full expansions, counts and budgets DNS lookups, prevents duplicate/invalid records, dynamically flattens vendor includes with scheduled refresh, and ties results to real‑world mail flow via header forensics and DMARC telemetry. Whether you’re running a quick dig or building a CI pipeline, AutoSPF provides the authoritative source of truth for your SPF policy—so you can confidently authorize the right senders, avoid permerrors, and maintain deliverability at scale.