Ubuntu – Postfix – hostname appearing in email address

hostnamepostfixUbuntu

I have a fresh install of postfix on Ubuntu 14.04 server but the test emails I have sent all include the hostname in the email address. I have searched and found quite a few people with the same problem but none of their solutions worked/applied to me. I have tried options from various tutorials but I don't seem to get the same results as they do.

My /etc/postfix/main.cf:

mydomain = example.com    
myorigin = example.com
smtpd_banner = $mydomain ESMTP $mail_name (Ubuntu)
biff = no 
append_dot_mydomain = no
readme_directory = no
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
smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination
myhostname = merlin.example.com
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
mydestination = $myhostname localhost.$mydomain localhost $mydomain
relayhost =
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = all
inet_protocols = all

My /etc/hosts file is:

127.0.0.1       localhost
XX.XX.XX.XX     merlin.example.com merlin

# The following lines are desirable for IPv6 capable hosts
::1     localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

An example received mail header is:

Delivered-To: xxx@gmail.com
Received: by 10.107.173.142 with SMTP id m14csp624755ioo;
Sun, 3 Apr 2016 01:12:36 -0700 (PDT)
X-Received: by 10.66.101.35 with SMTP id fd3mr43641306pab.7.1459671156649;
Sun, 03 Apr 2016 01:12:36 -0700 (PDT)
Return-Path: <user@merlin.example.com>
Received: from merlin.example.com (xxx-89-xx-64.xxx.xxx.xx.xx. [xxx.89.xx.64])
by mx.google.com with ESMTP id n69si18026934pfi.104.2016.04.03.01.12.36
for <xxx@gmail.com>;
Sun, 03 Apr 2016 01:12:36 -0700 (PDT)
Received-SPF: neutral (google.com: xxx.89.xx.64 is neither permitted nor denied by best guess record for domain of user@merlin.example.com) client-ip=xxx.89.xx.64;
Authentication-Results: mx.google.com;
spf=neutral (google.com: xxx.89.xx.64 is neither permitted nor denied by best guess record for domain of user@merlin.example.com) smtp.mailfrom=user@merlin.example.com
Received: by merlin.example.com (Postfix, from userid 1000)
id 02854601326; Sun,  3 Apr 2016 20:12:12 +1200 (NZST)

I can't see what is wrong in my setup and have changed as many options as I can think of based on looking at http://www.postfix.org/. I have restarted postfix after every change.

I would appreciate any suggestions 🙂

Best Answer

Excerpt from postfix help:

What domain name to use in outbound mail

The myorigin parameter specifies the domain that appears in mail that is posted on this machine. The default is to use the local machine name, $myhostname, which defaults to the name of the machine. Unless you are running a really small site, you probably want to change that into $mydomain, which defaults to the parent domain of the machine name.

For the sake of consistency between sender and recipient addresses, myorigin also specifies the domain name that is appended to an unqualified recipient address.

Examples (specify only one of the following):

/etc/postfix/main.cf:
    myorigin = $myhostname (default: send mail as "user@$myhostname")
    myorigin = $mydomain   (probably desirable: "user@$mydomain")