Many developers encounter this common Sendmail error when their mail server can't properly resolve the local hostname. The error message typically appears in /var/log/maillog
:
"My unqualified host name (foo.bar) unknown; sleeping for retry"
Sendmail requires a fully qualified domain name (FQDN) for proper operation. When it only finds an unqualified hostname like "foo.bar" (without a domain suffix), it throws this warning and may delay mail sending.
While adding the hostname to /etc/hosts
is often suggested, the solution requires more comprehensive configuration:
127.0.0.1 localhost localhost.localdomain
127.0.0.1 foo.bar foo.example.com
First, verify your current hostname:
hostname
hostname -f
Then update these critical files:
# /etc/hosts
127.0.0.1 localhost localhost.localdomain
192.168.1.10 foo.example.com foo
# /etc/hostname
foo.example.com
# /etc/mail/local-host-names
foo.example.com
localhost.localdomain
localhost
Edit your Sendmail configuration file (/etc/mail/sendmail.mc
) and add:
define(confDOMAIN_NAME', foo.example.com')dnl
FEATURE(use_cw_file')dnl
Then rebuild the configuration:
make -C /etc/mail
service sendmail restart
Check if Sendmail now recognizes your hostname:
sendmail -d0.1 -bv root | grep Canonical
For WordPress specifically, you might need to adjust the PHP mail configuration:
# /etc/php.ini (or relevant PHP config file)
[mail function]
sendmail_path = /usr/sbin/sendmail -t -i -f webmaster@example.com
If problems continue, check DNS resolution:
dig foo.example.com
nslookup foo.example.com
And verify Sendmail's mail queue:
mailq
When working with sendmail
or mail-related plugins (like WordPress email plugins), you might encounter this error in your maillog
:
"My unqualified host name (foo.bar) unknown; sleeping for retry"
This typically occurs when Sendmail can't properly resolve your server's hostname to a fully qualified domain name (FQDN).
Sendmail requires a properly configured hostname that meets these criteria:
- Must be a FQDN (like
server.example.com
) - Must be resolvable both forward and reverse
- Must appear in your
/etc/hosts
file correctly
First, check your current hostname:
hostname
hostname -f
Then examine your /etc/hosts
file:
cat /etc/hosts
Here's how to properly configure your system:
1. Set a FQDN Hostname
sudo hostnamectl set-hostname server.example.com
2. Correct /etc/hosts Configuration
Your /etc/hosts
should look like this:
127.0.0.1 localhost localhost.localdomain
127.0.1.1 server.example.com server
3. Update Sendmail Configuration
Edit /etc/mail/sendmail.mc
and ensure these lines exist:
define(confDOMAIN_NAME', server.example.com')dnl
define(confCF_VERSION', server.example.com')dnl
Then rebuild the sendmail configuration:
sudo make -C /etc/mail
After making changes, test with:
sendmail -bv root
You should see output confirming proper delivery configuration.
If you need a temporary solution, add this to /etc/mail/local-host-names
:
foo.bar
localhost
localhost.localdomain
Then restart sendmail:
sudo systemctl restart sendmail
- Using just
127.0.0.1
without the FQDN - Not having reverse DNS properly configured
- Forgetting to rebuild sendmail config after changes