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
Simply changed:
To this
Sendmail
looks for a fully qualified domain (FQDN) name and will use thelocalhost.localdomain
in the single line version.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.
The accepted answer:
seems to work, but produces the errors in
/var/log/syslog
:But leaving just
in
/etc/hosts
, and removing the second line allowsmail
to get sent, and does not result in any errors.Update: when doing
sudo ...whatever..
there is a messagesudo: unable to resolve host foo.bar
, but looks like it does not affect anything..BTW, to restart the hostname service without reboot:
On Ubuntu 16.04, but should not be necessary for
mail
to work after editing/etc/hosts