Using gue's and Bob Eager's answer, I figured out that the following setting in
/etc/postfix/main.cf also does the job (on an Ubuntu 18.04 machine):
# appending .domain is the MUA's job.
# append_dot_mydomain = no # --> this is the default setting
append_dot_mydomain = yes # --> Setting it to yes appends the domain to the hostname
It also explains what gue said: appending the .domain is the Mail User Agent's job.
By setting it to
yes we are overriding this.
So, my setup is :
append_dot_mydomain = yes
myorigin = /etc/mailname
Still, it doesn't feel like the right way; after all by setting it to
yes we are violating the principle that "appending the .domain is the Mail User Agent's job"
Furthermore, I am not sure why I need to configure it this way to make it work. I have another server (configured by someone else; a Debian 8.11 machine), which does append the domain after the hostname correctly, even with
/etc/mailname being set to the domain, and with
append_dot_mydomain=no. And on that server it works both for
mailx and for mails sent by e.g. logcheck