Yes, if your Exchange Hybrid server sends email directly to the internet, its public IP should be included in your SPF record. However, if all outbound mail is routed through Microsoft 365 or another smart host, you may not need to add it. The decision depends entirely on your mail flow architecture.
Background: What SPF Actually Does
SPF (Sender Policy Framework) is a DNS TXT record that lists which IP addresses or hostnames are authorized to send mail for your domain. When a receiving server gets a message, it checks the envelope sender domain against the SPF record. If the sending IP isn't listed, the message may be marked as spam or rejected outright.
In an Exchange Hybrid deployment, you have both on-premises Exchange servers and Microsoft 365. The SPF record needs to cover every server that can send mail with your domain in the envelope. Missing one legitimate sender is a common cause of delivery failures.
How Exchange Hybrid Mail Flow Works
In a typical hybrid setup, outbound mail from on-premises mailboxes can take one of two paths:
- Direct outbound: On-premises Exchange sends mail straight to the internet via its own public IP (often through a firewall or edge device).
- Centralized mail flow: On-premises Exchange routes all outbound mail to Microsoft 365, which then delivers it to the internet. This is the default when you run the Hybrid Configuration Wizard.
If you use centralized mail flow, your on-premises servers never talk directly to external recipients. In that case, the SPF record only needs to include Microsoft 365's published SPF entry (typically include:spf.protection.outlook.com) plus any other legitimate senders. Adding your public IP would be harmless but unnecessary.
If you send directly, your public IP must be in the SPF record. Otherwise, external mail servers will see your IP as unauthorized, and your messages will likely fail SPF checks.
How to Check Your Current Mail Flow
Before editing your SPF record, confirm which path your outbound mail takes. You can:
- Open the Exchange Management Shell on your on-premises server.
- Run
Get-SendConnector | Format-List Name,AddressSpaces,SourceTransportServersto see your send connectors. - Look for a connector with
AddressSpacesset toSMTP:*(all domains). If the smart host isoutlook.comor similar, you're using centralized flow. - If the connector has no smart host and points directly to MX records, you're sending directly.
You can also check your sent message headers. Look at the Received lines: if the first external hop is from Microsoft's IP range, you're centralized. If it's from your own public IP, you're direct.
When to Add Your Public IP to SPF
Add your public IP to SPF if any of these are true:
- You have a send connector that delivers directly to the internet without a smart host.
- You run a third-party gateway or relay that sends mail on behalf of your domain.
- You have a separate server (like a marketing tool) that sends from your domain.
If none of those apply, you don't need to add it. But adding it won't break anything as long as the IP is stable and not shared with spammers. A shared IP could cause your mail to be blacklisted if another tenant on that IP sends spam.
How to Update Your SPF Record Safely
SPF records have a 10-lookup limit. Each include and each a or mx mechanism counts toward that limit. Over the limit causes a permanent error, and SPF fails.
To add your public IP, edit your DNS TXT record for the domain. A typical record might look like:
v=spf1 include:spf.protection.outlook.com ip4:203.0.113.25 -all
Replace 203.0.113.25 with your actual public IP. Use -all (hard fail) if you're certain all senders are listed; use ~all (soft fail) if you're still testing. After updating DNS, wait for propagation (can be up to 48 hours, though usually faster) and test with a tool like MXToolbox or a manual email to a Gmail address.
If you have multiple on-premises servers with different public IPs, list them all as separate ip4 entries. Avoid using a if your IP is dynamic.
Common Problems and Misconceptions
One frequent mistake is adding the public IP but forgetting that your on-premises server may also send via a relay that has a different IP. Another is using +all or ?all which effectively disables SPF.
People often confuse SPF with DKIM or DMARC. SPF checks the envelope sender; DKIM uses a digital signature; DMARC ties them together. Even if you add the IP to SPF, you still need DKIM for best deliverability. Also, SPF fails when a message is forwarded because the forwarding server's IP isn't in the original sender's SPF record. That's normal and not something you can fix from your side.
Another misconception: adding your public IP to SPF will protect you from spoofing. It helps, but only if you also set up DMARC. Without DMARC, receiving servers may still accept spoofed mail that fails SPF.
Comparison: Direct vs. Centralized Mail Flow
Here's a quick comparison to help you decide:
- Direct flow: More control, but you must manage SPF, DKIM, and reputation for your own IP. You also need a static IP with proper PTR (reverse DNS) record.
- Centralized flow: Microsoft handles delivery and reputation. Your SPF record is simpler, and you don't need to worry about your IP's reputation. Downside: you lose some control and may have higher latency for large volumes.
Most small to medium organizations use centralized flow because it's simpler and more reliable. Large enterprises with compliance needs often use direct flow.
Safety and Testing Before You Change SPF
Before editing your SPF record, do the following:
- Back up your current TXT record.
- Use a SPF validation tool to check your current record's syntax and lookup count.
- Add the new IP and set
~alltemporarily to avoid hard failures if something is wrong. - Send test emails to external addresses and check headers for
spf=passorspf=softfail. - After 24-48 hours, if everything passes, switch to
-all.
Never add an IP that you don't control. If you use a dynamic IP, consider using a relay service instead.
Frequently Asked Questions
Will adding my public IP to SPF break email forwarding?
No, but forwarding can still cause SPF failures because the forwarding server's IP is not in your SPF record. That's a limitation of SPF. You can mitigate it by setting up DMARC and using ARC (Authenticated Received Chain) if your forwarder supports it.
What if I have multiple public IPs for different servers?
List each IP as a separate ip4 mechanism in the same SPF record. For example: ip4:203.0.113.1 ip4:203.0.113.2. Keep the total under 10 lookups.
Can I use a hostname instead of an IP in SPF?
Yes, you can use a:mail.example.com if that hostname resolves to your public IP. But using ip4 is more direct and avoids an extra DNS lookup.
How long does it take for SPF changes to take effect?
DNS propagation can take up to 48 hours, but often it's much faster. Use a tool like MXToolbox to check when the new record is visible globally.
Should I use -all or ~all?
Use -all if you are absolutely certain you have listed every legitimate sender. Otherwise, use ~all to avoid rejecting mail from servers you forgot. You can switch to -all later.