Step-by-step SPF setup for Microsoft 365 custom domains: publish one TXT record with include:spf.protection.outlook.com, add third-party senders, stay under the 10 DNS lookup limit and choose -all or ~all.
Home › Guides › SPF for Microsoft 365
Last updated 16 October 2026
If Microsoft 365 is the only service that sends mail as your domain, publish this single TXT record at the root of the domain (host @):
v=spf1 include:spf.protection.outlook.com -all
Using GCC High or DoD? The include is spf.protection.office365.us. Microsoft 365 operated by 21Vianet uses spf.protection.partner.outlook.cn. Commercial and GCC tenants use spf.protection.outlook.com.
Your *.onmicrosoft.com domain already has SPF; Microsoft owns that zone, so you can't (and don't need to) change it. Everything below is for custom domains such as contoso.com.
SPF lists the servers allowed to send mail for a domain. The receiver checks the envelope sender (MAIL FROM / Return-Path, also called the 5321.MailFrom), not the From address people see. That matters for DMARC: SPF only helps DMARC pass when the MAIL FROM domain aligns with the visible From domain. SPF also breaks when mail is forwarded, which is why you need DKIM as well.
Resolve-DnsName contoso.com -Type TXT.v=spf1. Two SPF records is a permanent error (permerror) and SPF fails for all your mail. Merge them into one.Check DMARC aggregate reports if you have them (see the DMARC guide), then ask around. Typical senders:
include:spf.protection.outlook.com.ip4:203.0.113.10 or ip4:203.0.113.0/28. Devices that relay through Exchange Online are already covered by the Microsoft include.include:_spf.google.com (Google Workspace), include:sendgrid.net (SendGrid), include:mailgun.org (Mailgun) and include:_spf.salesforce.com (Salesforce). Always copy the exact value from the vendor's current documentation.Many bulk-mail services send with their own bounce domain in MAIL FROM, so adding their include to your root record does nothing for DMARC alignment. For those, set up DKIM signing with your domain at the vendor (and a custom return-path/bounce domain if they offer one), or move them to a subdomain such as marketing.contoso.com with its own SPF record. Microsoft recommends subdomains for services you don't directly control.
Combine everything into a single record with the SPF Record Builder. Example for Microsoft 365 plus one on-premises relay and SendGrid:
v=spf1 ip4:203.0.113.10 include:spf.protection.outlook.com include:sendgrid.net -all
v=spf1, end with one all term. Anything after all is ignored.a or mx for Microsoft 365. Your MX points at Exchange Online Protection for inbound mail; those terms only cost lookups.+all (lets the whole internet pass) or ptr (deprecated, slow).RFC 7208 caps SPF evaluation at 10 DNS lookups. include, a, mx, ptr, exists and redirect each cost one, and nested includes inside a vendor's record count too. ip4, ip6 and all are free. Go over 10 and receivers return permerror, which DMARC treats as an SPF fail. RFC 7208 also allows only 2 "void" lookups (names that return nothing).
When we checked in October 2026, spf.protection.outlook.com listed Microsoft's IP ranges directly, so it cost one lookup. Microsoft can change that, so recount with the SPF Checker after every edit. To get back under the limit:
ip4/ip6 ranges ("flattening") only if the vendor publishes stable ranges, and recheck them regularly. Microsoft says not to flatten spf.protection.outlook.com because its IP addresses change.-all (hard fail): anything not listed is unauthorized. Microsoft recommends -all for Microsoft 365 domains, alongside DKIM and DMARC, so DMARC can act on mail that fails SPF and has no DKIM signature.~all (soft fail): unlisted senders are probably unauthorized. Reasonable while you are still finding senders.?all (neutral): for testing only. Don't leave it in production.DMARC treats both -all and ~all results as SPF failures. Your DMARC policy, not the SPF qualifier, is what really decides whether spoofed mail is junked or rejected. A practical order: ~all while you build the inventory, then -all once DMARC reports show every legitimate source passing.
@). Microsoft recommends a TTL of at least 3600 seconds (1 hour).spf=pass and an smtp.mailfrom domain that matches your From domain.marketing.contoso.com) needs its own SPF record. DMARC, on the other hand, does cover subdomains.v=spf1 -all plus a DMARC record of v=DMARC1; p=reject;. Don't publish DKIM records for them.include=spf.protection.outlook.com (equals sign), include: spf.protection.outlook.com (space), or a trailing dot after the domain name.spf.protection.office365.us).Need SPF, DMARC and MX checks across a whole client list? Run the Bulk SPF / DMARC / MX Auditor on Apify ($2 per 1,000 domains).
Build or test records with the SPF Record Builder and SPF Record Checker, check the whole domain with the Email Deliverability Checker, and confirm which tenant owns a domain with the M365 Tenant Lookup. Next steps: enable DKIM, then set up DMARC.
For commercial and GCC tenants where Microsoft 365 is the only sender: v=spf1 include:spf.protection.outlook.com -all as a TXT record at the domain root. GCC High and DoD use include:spf.protection.office365.us, and 21Vianet uses include:spf.protection.partner.outlook.cn.
No. If a domain publishes more than one TXT record starting with v=spf1, receivers return a permanent error and SPF fails for all mail. Put every sender into one record.
Microsoft recommends -all (hard fail) for Microsoft 365 domains once DKIM and DMARC are in place. Use ~all only while you are still discovering legitimate senders, then switch.
When we checked in October 2026 it listed IP ranges directly, so it cost one lookup out of the 10 allowed. Microsoft can change its record, so count your whole record with an SPF checker after every change.
No. Microsoft owns onmicrosoft.com and already publishes SPF for it, and you can not modify that record. You do need a DMARC record for it, which you add in the Microsoft 365 admin center.
Runbooks, checklists and helpdesk templates: IT Admin Packs on Gumroad.