How to Fix Mail Looping Between On-Premises Exchange and Exchange Online
Question details
The user needs to resolve an issue where emails sent to Exchange Online mailboxes are repeatedly routed back to the on-premises Exchange server, resulting in a mail loop.

- Product
- Microsoft Exchange
- Device & OS
- not provided
- Scenario
- Configuring or troubleshooting hybrid mail flow and outbound connectors between local servers and the cloud.
- Observed behavior
- Messages continuously bounce back and forth between environments until delivery fails with a 'Hop count exceeded - possible mail loop detected' error.
Verify that the affected Exchange Online mailbox is fully active, properly licensed, and not configured with an accidental forwarding rule before altering your global transport rules.
Verify Exchange Online Outbound Connector Settings
Use this solution to ensure that the outbound connector in Exchange Online is not mistakenly routing all cloud-destined messages back to your on-premises environment.
In a hybrid environment, an improperly configured outbound connector can force mail destined for Exchange Online back to the on-premises gateway. If the gateway doesn't recognize the cloud recipient, it sends it back to Exchange Online, creating an infinite loop.
Log into the Microsoft 365 Exchange admin center and navigate to the 'Mail flow' section, then click on 'Connectors'.
Select the connector responsible for routing mail from Microsoft 365 to your organization's email server.
Verify if 'RouteAllMessagesViaOnPremises' is set to True. If it is enabled, ensure your local gateway or SmartHost is configured to recognize Exchange Online recipients and route them to the cloud rather than returning them to on-premises Exchange.

Check Recipient Object Attributes and Forwarding
Use this solution to confirm that the recipient's mailbox attributes and domain types are correctly identifying the mailbox as a cloud resource.
Run an Extended Message Trace
Use this solution to track the exact path of the email and identify which specific server or gateway is bouncing the message back.
Analyze Message Trace Reports Easily with WPS Office
Troubleshooting complex Exchange environments often requires reading extensive CSV files generated by extended message traces. WPS Office provides a lightweight, highly compatible, and free alternative to Microsoft Office, perfect for IT administrators who need a reliable spreadsheet tool without the heavy subscription costs.
- 1. Download the Installer: Visit the official WPS Office website and download the free installation package for your operating system.
- 2. Install WPS Office: Run the installer and follow the on-screen prompts to set up the lightweight productivity suite on your workstation.
- 3. Open CSV Trace Files: Launch WPS Spreadsheet and open your extended message trace CSV files to seamlessly filter and analyze server hop data.

Frequently Asked Questions
What causes the 'Hop count exceeded - possible mail loop detected' error in Exchange?
This error occurs when an email message bounces between servers too many times without reaching its final destination. In hybrid environments, it typically happens when Exchange Online sends an email to an on-premises server, and the on-premises server (or its gateway) routes it right back to Exchange Online due to misconfigured connectors or recipient settings.
How do I find out which server is causing the mail loop?
You can identify the source by running an Extended Message Trace in the Exchange admin center. By downloading the trace as a CSV file, you can inspect each server hop and see exactly which local gateway or cloud connector is making the incorrect routing decision.
Does RouteAllMessagesViaOnPremises always cause mail loops?
No, 'RouteAllMessagesViaOnPremises' is a legitimate setting for organizations that require all outbound cloud mail to be filtered or archived locally. However, if your local email gateway is not configured to recognize that the target mailbox actually resides in Exchange Online, it will bounce the message back to the cloud, creating a loop.




