Mail for "domain" loops back to myself

SYSTEM INFORMATION
OS type and version debian 13
Webmin version 2.610
Virtualmin version 7.50.2 GPL

Hello,
I am unable to send emails from my server to adresses @mydomain.com. I have this postfix message :

status=bounced (mail for mydomain.com loops back to myself)

/etc/hostname → mydomain.com
I don’t have any domain configured with “mail for domain”
And in postfix configuration I set
What domains to receive mail for → localhost
I thought that would be enough
What is wrong ?
Thanks

mydomain.com should exist in virtualmin and have “mail for domain” enabled.

I don’t want to receive mail on my server. I just want to send mail, no receiving. So postfix should deliver externally.
I can send to other emails adresses without error, even to adresses with domain name belonging to virtualmin domains without “mail for domain”.
Just this one domainname fails because this is my hostname.
How to tell postfix to not deliver locally ?

you’ve got me confused. you’re sending from your domain (local) to your domain (local), without it being enabled for “mail”… so bounce is normal.
did you try to send externally to “externaldomain.com” ?

Yes I can send to any domain, except my hostname domain.
So there should be a setting in postfix to force it to send mail externally even for local domain…

yes there are maps for that. but where is the real domain destination? MX record for mydomain.com?

it’s at OVH :
mx0.ovh.net

The hostname should not be the same as a virtual server.

Don’t change that.

Your MX record is, I guess, wrong? MX record decides where mail is supposed to be delivered. Postfix believes the server itself is supposed to receive mail for your domain.

If you have DNS enabled on the system, but it’s not actually authoritative for your zone, that could lead to the server itself thinking the MX record is itself…so, disable the DNS feature if you’re not actually hosting DNS locally.

But, also, don’t name your server the same thing as a name you’re hosting in Virtualmin. This wouldn’t usually matter if you’re not receiving mail, but you have something else wrong…so Postfix is trying to deliver locally.

I thought the DNS system on Virtualmin servers was not setup to do Local lookups and performed all lookups externally. I appreciate that at some point the authoritative DNS request chain comes back to the server (when appropriate) and that DNS requests can be cached.

I know cpanel does internal lookups for email by default. It enumerates all of the domains on the server and if the target domain is listed it will get delivered there unless you change the option as below.

I am not sure if there is an equivalent feature in virtualmin/webmin. I thought I did a request for this but I cannot find it, so maybe I didn’t

Ok I disabled DNS completely on my server. I don’t know if this is because of other changes I made, or because I disabled DNS? but now I get this error when I try to send mail to mydomain :

Dec 13 09:27:01 mydomain.eu postfix/local[1638819]: AB3C96894B: to=<logs@mydomain.eu>, relay=local, delay=0.08, delays=0.07/0.01/0/0.01, dsn=5.1.1, status=bounced (unknown user: "logs")

I have no “mail for domain” enabled, so I don’t understand this error

Can I use host.mydomain.eu as my server name, and host mydomain.eu in virtualmin ?

Yep that fine. I normaily call my server server.domainname.com and then I can use domainname.com as a virtual server.

Ok, so now I have “server.mydomain.eu” as my hostname but I still cannot send mail to logs@mydomain.eu externally from my own server. This adress works fine otherwise.
I still have this postfix error :
"Dec 13 09:27:01 mydomain.eu postfix/local[1638819]: AB3C96894B: to=<logs@mydomain.eu>, relay=local, delay=0.08, delays=0.07/0.01/0/0.01, dsn=5.1.1, status=bounced (unknown user: "logs")

Postfix still believes it is the mail server for your domain. So, find why that is and change it. /etc/mailname (this is a dumb misfeature of Debian/Ubuntu, but you picked an OS, so you’ve gotta live by its rules), maybe?

Actually, changing my hostname to server.mydomain.eu is really not what I want.
This means changing the reverse DNS of my server, and now antispams complain my server does not have MX record, and I don’t want to handle mail on server.mydomain.eu.
I already have everything setup with mydomain.eu
This was working perfectly fine on my previous server (also with debian/webmin).
And everything else is working perfectly fine like that.
The only remaining issue is this postfix error I am trying to fix since the begining. ( Mail for “domain” loops back to myself )
How to tell postfix not to handle mails for my hostname ? Or how to tell postfix to not handle mail locally at all ?
This really should not be that complicated !
Thanks to anyone who can point me in the right direction without changing my entire server configuration.

I pointed you at it (probably): Mail for "domain" loops back to myself - #16 by Joe

What is in /etc/mailname?

But, also, why does the system hostname need to be something you’re virtually hosting? That doesn’t make sense. You can name the system literally anything other than things you’re virtually hosting, and avoid a wide variety of problems that come from having two things with the same name.

Because the system needs a domain name, and I chose the same one than one of my website.
And now that I’ve set everything up around this, including my emails which are quite a pain to configure to get good anti-spam scores, I’d rather not have to start all over again.