6

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 root@example.com.au. But the email is sent to root@host.example.com.au.

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            admin@example.com.au

/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 the from address to show my domain name instead of hostname but yet, the to 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 the masquerade_domains, but still cant get my head around why the user email is not respecting the same and the to address is still addressed as root@host.example.com.au instead of root@example.com.au.

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
Neel
  • 1,421
  • 7
  • 21
  • 35
  • If you haven't try it already: put `root: admin@example.com.au`in `/etc/aliases` file, run `newaliases` and see. – Diamond Jan 08 '16 at 13:32

3 Answers3

3

You need to put an alias for root in the /etc/aliases file like below, and then run newaliases and it should work.

root: admin@example.com.au

I have tested it and it works.

Diamond
  • 8,791
  • 3
  • 22
  • 37
  • Hi 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 using `newaliases`. It did not make any difference and the email to root user is still sent to root@hostname – Neel Jan 08 '16 at 13:45
  • I also tried adding the email to `virtual_alias_maps` and that didnt help neither. – Neel Jan 08 '16 at 13:47
  • Well, here is another alternative using `mail.rc` file. Set an alias there like: `alias root admin@example.com.au` in `/etc/mail.rc` file and see what happens. – Diamond Jan 08 '16 at 14:17
  • Hi 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 Jan 08 '16 at 17:06
  • @Neel, ok, then create an alias like this: `@host.example.com.au @example.com.au` in the `/etc/postfix/virtual` file, run `postmap` and then restart postfix and see. – Diamond Jan 08 '16 at 20:51
  • hi 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 Jan 08 '16 at 21:06
  • I can award the bounty in 13 hours – Neel Jan 08 '16 at 21:06
  • @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: http://www.postfix.org/postconf.5.html#mydestination – Diamond Jan 08 '16 at 22:04
2

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: root@example.com.au

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!

Neel
  • 1,421
  • 7
  • 21
  • 35
  • Thanks and also you need to add `masquerade_domains = $mydomain`. This was needed to get it working for my setup. – Ricky Boyce Jun 14 '17 at 15:14
-1

Can you give a shot and try to add the example.com.au to your hosts file? Reference: http://www.tldp.org/LDP/solrhe/Securing-Optimizing-Linux-RH-Edition-v1.3/chap9sec95.html

Lucas Carvalho
  • 531
  • 4
  • 10
  • Hi 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 of `11x.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? – Neel Jan 08 '16 at 19:47