Solving "Helo command rejected: need fully-qualified hostname" in Postfix
Sometimes outgoing mail rejecting by stmp server at the handshaking stage (wiki page > HELO procedure). Often this related with server configuration to reject handshaking when client hostname is incorrect or empty.
So, when we look in our MTA log (for examle, exim main log often located in /var/log/exim4/mainlog) we could see this:
504 5.5.2 <?none?>: Helo command rejected: need fully-qualified hostname
and may also contain this:
Recipient address rejected: User unknown in virtual mailbox table
Btw, 504 error means that Command parameter not implemented...
End the problem is here >>
Our MTA send own hostname, and for some reason it's empty (none), that is invalid for establishing smtp session in some cases.
First, check hostname to ensure that the problem is really here (use /bin/hostname - may be part of net-tools package or a single package according distribution package policy). Current hostname can also be obtained from kernel parameters,
cat /proc/sys/kernel/hostname will show actual hostname.
For solving this funny issue we just need to set correct (good article here or just
man hostname) hostname , (for Debian based distros is the /etc/hostname file, for Gentoo /etc/conf.d/hostname, rhel-based - /etc/sysconfig/network).
To apply hostname quickly - run
hostname mydomain.com ,
echo 'mydomain.com' > /proc/sys/kernel/hostname will also did the trick and reload MTA. Sure, this stuff will apply only current system state, so saving hostname in config file is a good idea :D
Another way to solve hostname issue (this is not best solution!) - change SMTP server config:
for Postfix, remove the
reject_invalid_helo_hostname from config and reload MTA.
If everything is ok, e-mail Received: header should contain our hostname and look like this:
Received: from www by gonzo.roundside.com with local (Exim 4.76)
but not this
Received: from www by (none) with local (Exim 4.76)
It happens than some user-frienly? distros (especially on vps) may have unexpected surpices with setting hostname, more about it here.