Postfix "too many hops" error when forwarding emails

I’ve encountered a problem after setting up email forwarding on a newly created domain in Virtualmin and am hoping for some insight.

Setup Details:

A new domain mydomain.com was created in Virtualmin.
A new email address test@mydomain.com was created.

I configured forwarding for this address to an external email: mail@paulsdomain.com (hosted on a different server).

Issue:

When I send an email to test@mydomain.com, it results in a high volume of emails being sent to mail@paulsdomain.com, and eventually, I see the following error in the mail log:

Error: too many hops (in reply to end of DATA command)

This suggests a mail loop, but I can’t find an obvious cause beyond the current configuration.

Relevant Config Files:

/etc/aliases:

test\@mydomain.com: mail@paulsdomain.com,\test\@mydomain.com

/etc/postfix/virtual:

test@mydomain.com test\@mydomain.com

There are no other errors in /var/log/mail.log besides the “too many hops” message.

Any help or suggestions would be greatly appreciated.

Thanks in advance!

SYSTEM INFORMATION
OS type and version Ubuntu 24.04 LTS
Webmin version 2.303
Virtualmin version 7.30.8
Webserver version 2.4.58-1ubuntu8.6
Postfix 3.8.6-1build2

That looks like it would cause a loop.
Maybe a bug? I’ll try and test later.

tested, that didn’t cause any loop.

Is your system named the same as this domain? (It should not be.) Or, have you modified mydomain, myorigin, mydestination, etc? (You probably should not.)

That’s usually why this happens.

This is the myorigin and mydestination settings in main.cf.

myorigin = /etc/mailname
mydestination = $myhostname, srv.mydomain.com, localhost.mydomain.com, localhost
# cat /etc/mailname
srv.mydomain.com

Looks quite ok to me.

What is your system hostname?

srv.mydomain.com is the system hostname

On my system myorigin is commented out and this is mydestination.

Have you edited the main.cf file?
That’s a real no no with virtualmin.
Is /etc/mailname a Ubuntu thing as I don’t have that file.

Don’t compare different OSes. It’s misleading.

We do not alter the way the OS does things like this. You should not expect a Virtualmin on Ubuntu system to look like a Virtualmin on EL system at the level of configuration files. We try very hard to use the OS as the OS developers intended.

1 Like

Just installed same OS with a spare domain I have and configuration looks the same as OP with a slight difference and I can’t see that causing a issue. 2 commas with a space between.
no loop issue.
If you remove the forward does test@mydomain.com receive emails ok?

Thank you everyone for your inputs and suggestions.

I’ve identified the issue—it was caused by a custom content filter we had implemented. The problem occurred specifically when sending an email from one server to another, both of which were running the same content filter service. Disabling the content filter resolved the issue, and the forwarding worked correctly.

I’ll now proceed to troubleshoot the content filter service in more detail.
Appreciate the help from the community in pointing me in the right direction!

2 Likes

you should have mentioned that in post 1, it may have saved some time