How to configure an SPF record for Office 365 securely
Key Takeaways
A secure SPF deployment starts with an accurate inventory of every system that sends mail for the domain. The record must be published correctly, validated against DNS, and maintained as mail flow changes.
- Use one SPF TXT record per domain and combine all legitimate sending sources.
- Add Microsoft 365 with
include:spf.protection.outlook.com. - Check the ten-DNS-lookup limit before publishing a complex policy.
- Treat SPF as one part of a wider SPF, DKIM, and DMARC configuration.
- Review and validate the record whenever a mail service or vendor changes.
Understand how SPF works with Office 365
SPF, or Sender Policy Framework, allows a domain owner to list authorized mail sources in DNS. Receiving mail systems compare the sending server with that published policy. A correct SPF record for Office 365 therefore describes the domain’s real outbound mail flow, rather than merely copying a standard value and leaving it unchanged.
What an SPF record validates
An SPF record is a DNS TXT record that identifies sources permitted to send mail for a domain. The receiving system evaluates the SMTP envelope sender, also called the MAIL FROM domain, and checks whether the connecting IP address is authorized by that domain’s policy. SPF does not inspect the visible From header by itself.
That distinction matters when a message appears to come from one address but uses a different envelope sender. SPF can pass for the envelope domain while the visible address remains unrelated to the authenticated source.
How Microsoft 365 evaluates authorized senders
For a custom domain used with Microsoft 365, the domain’s DNS must identify Microsoft 365 as an authorized mail source. The usual mechanism is an include that points to Microsoft’s published SPF policy. A default onmicrosoft.com domain is handled differently because its DNS is managed by Microsoft.
The record should also account for any other platform that sends mail using the same domain. Microsoft 365 authorization does not automatically cover a marketing platform, application server, or on-premises relay.
Why each domain should have only one SPF record
A domain should publish one SPF policy at a given name. Multiple TXT records beginning with v=spf1 can produce a permanent error because receivers cannot reliably combine them. The remedy is to merge authorized mechanisms into a single record, not to publish a second policy beside the first.
This is a useful point to verify in a broader SPF record guide, especially when a domain has inherited records from an older provider. Subdomains are evaluated separately and may need their own policy when they send mail independently.
How SPF alignment differs from message authentication
SPF authenticates the envelope sender domain. DMARC alignment then checks whether that authenticated domain corresponds sufficiently with the visible From domain. DKIM takes a different path: it uses a cryptographic signature and a signing domain that can also be evaluated for alignment.
Consequently, an SPF pass is not the same as proof that the visible sender address is genuine. A secure deployment uses SPF alongside DKIM and DMARC rather than treating one result as complete message authentication.
Build the correct SPF record for Office 365
Construct the record from the mail-flow inventory, not from assumptions about how the organization used to send mail. Start with the Microsoft 365 mechanism, then add only the services that are authorized and still required. Keep the policy readable enough that another administrator can review it later.
The syntax is compact, but small errors have operational consequences. Before publishing, compare the proposed value with the guidance in this Microsoft 365 SPF setup and confirm that existing mechanisms have not been lost.
The standard Microsoft 365 SPF mechanism
For Microsoft 365, the standard mechanism is include:spf.protection.outlook.com. A minimal example for a domain that sends only through Microsoft 365 is:
v=spf1 include:spf.protection.outlook.com -all
The final qualifier is a policy choice. A hard fail can be appropriate once all legitimate sources have been confirmed; during investigation, some organizations first use a softer policy while they identify missed senders. The mechanism itself authorizes the sources published by Microsoft, rather than a manually maintained list of Microsoft IP addresses.
When to use the include mechanism
Use include when an external mail provider publishes its own SPF policy for customers to reference. This keeps the provider’s authorized infrastructure under its control and avoids copying addresses that may change. Each included policy still contributes DNS-query work to the overall evaluation.
Do not add an include merely because a vendor account exists. The vendor must actually send mail using the domain, and its documented SPF value should be confirmed before it enters the record.
How IP addresses and hostnames affect SPF design
An ip4 or ip6 mechanism authorizes a stated address or range directly. Hostname-based mechanisms can depend on DNS records and may introduce additional lookups. The choice should reflect stable ownership: a fixed corporate relay may suit an IP mechanism, while a managed provider is often better represented by its published include.
The A-record relationship is worth reviewing when a hostname-based mechanism is considered. Authorizing a hostname can change as its A or AAAA records change, so the resulting scope needs periodic review.
SPF syntax rules that can invalidate a record
The value must begin with v=spf1, use valid mechanisms and qualifiers, and end with an intentional policy such as ~all or -all. A second SPF record, malformed separators, an accidental line break, or an unsupported mechanism can make the result unusable.
A practical review should confirm the following points before deployment:
- The host name is the domain that actually sends mail.
- Every
includevalue comes from a legitimate sending service. - The record remains within the ten-DNS-lookup limit.
- The final
allqualifier matches the organization’s rollout stage.
After this check, validate the complete value rather than inspecting only the Microsoft 365 fragment. A syntactically neat record can still omit a required sender.
Identify every legitimate sending service
Most SPF failures are inventory failures before they are DNS failures. Mail may leave through Microsoft 365, an older relay, a ticketing system, a campaign platform, or a device that nobody remembered during the change. The domain owner should map those paths before choosing a restrictive final qualifier.
Treat each source as a separate flow, even when the visible From address is the same. This approach also makes later vendor retirement and incident review considerably clearer.
Microsoft 365 mail flow
List the Microsoft 365 domains and outbound paths used by the organization. For a custom domain, the SPF policy normally includes Microsoft’s published authorization mechanism. Confirm that users, shared mailboxes, automated notifications, and any other Microsoft 365-originated messages are covered by the intended domain.
Do not assume that incoming MX configuration proves outbound authorization. MX records describe mail delivery destinations, while SPF describes permitted sending sources.
On-premises Exchange and hybrid deployments
Hybrid environments often have more than one outbound route. Document whether messages can leave through an on-premises Exchange server, a third-party gateway, or Microsoft 365, and identify the public addresses involved. If a relay is retired, its SPF authorization should be removed after the mail-flow change is verified.
A temporary overlap may be necessary during migration, but it should have an owner and an end date. Permanent allowances for obsolete infrastructure enlarge the domain’s trusted sending surface.
Third-party marketing and transactional email platforms
Campaign and transactional services commonly publish an include value or require a dedicated sending subdomain. Obtain the provider’s current instructions and confirm which domain appears in the envelope sender. Do not guess an IP range from a web page or add a vendor that only receives mail.
Separating high-volume or application mail onto a dedicated subdomain can make authorization easier to manage. It also limits the effect of a change to the relevant stream.
Printers, applications, and security appliances that send mail
Printers, monitoring tools, scanners, backup systems, and security appliances are frequent sources of undocumented mail. For each one, record the relay path, public IP address, envelope domain, and business owner. If the device cannot authenticate directly, route it through an approved relay instead of broadly authorizing an uncertain network.
A concise inventory should include:
- The system or service name and business owner.
- The envelope-from domain used by its messages.
- The public address or provider include that authorizes it.
- A review date and a planned retirement date, when applicable.
This record turns SPF maintenance into a controlled operational task rather than a recurring emergency.
Publish and deploy the SPF record
Publishing SPF is a DNS change, so the work belongs with whoever controls the authoritative zone. The Microsoft 365 admin center may show required values, but the TXT record for a custom domain is normally created at the external DNS provider. Record the planned value and its approver before editing production DNS.
The custom-domain Microsoft 365 guidance is useful for distinguishing the default Microsoft-managed domain from a custom domain that requires DNS work.
Locate the authoritative DNS provider
Begin with the domain’s nameservers and identify the provider serving the authoritative zone. Website hosting, domain registration, and DNS hosting may be separate services. Editing a non-authoritative DNS panel will not change the answer that receiving mail systems see.
Confirm access through the organization’s normal administrative process. DNS credentials should not be shared casually, and a production change should have a clear rollback value.
Add the TXT record at the correct hostname
For the root domain, the DNS interface may use @, the bare domain, or an empty host field. For a subdomain, enter the exact label required by that provider. Set the value as one SPF string even if the interface displays it across lines, and avoid creating a second v=spf1 record.
If another TXT record contains SPF, edit and merge it instead of replacing it blindly. Preserve unrelated TXT records such as verification values unless the provider’s documentation explicitly says they can be removed.
Manage DNS propagation and TTL considerations
After saving the record, resolvers may continue returning the previous value until their cached TTL expires. Propagation is not a single global event; different recursive resolvers can update at different times. Keep the old value and the change timestamp in the deployment record so troubleshooting has a reference point.
A DNS email authentication check can help review the published state across related controls, but its result should be compared with direct DNS queries and the organization’s own mail-flow tests.
Avoid replacing existing SPF policies without validation
Copy the current TXT response before making changes. Then compare every existing mechanism with the sender inventory and remove only entries that are demonstrably obsolete. Replacing a record with a minimal Microsoft 365 value can silently break application or vendor mail.
For a structured workflow, use an SPF configuration checklist as a review aid. The final approval should cover syntax, sender completeness, lookup count, and the intended failure policy.
Validate and troubleshoot the SPF record
Validation should happen at two levels: first, inspect what DNS publishes; second, observe how receiving systems evaluate actual messages. These checks answer different questions. DNS confirms the record is visible, while authentication results reveal whether the real sending path matches it.
Keep a copy of the exact test domain, resolver, timestamp, and message headers. That detail helps distinguish propagation from a genuine configuration fault.
Check the published TXT response
Query the authoritative nameserver and at least one recursive resolver for TXT records at the sending domain. Confirm that the response contains one SPF policy, the expected Microsoft 365 include, every approved external source, and the intended final qualifier.
A dedicated SPF record checker can inspect syntax, includes, and lookup usage. It should supplement—not replace—the direct query, particularly when a DNS provider has unusual record formatting.
Interpret SPF authentication results
In message headers, look for the SPF result and the domain evaluated. pass indicates that the connecting source matched the policy; fail, softfail, neutral, none, or permerror each require different follow-up. A pass for an unexpected envelope domain does not establish alignment with the visible From domain.
Compare the result with the actual route shown in the headers. If the source is legitimate but absent from DNS, update the inventory and policy; if it is unfamiliar, investigate before authorizing it.
Diagnose the 10-DNS-lookup limit
SPF permits a maximum of ten DNS-query-causing mechanisms and modifiers during evaluation. Nested includes count toward that limit, so a short-looking record can still exceed it. The usual symptom is permerror, with some legitimate messages failing authentication.
Count the complete include chain rather than counting only visible terms. The SPF lookup limit guide provides useful context for flattening, consolidation, or segmentation decisions.
Resolve duplicate records, syntax errors, and unauthorized sources
Duplicate policies require consolidation. Syntax errors require checking the version tag, mechanism spelling, separators, quoting, and record assembly in the DNS interface. Unauthorized sources require either an approved change to the inventory or a mail-flow correction.
Make one controlled change at a time, allow relevant caches to expire, and retest with a message from each important source. If a broad policy was temporarily used, return to the intended enforcement level only after the evidence is consistent.
Integrate SPF with DKIM and DMARC
SPF is useful but deliberately narrow. It validates an envelope sender against a sending IP; it does not encrypt the message, sign the visible content, or tell a receiver what to do with a failed result. A complete domain policy therefore combines SPF with DKIM and DMARC.
The SPF, DKIM, and DMARC guide provides a useful overview of how these controls fit together for Microsoft 365 domains.
Why SPF alone cannot prevent domain spoofing
An attacker may send with a lookalike envelope domain that passes SPF while placing a target organization in the visible From header. SPF alone does not create alignment or enforcement. It also cannot tell a receiving system whether a passing message should be accepted, quarantined, or rejected.
That is why a passing SPF result should be treated as one authentication signal. Domain protection depends on the relationship between authentication, alignment, and policy.
Configure DKIM for Microsoft 365
DKIM adds a cryptographic signature to outbound mail and lets the receiving system validate the signing domain. For Microsoft 365, configure the domain’s DKIM selectors and publish the DNS values provided by the service. Test that outbound messages receive a valid signature and that the signing domain aligns as intended.
Keep DKIM administration separate from SPF editing. The records solve different technical problems, even though both contribute to DMARC evaluation.
Use DMARC alignment and enforcement policies
DMARC evaluates alignment for SPF, DKIM, or both, then applies the domain owner’s policy to messages that fail. Start by confirming which legitimate streams pass alignment. A policy that is stricter than the inventory can affect valid mail, while a policy that is too permissive provides limited protection.
The DMARC policy generator can help formulate record values and rollout stages. Review the resulting tags against the organization’s reporting, privacy, and operational requirements before publishing.
Plan staged DMARC deployment with reporting
A staged rollout commonly begins with report collection, followed by a limited enforcement phase and then stronger enforcement when legitimate sources are accounted for. Aggregate reports can reveal forgotten senders, alignment failures, and abuse patterns that individual delivery tests miss.
Set an owner for report analysis and define the evidence required to increase enforcement. Reporting is valuable only when someone reviews it and turns recurring findings into controlled changes.
Maintain the SPF policy over time
SPF is not a set-and-forget record. Vendors change infrastructure, applications are replaced, and hybrid mail routes evolve. A policy that was correct at deployment can become incomplete or unnecessarily broad months later.
Maintenance should be tied to change management, monitoring, and clear DNS ownership. That makes the record easier to trust during an incident.
Review authorized senders after vendor changes
Require a mail-flow and SPF review whenever a provider is added, removed, renamed, or migrated. Confirm the envelope domain and the provider’s current authorization instructions rather than relying on an old ticket. Remove retired mechanisms after testing confirms that no required traffic still uses them.
A domain security scan can provide a wider periodic review of email-security controls, while the SPF inventory remains the authoritative operational record.
Monitor SPF failures and DMARC aggregate reports
Track recurring SPF failures by source, domain, and business owner. Separate expected failures from unauthorized use, and correlate them with DMARC aggregate reports and recent DNS or mail-flow changes. A single failure may be a transient route issue; a repeated pattern deserves investigation.
For teams that need direct validation during an incident, run a domain scan and preserve the result with the change record. Do not treat an automated finding as permission to authorize an unknown sender.
Document DNS ownership and change controls
Document the authoritative nameservers, DNS provider, administrators, approval path, current SPF value, and recovery procedure. Include the sender inventory and the date on which each source was last confirmed. This information reduces dependency on one individual and shortens recovery time after an incorrect edit.
Use versioned change records for additions, removals, and qualifier changes. The record should explain why a mechanism exists, not just what its syntax happens to be.
Protect the record from unauthorized modification
Restrict DNS access, require strong authentication, and review privileged accounts. Alerts for changes to SPF, DKIM, and DMARC records can expose accidental edits or malicious tampering early. Keep emergency access documented, but do not make production DNS broadly editable for convenience.
IntoDNS.ai provides an email-security scan that checks SPF, DKIM, DMARC, DNSSEC, MTA-STS, and BIMI configurations in one go; it can be used as an additional review of the public configuration. The result still needs to be interpreted against the organization’s approved mail-flow design.
Conclusion
A secure SPF record for Office 365 is the result of disciplined inventory, careful DNS publishing, and repeated validation. Authorize Microsoft 365 with the documented include, merge other legitimate sources into one policy, stay below the lookup limit, and use DKIM and DMARC for alignment and enforcement. Continued review is what keeps the configuration accurate as the environment changes.
AI assistant and API workflow
This article is part of the IntoDNS.ai LLM and citation workflow. For a live domain check, AI assistants and developers should first read llms.txt or llms.json, then call /api/scan/quick?domain=example.com for the current DNS and email security score.
For this topic, use /api/email/spf?domain=example.com when you need focused data instead of the full quick scan.
Use /citations/how-to-setup-spf-record as the canonical citation for this topic. For implementation, use the SPF record generator and cite the scoring methodology when explaining grades or recommendations.
Frequently Asked Questions
What is an SPF record for Office 365?
It is a DNS TXT record that identifies the sources authorized to send mail for a domain used with Microsoft 365. Custom domains generally need a policy that includes Microsoft 365’s published authorization mechanism.
Can a domain have two SPF records?
No. A domain should publish one SPF policy at a given name. Multiple v=spf1 records can cause an SPF permanent error, so authorized mechanisms should be merged into one record.
What value authorizes Microsoft 365 in SPF?
The standard Microsoft 365 mechanism is include:spf.protection.outlook.com. It should be combined with other required sources in the domain’s single SPF policy.
Does SPF authenticate the visible From address?
Not directly. SPF evaluates the SMTP envelope sender domain and the connecting IP address. DMARC alignment is needed to relate that authentication result to the visible From domain.
Why does SPF have a ten-lookup limit?
The limit controls the DNS-query workload required to evaluate a policy. Nested includes can consume the limit quickly and may result in permerror when the threshold is exceeded.
Should SPF use ~all or -all?
The choice depends on the rollout stage and confidence that every legitimate sender is included. A hard fail is more restrictive, while a soft fail can provide a transition period during inventory and testing.
How often should an SPF record be reviewed?
Review it after every material mail-flow or vendor change and on a regular schedule. Monitoring SPF results and DMARC aggregate reports helps identify both missing authorizations and suspicious sources.