mx record server sending email back to webserver when webserver configured to use mx server to send

coderodour asked:

I have my webserver running a webmail client. I have this webmail client configured to use a seperate standalone mail server to send emails. I can send email from this webmail to gmail successfully.

However, upon trying to send email to an address on my own domain, I can see that I connect to the standalone server to send the email as the logs state:

Nov 12 12:47:46 mx dovecot: imap([email protected]): Disconnected: Logged out in=291 out=2751
Nov 12 12:48:46 mx dovecot: imap-login: Login: user=<[email protected]>, method=PLAIN, rip=192.168.1.11, lip=192.168.1.12, mpid=19294, TLS, session=<6pT3wzxd4QrAqAoM>
Nov 12 12:48:46 mx dovecot: imap([email protected]): Disconnected: Logged out in=291 out=2751

But instead of the mx server itself receiving the email like it does for incoming email from other domains, i.e gmail etc., the email seems to be received at the web server where the mail log displays:

Nov 12 12:27:12 myservername postfix/pickup[29249]: 3210A1020814: uid=56 from=<[email protected]>
Nov 12 12:27:12 myservername postfix/cleanup[29254]: 3210A1020814: message-id=<[email protected]>
Nov 12 12:27:12 myservername postfix/qmgr[29250]: 3210A1020814: from=<[email protected]>, size=532, nrcpt=1 (queue active)
Nov 12 12:27:12 myservername postfix/local[29256]: 3210A1020814: to=<[email protected]>, relay=local, delay=0.09, delays=0.06/0/0/0.03, dsn=5.1.1, status=bounced (unknown user: "sender")
Nov 12 12:27:12 myservername postfix/cleanup[29254]: 3F1291020816: message-id=<[email protected]>
Nov 12 12:27:12 myservername postfix/bounce[29257]: 3210A1020814: sender non-delivery notification: 3F1291020816
Nov 12 12:27:12 myservername postfix/qmgr[29250]: 3F1291020816: from=<>, size=2288, nrcpt=1 (queue active)
Nov 12 12:27:12 myservername postfix/qmgr[29250]: 3210A1020814: removed
Nov 12 12:27:12 myservername postfix/local[29256]: 3F1291020816: to=<[email protected]>, relay=local, delay=0.05, delays=0.03/0/0/0.03, dsn=5.1.1, status=bounced (unknown user: "sender")
Nov 12 12:27:12 myservername postfix/qmgr[29250]: 3F1291020816: removed

main.cf for postfix:

# See /usr/share/postfix/main.cf.dist for a commented, more complete version


# 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 (Ubuntu)
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 = mydomain.com
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
myorigin = /etc/mailname
mydestination = mydomain.com, localhost.com, , localhost
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


smtp_tls_security_level = may

How can I get the standalone mail server for which my mx record is configured to send the email my webmail server mail client sends through it to itself, rather than back to the webserver?

My answer:


You have configured Postfix on your web server to believe that it handles all incoming mail for your domain, by setting myhostname = mydomain.com. With this set, Postfix will always attempt to deliver mail for the named domain locally.

This is apparently not what you want.

Instead, you should simply remove this setting, which will cause Postfix to use the system hostname instead (which should not be set to the naked domain name) and thus deliver mail for the domain according to its MX records.


View the full question and any other answers on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.