Set up SPF in Office 365 to help prevent spoofing
Summary: This article describes how to update a Domain Name Service (DNS) record so that you can use Sender Policy Framework (SPF) with your custom domain in Office 365. Using SPF helps to validate outbound email sent from your custom domain.
In order to use a custom domain, Office 365 requires that you add a Sender Policy Framework (SPF) TXT record to your DNS record to help prevent spoofing. SPF identifies which mail servers are allowed to send mail on your behalf. Basically, SPF, along with DKIM, DMARC, and other technologies supported by Office 365 help prevent spoofing and phishing. SPF is added as a TXT record that is used by DNS to identify which mail servers can send mail on behalf of your custom domain. Recipient mail systems refer to the SPF TXT record to determine whether a message from your custom domain comes from an authorized messaging server.
For example, let's say that your custom domain contoso.com uses Office 365. You add an SPF TXT record that lists the Office 365 messaging servers as legitimate mail servers for your domain. When the receiving messaging server gets a message from email@example.com, the server looks up the SPF TXT record for contoso.com and finds out whether the message is valid. If the receiving server finds out that the message comes from a server other than the Office 365 messaging servers listed in the SPF record, the receiving mail server can choose to reject the message as spam.
Also, if your custom domain does not have an SPF TXT record, some receiving servers may reject the message outright. This is because the receiving server cannot validate that the message comes from an authorized messaging server.
If you've already set up mail for Office 365, then you have already included Microsoft's messaging servers in DNS as an SPF TXT record. However, there are some cases where you may need to update your SPF TXT record in DNS. For example:
Previously, you had to add a different SPF TXT record to your custom domain if you were using SharePoint Online. This is no longer required. This change should reduce the risk of SharePoint Online notification messages ending up in the Junk Email folder. Update your SPF TXT record if you are hitting the 10 lookup limit and receiving errors that say things like, "exceeded the lookup limit" and "too many hops".
If you have a hybrid environment with Office 365 and Exchange on-premises.
You intend to set up DKIM and DMARC (recommended).
Updating your SPF TXT record for Office 365
Before you update the TXT record in DNS, you need to gather some information and determine the format of the record. This will help prevent you from generating DNS errors. For advanced examples, a more detailed discussion about supported SPF syntax, see How SPF works to prevent spoofing and phishing in Office 365.
Gather this information:
The current SPF TXT record for your custom domain. For instructions, see Gather the information you need to create Office 365 DNS records.
IP addresses of all on-premises messaging servers. For example, 192.168.0.1.
Domain names to use for all third-party domains that you need to include in your SPF TXT record. Some bulk mail providers have set up subdomains to use for their customers. For example, the company MailChimp has set up servers.mcsv.net.
Determine what enforcement rule you want to use for your SPF TXT record. We recommend -all. For detailed information about other syntax options, see SPF TXT record syntax for Office 365.
To add or update your SPF TXT record
- If you have not already done so, form your SPF TXT record by using the syntax from the following table:
|If you're using...||Common for Office 365 customers?||Add this...|
||Any email system (required)
||Common. All SPF TXT records start with this value
||Exchange Online dedicated only
||ip4:184.108.40.206/19 ip4:220.127.116.11/19 ip4:18.104.22.168/16 include:spf.protection.outlook.com
||Office 365 Germany, Microsoft Cloud Germany only
||Third-party email system
Where domain name is the domain name of the third party email system.
||On-premises mail system. For example, Exchange Online Protection plus another mail system
||Use one of these for each additional mail system:
ip4:< IP address>
ip6:< IP address>
include:< domain name>
Where the value for < IP address> is the IP address of the other mail system and < domain name> is the domain name of the other mail system that sends mail on behalf of your domain.
||Any email system (required)
||Common. All SPF TXT records end with this value
||< enforcement rule>
This can be one of several values. We recommend that you use -all.
1.1 For example, if you are fully-hosted in Office 365, that is, you have no on-premises mail servers, your SPF TXT record would include rows 1, 2, and 7 and would look like this:
v=spf1 include:spf.protection.outlook.com -all
1.2 This is the most common Office 365 SPF TXT record. This record works for just about everyone, regardless of whether your Office 365 datacenter is located in the United States, or in Europe (including Germany), or in another location.
1.3 However, if you have purchased Office 365 Germany, part of Microsoft Cloud Germany, you should use the include statement from line 4 instead of line 2. For example, if you are fully-hosted in Office 365 Germany, that is, you have no on-premises mail servers, your SPF TXT record would include rows 1, 4, and 7 and would look like this:
v=spf1 include:spf.protection.outlook.de -all
1.4 If you are already deployed in Office 365 and have set up your SPF TXT records for your custom domain, and you are migrating to Office 365 Germany, you need to update your SPF TXT record. To do this, change include:spf.protection.outlook.com to include:spf.protection.outlook.de.
Once you have formed your SPF TXT record, you need to update the record in DNS. You can only have one SPF TXT record for a domain. If an SPF TXT record exists, instead of adding a new record, you need to update the existing record. Go to Create DNS records for Office 365, and then click the link for your DNS host.
Test your SPF TXT record.
More information about SPF
For advanced examples, a more detailed discussion about supported SPF syntax, spoofing, troubleshooting, and how Office 365 supports SPF, see How SPF works to prevent spoofing and phishing in Office 365.
Next steps: After you set up SPF for Office 365
Having trouble with your SPF TXT record? Read Troubleshooting: Best practices for SPF in Office 365.
SPF is designed to help prevent spoofing, but there are spoofing techniques that SPF cannot protect against. In order to protect against these, once you have set up SPF, you should also configure DKIM and DMARC for Office 365. To get started, see Use DKIM to validate outbound email sent from your custom domain in Office 365. Next, see Use DMARC to validate email in Office 365.
We'd love to hear your thoughts. Choose the type you'd like to provide:
Our feedback system is built on GitHub Issues. Read more on our blog.