Postfix sends to FQDN Hostname instead of Domain Name
Solution 1
Finally got it working. These are the steps I did to resolve my trouble:
1) mydestination:
Since I had a send only mail server, I left mydestination
in main.cf
file empty as per the postfix man page. However, doing do ended up having the above behaviour were the local emails are sent with hostname appended which was getting bounced. Therefore I added $hostname
and localhost
as mydestination
in main.cf
like this:
mydestination = $myhostname, localhost
2) aliases:
Next, I added the email address for root user in /etc/aliases
like this:
root: [email protected]
3) newaliases:
Lastly, I rebuild aliases and reloaded postfix
sudo newaliases
sudo service postfix reload
What Fixed it:
Since aliases are used for local delivery only and I dont have local delivery (meaning $mydestination is empty), having the root email address in aliases didn't make any difference. Now after adding the $hostname
to my destination, any emails sent to a user which was getting appended with $hostname
is getting picked up as $mydestination
that is then referring to aliases
which ultimately tells postfix to deliver that email to another email address.
What I still dont understand is why the postfix was ignoring the $domainname
as myorigin
in the first place and kept adding hostname
suffix to user is still a mystery. However, the above method seem to be the solution when postfix is adamant to add hostname
to all mails addressed to the user directly.
Hope this helps!
Solution 2
You need to put an alias for root
in the /etc/aliases
file like below, and then run newaliases
and it should work.
root: [email protected]
I have tested it and it works.
Related videos on Youtube
Neel
Updated on September 18, 2022Comments
-
Neel almost 2 years
I have installed a send only postfix. Postfix works when I send a mail to a full email address. However, if a mail to sent to a user, it adds the FQDN name as the extension instead of just the domain name I have set-up during installation.
For example, when I send a mail from ssh like this:
echo "This will go into the body of the mail." | mail -s "Hello world" root
I want the mail to go to
[email protected]
. But the email is sent to[email protected]
.I have reviewed my host settings, mailname settings, postfix settings and I have no clue on why it keeps adding the full hostname to it which obviously is getting bounced. Here are my config files:
Postfix main.cf:
# Debian specific: Specifying a file name will cause the first # line of that file to be used as the name. The Debian default # is /etc/mailname. #myorigin = /etc/mailname smtpd_banner = $myhostname ESMTP $mail_name (Debian/GNU) biff = no # appending .domain is the MUA's job. append_dot_mydomain = no # Uncomment the next line to generate "delayed mail" warnings #delay_warning_time = 4h readme_directory = no # TLS parameters smtpd_tls_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem smtpd_tls_key_file=/etc/ssl/private/ssl-cert-snakeoil.key smtpd_use_tls=yes smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache # See /usr/share/doc/postfix/TLS_README.gz in the postfix-doc package for # information on enabling SSL in the smtp client. myhostname = host.example.com.au alias_maps = hash:/etc/aliases alias_database = hash:/etc/aliases myorigin = /etc/mailname mydestination = relayhost = mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128 mailbox_size_limit = 0 recipient_delimiter = + inet_interfaces = loopback-only virtual_alias_maps = hash:/etc/postfix/virtual
Aliases:
mailer-daemon: postmaster postmaster: root nobody: root hostmaster: root usenet: root news: root webmaster: root www: root ftp: root abuse: root noc: root security: root
/etc/postfix/virtual:
root [email protected]
/etc/mailname:
example.com.au
/etc/hosts:
127.0.0.1 localhost 11x.0.0.xxx host.example.com.au host
/etc/hostname
host
I have reviewed everything and I dont have a clue on why mail send to
@host.example.com.au
. Can someone help me here please?I am on debian 8.
EDIT: Just now, I tried adding one more setting to main.cf file:
masquerade_domains = $mydomain
. Adding this seems to fix thefrom
address to show my domain name instead of hostname but yet, theto
address is still having the FQDN name. I am receiving the bounced email "Mail Delivery System" notification on my email address since the origin email is now right after adding themasquerade_domains
, but still cant get my head around why the user email is not respecting the same and theto
address is still addressed as[email protected]
instead of[email protected]
.myhostname = host.example.com.au mydomain = example.com.au alias_maps = hash:/etc/aliases alias_database = hash:/etc/aliases myorigin = $mydomain masquerade_domains = $mydomain mydestination = relayhost = mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
-
Diamond over 8 yearsIf you haven't try it already: put
root: [email protected]
in/etc/aliases
file, runnewaliases
and see.
-
-
Neel over 8 yearsHi bangal thank you for your answer. Unfortunately that did not work. I did try that before although I forgot to add that edit to my question and I tried that once again now by adding email address for root in
aliases
and rebuilt usingnewaliases
. It did not make any difference and the email to root user is still sent to root@hostname -
Neel over 8 yearsI also tried adding the email to
virtual_alias_maps
and that didnt help neither. -
Diamond over 8 yearsWell, here is another alternative using
mail.rc
file. Set an alias there like:alias root [email protected]
in/etc/mail.rc
file and see what happens. -
Neel over 8 yearsHi bangal, I tried it but it didint work. I did not have
/etc/mail.rc
file so I created a new one and added the alias there. Still same results. Do you think it might be due to using postfix or mail in Debian 8? I dont know, I have the exact same set-up on Debian 7 and it works fine on that server. Still no clue here.. -
Neel over 8 yearsHi Lucas, but I already have added example.com.au to my hosts file similar to the referenced link. Host file code in included in my question. If you mean, I try adding
11x.0.0.xxx example.com.au host
instead of11x.0.0.xxx host.example.com.au host
then isint that wrong as the hosts should be in this order:ip FQDN Host
? Or did I misunderstand what you meant? -
Diamond over 8 years@Neel, ok, then create an alias like this:
@host.example.com.au @example.com.au
in the/etc/postfix/virtual
file, runpostmap
and then restart postfix and see. -
Neel over 8 yearshi bangal, thank you for your support with my trouble. I just tried a solution which worked for me for which I have added the answer. Your answer confirming that
/etc/aliases
has to work got me thinking and I found a workaround for this issue. Thank you so much for your help bangal. much appreciated! -
Neel over 8 yearsI can award the bounty in 13 hours
-
Diamond over 8 years@Neel, you are welcome! Glad that you could sort it out. I have missed that too. Actually postfix documentation on
mydestination
can explain the behaviour. Have a look at: postfix.org/postconf.5.html#mydestination -
Ricky Boyce about 7 yearsThanks and also you need to add
masquerade_domains = $mydomain
. This was needed to get it working for my setup.