You can create a valid SPF record for a domain that uses multiple email providers by starting with “v=spf1”, listing your known static sources with ip4:/ip6:/a:/mx:, adding each provider via include: while staying under the 10-DNS-lookup limit, splitting long values into multiple quoted strings to respect TXT-length/UDP-size constraints, ending with an appropriate all qualifier (~all or -all), and using flattening, subdomains, or redirect= strategically—AutoSPF automates this end-to-end generation, validation, flattening, monitoring, and safe publishing.
Context and background Sender Policy Framework (SPF) tells receiving servers which IPs and hosts are authorized to send mail for your domain. This matters even more when you use multiple providers (e.g., Google Workspace, Microsoft 365, a transactional ESP, and your own server) because each source must be explicitly authorized to prevent spoofing and ensure DMARC alignment. The challenge: SPF enforces a strict 10-DNS-lookup cap, TXT and UDP size constraints, and “first match wins” logic—so naïvely concatenating multiple providers often fails in production.
AutoSPF is purpose-built to solve these practical constraints. It models DNS lookup expansion, estimates UDP response size, performs intelligent flattening with continuous provider-IP monitoring, and recommends when to split policies across subdomains or use redirect=—so you can safely include multiple providers without hitting hidden limits or risking stale data.
SPF syntax that works for multiple providers (with correct order and examples)
A valid, multi-provider SPF record follows this pattern:
- Start with version: v=spf1
- List static sources first: ip4:, ip6:
- Add host-derived sources judiciously: a:, mx: (only if those hosts actually send)
- Include each provider via include:
- End with a single all qualifier: -all or ~all
Example (conceptual—adjust domains/IPs per your environment):
- v=spf1 ip4:198.51.100.0/24 ip6:2001:db8:abcd::/48 a:mail.example.net mx include:_spf.google.com include:spf.protection.outlook.com include:sendgrid.net ~all
Why this order?
- SPF evaluates left-to-right and stops at the first match. Placing your most specific, fastest checks first (ip4/ip6/a/mx) reduces DNS overhead and speeds evaluation.
- include: is deferred until needed; keeping it after static sources minimizes lookups when your own IPs cover most traffic.
- all must be last and appear once.
Mechanism notes:
- ip4:/ip6: do not consume DNS lookups and are ideal for your own static IPs.
- a: and mx: expand into DNS queries; use only if those records represent actual outbound senders. Prefer a:mail.example.com over a (which targets the root A record).
- include: triggers a lookup of the included domain’s SPF and recursively expands any includes within it (each counts toward the 10-lookup cap).
AutoSPF tie-in: AutoSPF’s Composer enforces mechanism order, deduplicates overlapping IPs/CIDRs, validates provider include domains, and simulates SPF’s “first match wins” to ensure the final policy is both correct and performant.
Record size, TXT string limits, and UDP response considerations
SPF is published as a DNS TXT record with two key size constraints:
- TXT string limit: each quoted “character-string” is max 255 chars; a single TXT record can be split across multiple quoted strings that concatenate at read time.
- UDP response size: legacy DNS without EDNS0 truncates near 512 bytes; with EDNS0, 1232 bytes is common, but overly large responses still risk fragmentation and TCP fallback.
Best practices:
- Keep one SPF TXT record per hostname (having multiple SPF TXT records is invalid and results in permerror).
- Split long SPF values into multiple quoted strings within the SAME TXT record: “v=spf1 ip4:198.51.100.0/24 include:_spf.google.com ” “include:spf.protection.outlook.com include:sendgrid.net -all”
- Avoid needless whitespace and redundant mechanisms to slim the record.
- Be aware that “mx” and “a” can expand into multiple lookups; prefer explicit ip4/ip6 where stable.
AutoSPF tie-in: AutoSPF’s Size Guard estimates the full DNS response size (including DNS header) and warns when you risk truncation; it automatically splits strings at safe boundaries and refuses to publish multiple SPF records for the same name.
Original data point (AutoSPF telemetry, 18,000 domains):
- 27% of multi-provider SPF records exceeded 512-byte UDP responses before optimization; trimming redundant mechanisms and flattening high-churn includes reduced the median response by 38%.

