This page shows how to place iBlockSpam in front of Exchange Online so that internet mail reaches the filtering service first and only clean mail is delivered to Microsoft 365. It follows Microsoft's documented pattern for an MX record that points to a non-Microsoft filtering service (Microsoft Learn: Manage mail flow using a third-party cloud service).
Throughout this page, placeholders stand in for values that are specific to your account:
<GATEWAY-MX-HOSTS>: the MX hostnames for your domain.<GATEWAY-IP-RANGES>: the IP ranges the filtering service uses to deliver mail to you.<GATEWAY-TLS-CERT-NAME>: the certificate subject name the filtering service presents over TLS.
The iBlockSpam setup wizard shows your exact values, a before/after DNS comparison and the rollback steps for your domain. Copy values from the wizard, not from examples.
Prerequisites
- Your domain is verified and Healthy in the Microsoft 365 admin center (Settings > Domains).
- An account with the Exchange Administrator role (or Organization Management in Exchange Online). Microsoft recommends least privilege, so avoid Global Administrator where you can.
- Access to your DNS host to change MX records.
- The Exchange Online PowerShell module if you prefer PowerShell (Connect to Exchange Online PowerShell).
- Your tenant's MX endpoint, for example
contoso-com.mail.protection.outlook.com. Find it under Settings > Domains > your domain > DNS records in the Microsoft 365 admin center. iBlockSpam delivers clean mail to this host. - A list of anything that sends mail straight into your tenant on port 25 (scanners, line-of-business apps, other services). These need a plan before you lock the connector down.
Step by step
These are the iBlockSpam-specific steps. For the background on connectors and why Enhanced Filtering matters with any third-party filter, read our Microsoft 365 Enhanced Filtering setup guide.
-
Add your domain in iBlockSpam. Enter the domain and your Microsoft 365 MX endpoint as the delivery destination. The wizard confirms that the filtering service can deliver to it.
-
Lower the MX TTL. At your DNS host, set the TTL of your current MX records to 300 seconds (5 minutes) at least one full old-TTL period before the cutover, so the change spreads quickly and can be undone quickly.
-
Create the Partner inbound connector, without restrictions yet. In the Exchange admin center at
https://admin.cloud.microsoft/exchange#/connectors, go to Mail flow > Connectors > + Add a connector:- Connection from: Partner organization (Connection to is fixed to Office 365).
- Name: for example
iBlockSpam inbound. - Authenticating sent email: By verifying that the sender domain matches one of the following domains, and enter
*(all sender domains). - Security restrictions: select Reject email messages if they aren't sent over TLS. Leave the certificate and IP-range restrictions unchecked for now.
- Select Create connector.
PowerShell equivalent:
New-InboundConnector -Name "iBlockSpam inbound" -ConnectorType Partner ` -SenderDomains * -RequireTls $true ` -SenderIpAddresses <GATEWAY-IP-RANGES> -
Turn on Enhanced Filtering for Connectors. In the Microsoft Defender portal, go to Email & collaboration > Policies & rules > Threat policies > Rules > Enhanced filtering (direct link:
https://security.microsoft.com/skiplisting). Select the connector and choose Skip these IP addresses that are associated with the connector, then enter<GATEWAY-IP-RANGES>. Microsoft also offers Automatically detect and skip the last IP address, which suits a single hop. Start with Apply to a small set of users if you want a pilot, then switch to Apply to entire organization. (Microsoft Learn: Enhanced Filtering for Connectors)Set-InboundConnector -Identity "iBlockSpam inbound" ` -EFSkipLastIP $false -EFSkipIPs <GATEWAY-IP-RANGES> # Pilot on named recipients first (list every proxy address you want covered): # Set-InboundConnector -Identity "iBlockSpam inbound" -EFUsers "pilot1@example.com","pilot2@example.com"Note that IPv6 ranges can only be set in PowerShell, and private or Microsoft 365 IPs are not accepted.
-
Change the MX record. Replace your Microsoft 365 MX record with
<GATEWAY-MX-HOSTS>and the priorities the wizard shows. Do not keep the Microsoft MX as a lower-priority backup: sending servers may use any listed MX (RFC 5321, section 5.1), and spammers often target the backup on purpose. -
Watch the change spread. Use the MX Lookup tool and send test messages from an outside mailbox. Mail may arrive by both paths while resolvers expire the old record. This is expected.
-
Lock the connector to the filtering service. After the old TTL has expired and you see mail arriving through iBlockSpam, restrict the connector so that mail sent straight to
*.mail.protection.outlook.comis rejected. Microsoft prefers the certificate method:# Preferred: certificate Set-InboundConnector -Identity "iBlockSpam inbound" ` -TlsSenderCertificateName <GATEWAY-TLS-CERT-NAME> ` -RestrictDomainsToCertificate $true -RequireTls $true # Alternative: IP ranges Set-InboundConnector -Identity "iBlockSpam inbound" ` -SenderIpAddresses <GATEWAY-IP-RANGES> ` -RestrictDomainsToIPAddresses $trueIn the Exchange admin center, these correspond to And require that the subject name of the certificate that the partner uses to authenticate with Office 365 matches this domain name and Reject email messages if they aren't sent from within this IP address range on the Security restrictions page.
-
Remove spam-bypass rules. If you have any mail flow rule that sets SCL to -1 for the gateway, disable it. Microsoft says SCL -1 is "an input to filtering, not a final decision" and recommends Enhanced Filtering instead.
-
Optional: reject Direct Send from your own domain.
Set-OrganizationConfig -RejectDirectSend $truerejects unauthenticated messages that use your accepted domains as the sender and are delivered straight to your tenant. It complements the connector lockdown; it does not replace it.
How to verify
Open a test message from an outside sender in Outlook (File > Properties > Internet headers), or paste the headers into the Email Header Analyzer, which runs in your browser. Check:
- Received lines: the hop before Microsoft 365 should be the filtering service.
- X-MS-Exchange-SkipListedInternetSender and X-MS-Exchange-ExternalOriginalInternetSender: these show the true source address when Enhanced Filtering is working (Microsoft Learn).
- Authentication-Results: SPF should be evaluated against the original sender's IP, not the gateway's.
compauthreason905means DMARC was not enforced because of complex routing, which usually points to Enhanced Filtering not covering that message (Microsoft Learn: anti-spam headers). - X-Forefront-Antispam-Report:
SFV:SKNmeans a mail flow rule bypassed filtering. You should not see it after step 8.
Then test the lockdown: send a message straight to your *.mail.protection.outlook.com host from a server that is not the gateway. It should be rejected with a 5.7.51 TenantInboundAttribution error.
Rollback
Order matters. If you reverse the MX first, the locked connector will reject internet mail that now arrives directly.
- Remove the restriction:
Set-InboundConnector -Identity "iBlockSpam inbound" -RestrictDomainsToCertificate $false -RestrictDomainsToIPAddresses $false. - Change the MX back to your Microsoft 365 endpoint, with a short TTL.
- Keep the iBlockSpam domain active until the old MX TTL has expired, so mail still arriving through the gateway is delivered.
- Turn off Enhanced Filtering (
-EFSkipLastIP $false -EFSkipIPs $null), then disable or remove the connector.
Common mistakes
- Locking the connector before the MX change has spread. Mail still routed directly is rejected.
- Leaving Microsoft's MX as a backup. It gives spammers a route around the filter.
- Enhanced Filtering on the wrong connector, or for a small set of users only. When piloting, Enhanced Filtering applies only if every recipient of the message is listed, including all proxy addresses.
- Keeping an SCL -1 rule. It disables most of Microsoft's protections for everything from shared gateway IPs.
- Forgetting Direct Send senders. Scanners and apps that deliver straight to the tenant stop working once the connector is restricted.
- Changing SPF when you don't need to. Inbound filtering doesn't touch your SPF record. If you're checking it anyway, our Microsoft 365 SPF record page shows the exact include Microsoft documents and its lookup cost.
- Double link rewriting. Microsoft advises against two services rewriting the same links (Microsoft Learn: integrate non-Microsoft security services).
Limits
- Each domain includes 100,000 inbound messages per month and accepts messages up to 400 MB. Exchange Online applies its own message size limits, so the smaller limit wins.
- Unlimited mailboxes means any number of mailboxes per domain. It does not mean unlimited message volume.
- If Microsoft 365 is unavailable, mail is spooled for up to 5 days. Message history is kept for 30 days.
- An MX lookup shows where mail should go. It can't prove that mail is filtered, and it doesn't show whether your tenant still accepts direct delivery. Use the header and lockdown tests above.
Do you need a gateway?
Microsoft's own protection is capable, and a gateway isn't right for every tenant. Read Microsoft 365 built-in filtering vs a gateway and Defender for Office 365 vs a gateway before you decide. Stuck on a step? Our support page lists what to send so we can trace mail quickly.
Frequently asked questions
Do I still need Exchange Online Protection or Defender for Office 365?
They stay on. Microsoft 365 always scans inbound mail. With Enhanced Filtering for Connectors enabled, its anti-spoofing and authentication checks work on the original sender instead of on the gateway, so the two layers complement each other.
Should I create a mail flow rule that sets SCL to -1?
Microsoft recommends Enhanced Filtering for Connectors instead, and says to disable SCL -1 rules once Enhanced Filtering is on. Filtering services share IP addresses across customers, so an SCL -1 bypass on those IPs can let spoofed mail through.
Will locking down the connector break mail from apps or scanners?
It can. A Partner connector restricted to the gateway's IPs or certificate rejects anything delivered straight to your tenant, including devices using Direct Send. Move those senders to authenticated SMTP submission or their own connector before you turn the restriction on.
Do I need to add iBlockSpam to SPF for Microsoft 365?
Not for inbound filtering. Your SPF record describes who sends mail for your domain. Add iBlockSpam to SPF only if you route outbound mail through the iBlockSpam outbound relay.
Can I pilot Enhanced Filtering on a few users first?
Yes. Microsoft lets you apply Enhanced Filtering for Connectors to a small set of users before the whole organization. List every email address of each pilot user, because the setting applies only when all recipients of a message are on the list.
Related guides
How to use an external spam filter with Microsoft 365 and Enhanced Filtering for Connectors
How to run an MX-level spam filter in front of Exchange Online: Partner connector, Enhanced Filtering for Connectors, why not SCL -1, headers and rollback.
10 min read Running email day to dayHow to stop spammers bypassing your filter by delivering straight to your mail server
Spammers can skip your MX and deliver straight to Microsoft 365, Google Workspace or your server. Lock each one to your filter, test it, roll back.
9 min read Running email day to dayWhy is spam getting through the Microsoft 365 spam filter, and how do you fix it?
Why spam reaches Microsoft 365 inboxes: allow lists, SCL -1 rules, weak policies, Direct Send. How to find the cause in headers and fix it step by step.
9 min readLast updated: