How to fix Mail Loops Back to Myself
Everytime I’ve come across Postfix, Qmail or Exim (or some derivative thereof) complaining that “Mail Loops Back to Myself” it’s always been the same thing.
If the next hop of an SMTP conversation the next relay step responds with the same mailname or hostname as the initial server it thinks it’s talking to itself.
In my humble opinion a better (and clearer) mail message would be “I appear to be sending email to myself and that will cause a loop, so instead I’m sending you the email back before I break myself”.
The example I’ve come across recently was like this (and highlighted with hindsight):
- Firewall had a rule that traffic from WAN (internet) to it’s IP address on port 25 got redirected to the internal IP of the Exchange server.
- Someone had (correctly I might add), added the FQDN of the WAN side IP address as the mailname for the Exchange box, something like mail.companya.com.
- At a later date the company had bought an email filtering appliance, and set up a rule on it to forward mail to the IP of the Exchange server and changed the firewall rule to send to the email filtering appliance as opposed to the Exchange server.
- The email filter then had the FQDN of the WAN side IP address as the mailname for the SMTP server.
- No mail could be delievered inbound or outbound and the famous “Mail Loops Back to Myself” message came up when attempting to send mail to companya.com.
The problem? Well both the Exchange server and the email filtering appliance both greeted each other with mail.companya.com, so there thought they were the same server.
The solution? Changing the hostname of the Exchange server fixed the problem instantly.