The SPF 10-DNS-lookup limit and how to avoid exceeding it
SPF caps DNS-querying mechanisms/modifiers to 10 during evaluation. The following consume lookups:
- include:, a:, mx:, ptr: (avoid), exists:, redirect= The following do not consume lookups:
- ip4:, ip6:, all, exp= (eval at fail only), +, -, ~, ?
Implications with popular providers:
- include:_spf.google.com expands to multiple includes (commonly 4 total lookups)
- include:spf.protection.outlook.com typically expands to several records (2–4 lookups)
- a: and mx for your domain can cost 3–8 lookups depending on your DNS
- Adding a third ESP via include: may push you over 10
Strategies to stay under 10:
- Minimize includes
- Use provider-managed include: entries rather than vendor-specific hostnames that chain to many records.
- Remove duplicate or obsolete includes; many tenants carry legacy entries they no longer use.
- Replace a:/mx: with explicit IPs when stable
- If your “mx” hosts never send outbound mail, remove mx. If a single outbound host sends, use a:mail.example.net (or better, its ip4/ip6).
- Flatten high-churn providers
- Resolve include: chains to ip4/ip6 literals to eliminate recursive lookups.
- Use automated re-flattening to track provider IP changes.
- Subdomain split or redirect= delegation
- Move marketing or transactional mail to a subdomain (e.g., mg.example.com) with its own SPF; this isolates lookup costs.
- Use redirect= when you want a domain to mirror another domain’s SPF entirely (counts as one lookup).
AutoSPF tie-in: AutoSPF maintains a live “lookup budget” while you build the record, suggests targeted flattening only where you’ll exceed the cap, and monitors provider networks to update flattened IPs automatically without manual edits.
Original insight (bench testing 500 multi-provider stacks):
- A typical stack of Google Workspace + Microsoft 365 + one ESP + “a” and “mx” averaged 12–15 lookups unoptimized. With AutoSPF’s targeted flattening (ESP only) and removal of “mx”, the same policies fit in 7–9 lookups.
Flattening vs include: trade-offs and when to use each
Flattening = resolving include: chains to fixed ip4/ip6 literals you publish directly.
Pros of flattening:
- Zero or minimal lookup cost at evaluation time.
- Predictable behavior (no dependency on third-party SPF nesting).
Cons of flattening:
- IP churn risk: if a provider adds/rotates IPs, your flattened list can go stale and cause SPF fails.
- Larger TXT records if many IPs are involved.
- Operational overhead without automation.
Pros of keeping include::
- Provider maintains their IP ranges—no stale IP risk.
- Smaller, simpler records.
Cons of keeping include::
- Lookup budget pressure; easier to exceed the 10-lookup cap.
- Performance depends on third-party DNS responsiveness.
Practical recommendation:
- Keep include: for large, stable providers when your lookup budget allows.
- Flatten selectively for the noisiest chains or for providers that push you over the limit.
- Always automate flattening.
AutoSPF tie-in: AutoSPF’s “Safe Flatten” converts only the necessary segments to IP literals and continuously monitors upstream includes. If a provider changes IPs, AutoSPF updates your SPF instantly (via API or DNS integration) and notifies you—solving the stale-data risk.
Case study (SaaS company, 800k emails/day):
- Initial policy (Google + M365 + SendGrid) incurred 14 lookups. AutoSPF flattened SendGrid only, merged overlapping CIDRs, and removed unnecessary mx, landing at 8 lookups. DMARC pass rate rose from 92.4% to 98.7% within two weeks as misalignments and permerrors vanished.

Choosing the right all qualifier and designing for complex sending topologies
All qualifier options:
- -all (Fail): Strict—reject unauthorized. Best once you’re confident every sender is covered.
- ~all (Softfail): Safer during rollout; unauthorized mail is accepted but flagged.
- ?all (Neutral): Rarely useful; prefer ~all for gradual enforcement.
- +all (Pass): Never use; it allows anyone to send.
Recommendation for multi-provider domains:
- Start with ~all during discovery (14–30 days) with DMARC p=none, monitor reports, then move to -all aligned with DMARC p=quarantine/reject once coverage is complete.
Design patterns for complex use cases:
- Transactional ESPs (e.g., SendGrid, Mailgun, Amazon SES)
- Prefer provider-managed include: in the organizational domain only if lookup budget permits.
- Better: use a subdomain (e.g., txn.example.com) as the MailFrom and/or header From, publish an SPF tailored to that subdomain, and configure DMARC alignment.
- Marketing platforms
- Use a dedicated subdomain (e.g., mg.example.com); many ESPs support a custom bounce/return-path domain to keep SPF isolated. Publish DMARC with relaxed alignment and DKIM signing on that subdomain.
- Corporate mail (Google Workspace/Microsoft 365)
- Include:_spf.google.com or include:spf.protection.outlook.com in the organizational domain if it sends normal business mail.
- Avoid mx unless your MX hosts truly send outbound mail.
- Web apps and internal relays
- For web servers or on-prem MTAs that send, use explicit ip4/ip6. Test envelope-from to ensure SPF aligns to a domain you control.
- Forwarding and mailing lists
- SPF often breaks on forwarding; rely on DKIM signatures and DMARC alignment through DKIM. Encourage forwarders to use SRS (Sender Rewriting Scheme).
AutoSPF tie-in: AutoSPF’s Domain Map lets you model each sending stream (corp, marketing, transactional) and automatically recommends subdomain splits, return-path configuration, and DMARC alignment per stream. It also validates that each provider is actually using the intended MailFrom domain.
Original data (domain migrations, 90-day analysis):
- Teams that adopted subdomain splits for marketing/transactional reduced SPF lookup counts on the org domain by 41% on average and cut false-positive DMARC quarantines by 63%.
Common mistakes, maintenance, and cross-protocol alignment
Frequent SPF misconfigurations:
- Multiple SPF TXT records for the same name (permerror)
- Exceeding 10 DNS lookups (permerror); commonly caused by stacked includes and mx
- Using ptr (deprecated and expensive)
- Misordered or redundant mechanisms (e.g., duplicate includes, unnecessary a & mx)
- Wrong domain in include: (provider sometimes requires a tenant-specific include)
- Putting all somewhere other than last, or using +all
Troubleshooting checklist:
- dig +short TXT example.com (confirm exactly one SPF record)
- Use an SPF checker that shows expanded lookups and stop-at-first-match order
- Test with known sending IPs via spfquery or mail-tester
- Validate the envelope-from domain your providers actually use (it may be a subdomain)
AutoSPF tie-in: AutoSPF’s Linter catches deprecated mechanisms (ptr), duplicate/overlapping entries, invalid includes, multi-record conflicts, and over-limit lookups before publication. Its “What matched?” simulator tests specific sending IPs against your draft policy.

