38

When trying to start sendmail or send a mail using a wordpress plugin, this error shows up in the maillog:

"My unqualified host name (foo.bar) unknown; sleeping for retry"

After Googling the best advice was, "add foo.bar to the /etc/hosts file", but it already is:

127.0.0.1     localhost localhost.localdomain
127.0.0.1     foo.bar
Richard Stelling
  • 1,467
  • 2
  • 19
  • 25

3 Answers3

58

Simply changed:

127.0.0.1     localhost localhost.localdomain
127.0.0.1     foo.bar

To this

127.0.0.1     localhost localhost.localdomain foo.bar

Sendmail looks for a fully qualified domain (FQDN) name and will use the localhost.localdomain in the single line version.

Richard Stelling
  • 1,467
  • 2
  • 19
  • 25
  • 2
    fixed my problem. Just want to be clear, it is the hostname that should be put in this line. So first use hostname command find it, than add it to this line in \etc\hosts . Thanks, man. – Leon Jul 04 '13 at 06:53
  • It didn't work for me – user10089632 Mar 13 '18 at 19:12
  • or actually use a domain name that exists and is configured properly. At least if you want your mail to get _delivered_ you should. – Sammitch Dec 29 '18 at 01:41
  • just to clarify it a bit - the foo.bar should be your `hostname`, to get your hostname easily run `$ hostname` . Then add the shown hostname to that line as suggested in this solution – Shir Gans Nov 06 '19 at 09:24
2

Simply adding the domain to your hosts files as @rjstelling suggests will only allow your mail to be sent, but it is incredibly unlikely to land in someone's inbox.

In order to send an email that won't be flagged as spam, to say nothing of the receiving server just terminating the delivery attempt or dropping the message, you need to be using a real, registered domain name with working DNS and an MX record.

And that is to say nothing for FCRDNS or any one of the dozens of things that you need to do to run a server whose email might actually be accepted most of the time. [if the internet gods deign to smile upon you even briefly] The true answer is that you probably shouldn't be running your own mailserver because it's simply not worth the work required to keep it in good standing. Look into mail services like SendGrid, MailChimp, etc.

Sammitch
  • 2,072
  • 1
  • 20
  • 34
1

The accepted answer:

    127.0.0.1   localhost localhost.localdomain foo.bar

seems to work, but produces the errors in /var/log/syslog:

    sendmail[11655]: gethostbyaddr(192.168.1.123) failed: 1

But leaving just

    127.0.0.1   localhost

in /etc/hosts, and removing the second line allows mail to get sent, and does not result in any errors.

Update: when doing sudo ...whatever.. there is a message sudo: unable to resolve host foo.bar, but looks like it does not affect anything..

BTW, to restart the hostname service without reboot:

    systemctl restart systemd-hostnamed

On Ubuntu 16.04, but should not be necessary for mail to work after editing /etc/hosts

user507226
  • 11
  • 2