Postfix uses hostname instead of thehostname

hostnamepostfixsendmail

I am trying to set up an outgoing mail server for sending emails which is to relay to our ISP.

In /etc/postfix/main.cf I have myhostname to ourcompany.example.com and myorigin and mydomain to $myhostname. ourcompany.example.com is resolvable.

But looking at the logs in /var/log/maillog it appears that postfix does use the myhostname for the send address, but uses whatever from getmyhostname(), which is set to an internal DNS name since this is an internal server and we only send email out, but not handling incoming email.

Any ideas?

EDIT: postconf -n

alias_database = hash:/etc/aliases
alias_maps = hash:/etc/aliases
command_directory = /usr/sbin
config_directory = /etc/postfix
daemon_directory = /usr/libexec/postfix
data_directory = /var/lib/postfix
debug_peer_level = 2
html_directory = no
inet_interfaces = localhost
inet_protocols = all
mail_owner = postfix
mailq_path = /usr/bin/mailq.postfix
manpage_directory = /usr/share/man
mydestination = $myhostname, localhost.$mydomain, localhost
mydomain = example.com
myhostname = ourcompany.example.com
myorigin = $mydomain
newaliases_path = /usr/bin/newaliases.postfix
queue_directory = /var/spool/postfix
readme_directory = /usr/share/doc/postfix-2.6.5/README_FILES
relayhost = smtp.grapevine.com.au
sample_directory = /usr/share/doc/postfix-2.6.5/samples
sendmail_path = /usr/sbin/sendmail.postfix
setgid_group = postdrop
unknown_local_recipient_reject_code = 550

Where both ourcompany.example.com and example.com are public domains are resolvable by anyone, therefore should be resolvable by my ISP. The problem isn't the domain, but the fact that postfix is not using it, I am getting logs like:

May 26 10:23:22 localhost postfix/smtp[3910]: 449AF5803F6: to=<tesing@example.com>, relay=smtp.grapevine.com.au[203.129.32.140]:25, delay=63275, delays=63274/0.02/0.04/0.4, dsn=4.1.8, status=deferred (host smtp.grapevine.com.au[203.129.32.140] said: 450 4.1.8 <benny@server.internal>: Sender address rejected: Domain not found (in reply to RCPT TO command))

It is using server.internal instead of $myorigin, and server.internal is what you get from calling gethostname(), and it is an internal hostname and is not resolvable on the public internet.

So my question is this, how do I set postfix to use example.com instead of using gethostname()? My thinking was that gethostname() is only used when I leave myorigin, mydomain and myhostname empty, but setting them to the above setting doesn't do anything.

Best Answer

mydomain = example.com
myorigin = $mydomain

By default, the option append_at_myorigin is set to yes, which means that any and all outgoing mail that has no domain component will get the value of myorigin appended.

In your case, that is the domain name, and not the hostname.

Always send mail using fully-qualified addresses, i.e. containing both a localpart and a valid, existing domain/hostname part.

If for some reason you cannot, use one of the methods described in the Address Rewriting Readme