Postfix中继报错‘mail for example.com loops back to myself’问题排查求助
Hey Tarik, let's break down why you're hitting this "mail loops back to myself" error with your Postfix relay on Ubuntu 22.04. After going through your config and DNS records, I can spot the key issues and how to fix them.
What's Causing the Loop?
Postfix thinks it's the final delivery server for example.com
In yourmain.cf, themydestinationparameter includesexample.com:mydestination = $myhostname, localhost.$mydomain, localhost, example.comThis setting tells Postfix, "I'm the end server responsible for delivering mail to example.com." When external emails come in for your corporate example.com addresses, they hit your Postfix server first (thanks to your MX record priority), and Postfix tries to deliver them locally. But since you don't have those Google Workspace accounts set up on this server, it gets stuck and throws the loop error—it knows it should handle the mail, but can't, so it assumes there's a routing loop.
MX record priority is misaligned
Your example.com MX records listmail.example.comwith priority 1, which is higher (lower number) than all Google's MX entries. That means every email sent to example.com will route to your Postfix server first, instead of going directly to Google Workspace where your actual mailboxes live. This creates a conflict between what Postfix is configured to do and where the mail should actually be delivered.
How to Fix It
Follow these steps to resolve the issue:
Update your Postfix
mydestinationconfig
Edit/etc/postfix/main.cfand removeexample.comfrom themydestinationline. It should look like this:mydestination = $myhostname, localhost.$mydomain, localhostThis tells Postfix it's not responsible for delivering mail to example.com, so it will forward those emails to the correct MX servers (Google's) instead of trying local delivery.
Adjust your MX record priorities (recommended)
Since your Postfix server is only meant for outgoing relay (not receiving incoming mail for example.com), you should either:- Set Google's MX records to have a higher priority (lower number) than
mail.example.com(e.g., setaspmx.l.google.comto priority 1, andmail.example.comto priority 20), or - Remove the
mail.example.comMX record entirely if you don't need it for any incoming mail tasks.
This ensures external emails go straight to Google Workspace instead of hitting your relay first.
- Set Google's MX records to have a higher priority (lower number) than
Restart Postfix to apply changes
Run this command to reload the new configuration:sudo systemctl restart postfix
Quick Verification Steps
- Check that your
mydestinationchange took effect:postconf -n | grep mydestination - Verify your MX records with:
dig example.com MX
Once you make these changes, incoming mail to your corporate example.com addresses should route correctly to Google Workspace, and the loop error should disappear.
备注:内容来源于stack exchange,提问作者Tarik

