Office 365 as MX Record

In this tutorial, you will learn how to configure Microsoft Office 365 with Email Security as its MX record.
- Go to the Anti-spam policies page ↗ > Select Edit connection filter policy.
- In Always allow messages from the following IP addresses or address range, add IP addresses and CIDR blocks mentioned in Egress IPs.
- Select Save.
- Microsoft recommends disabling SPF Hard fail when an email solution is placed in front of it:
- Return to the Anti-spam option ↗.
- Select Default anti-spam policy.
- Select Edit spam threshold and properties ↗ > Mark as spam > SPF record: hard fail, and ensure it is set to Off.
- Select Save.
- Set up a connector ↗.
- Select Partner organization under Connection from.
- Provide a name for the connector:
- Name:
Email Security Inbound Connector
- Description:
Inbound connector for Enhanced Filtering
- Name:
- Provide a name for the connector:
- In Authenticating sent email, select By verifying that the IP address of the sending server matches one of the following IP addresses, which belongs to your partner organization.
- Enter all of the egress IPs in the Egress IPs page.
- In Security restrictions, accept the default Reject email messages if they aren't sent over TLS setting.
Now that the inbound connector has been configured, you will need to enable the enhanced filtering configuration of the connector.
- Go to the Security admin console ↗, and enable enhanced filtering ↗.
- Select Automatically detect and skip the last IP address and Apply to entire organization.
- Select Save.
To configure anti-spam policies:
- Open the Microsoft 365 Defender console ↗.
- Go to Email & collaboration > Policies & rules.
- Select Threat policies.
- Under Policies, select Anti-spam.
- Select the Anti-spam inbound policy (Default) text (not the checkbox).
- In Actions, scroll down and select Edit actions.
- Set the following conditions and actions (you might need to scroll up or down to find them):
- Spam: Move messages to Junk Email folder.
- High confidence spam: Quarantine message.
- Select quarantine policy: AdminOnlyAccessPolicy.
- Phishing: Quarantine message.
- Select quarantine policy: AdminOnlyAccessPolicy.
- High confidence phishing: Quarantine message.
- Select quarantine policy: AdminOnlyAccessPolicy.
- Retain spam in quarantine for this many days: Default is 15 days. Email Security recommends 15-30 days.
- Select the spam actions in the above step:
- Select Save.
To create the transport rules that will send emails with certain dispositions to Email Security:
-
Open the new Exchange admin center ↗.
-
Go to Mail flow > Rules.
-
Select Add a Rule > Create a new rule.
-
Set the following rule conditions:
- Name: Email Security Deliver to Junk Email folder.
- Apply this rule if: The message headers > includes any of these words.
- Enter text:
X-CFEmailSecurity-Disposition
> Save. - Enter words:
SUSPICIOUS
,BULK
> Add > Save.
- Enter text:
- Apply this rule if: Select + to add a second condition.
- And: The sender > IP address is in any of these ranges or exactly matches > enter the egress IPs mentioned in Egress IPs.
- Do the following - Modify the message properties > Set the Spam Confidence Level (SCL) > 5.
-
Select Next.
-
You can use the default values on this screen. Select Next.
-
Review your settings and select Finish > Done.
-
Select the rule Email Security Deliver to Junk Email folder you have just created, and Enable.
-
Select Add a Rule > Create a new rule.
-
Set the following rule conditions:
- Name: .
- Apply this rule if: The message headers > includes any of these words.
- Enter text:
X-CFEmailSecurity-Disposition
> Save. - Enter words:
MALICIOUS
,UCE
,SPOOF
> Add > Save.
- Enter text:
- Apply this rule if: Select + to add a second condition.
- And: The sender > IP address is in any of these ranges or exactly matches > enter the egress IPs in the Egress IPs.
- Do the following: Redirect the message to > hosted quarantine.
-
Select Next.
-
You can use the default values on this screen. Select Next.
-
Review your settings and select Finish > Done.
-
Select the rule you have just created, and select Enable.
Now that you have completed the prerequisite steps, you can set up MX/Inline on the Cloudflare dashboard.
Was this helpful?
- Resources
- API
- New to Cloudflare?
- Products
- Sponsorships
- Open Source
- Support
- Help Center
- System Status
- Compliance
- GDPR
- Company
- cloudflare.com
- Our team
- Careers
- 2025 Cloudflare, Inc.
- Privacy Policy
- Terms of Use
- Report Security Issues
- Trademark