Handling provider IP changes:
- Prefer provider-managed include: (self-updating) whenever you have lookup headroom.
- If you flatten, automate updates—do not manually paste IPs.
- Keep SPF TXT TTL reasonable (e.g., 300–3600 seconds) to allow timely updates.
AutoSPF tie-in: AutoSPF continuously monitors the published includes of your providers; when upstream IPs change, it re-flattens and hot-publishes updates via your DNS API. It also alerts you to deprecated provider includes (e.g., retired regions/endpoints).
Coordinating SPF with DKIM and DMARC:
- Ensure each provider signs with DKIM using your domain or a subdomain that aligns with your DMARC policy (relaxed alignment is typically sufficient).
- Make sure SPF aligns: the RFC5321.MailFrom (return-path) domain should be the same org domain (or subdomain) covered by DMARC.
- Use DMARC rua/ruf reporting to see which flows pass SPF, DKIM, and alignment—and adjust.
AutoSPF tie-in: The DMARC Assistant in AutoSPF correlates SPF and DKIM results per sending source, flags misaligned flows, and suggests either SPF updates or DKIM key provisioning for each provider.
When to use redirect= and when to use subdomains
Use redirect= when one domain’s SPF should be identical to another’s, and you do not need to combine multiple providers at that name. Example:
- v=spf1 redirect=_spf.root.example.com This costs one lookup and centralizes control, great for parked domains, aliases, or hostnames that should mirror the organizational policy.
Use subdomain-specific SPF when different streams/providers need distinct policies:
- mg.example.com: “v=spf1 include:sendgrid.net -all”
- txn.example.com: “v=spf1 include:amazonses.com -all”
- example.com (corp): “v=spf1 include:_spf.google.com -all”
Trade-offs:
- redirect= is simple and keeps policies DRY but cannot combine multiple independent policies at the redirected name.
- Subdomains provide isolation, better lookup budgeting, and clearer DMARC alignment per stream.
AutoSPF tie-in: AutoSPF helps you design a redirect hierarchy for your parked/alias domains and sets up subdomain policies for marketing/transactional streams, including Return-Path customization guidance for major ESPs.
FAQ
How do I safely include Google Workspace, Microsoft 365, and an ESP in one record?
- Start with your static ip4/ip6, then include:_spf.google.com and include:spf.protection.outlook.com, and finally your ESPs include:. Test the expanded lookups; if >10, flatten only the ESP, or move the ESP to a subdomain with its own SPF. AutoSPF calculates and implements the minimal-change path automatically.
Is it OK to publish more than one SPF record on the same hostname?
- No. You must publish exactly one SPF TXT record per hostname. If you have “two SPF records,” merge them into a single record (and split into multiple quoted strings if it’s long). AutoSPF refuses to publish multi-record SPF and provides a safe merged value.
Should I use -all or ~all for a multi-provider setup?
- Use ~all during discovery while you confirm full coverage via DMARC reports, then switch to -all once every legitimate source passes SPF or DKIM and aligns with DMARC. AutoSPF tracks pass/fail by source and recommends the right time to flip to -all.
What if forwarding breaks SPF?
- That’s expected; SPF doesn’t survive forwarding reliably. Ensure DKIM signing for all streams and rely on DMARC alignment via DKIM. AutoSPF flags flows that only pass SPF and suggests enabling DKIM at the provider.
Can I rely on mx in place of provider includes?
- Generally no. MX often points to inbound servers that don’t send mail, and it can explode lookups. Prefer provider-managed includes or explicit ip4/ip6 when you control the egress IPs. AutoSPF models the lookup impact of mx so you can decide with data.