I am using Raspbian and the Postfix (version 2.9.6) service seems to be automatically run when I boot, but if I want to send a mail, the email stays in the queue:

$ mailq
26CB72201F    443 Sat Sep 19 19:44:17   user@mail.example.com
(Host or domain name not found. Name service error for name=smtp.gmail.com type=A: Host not found, try again)

If I restart the service (sudo service postfix restart) then emails work until the next boot.

Why? What is the difference?

During the Postfix installation I chose the configuration “Internet with smarthost” but then I followed a tutorial for …Internet Site” to finish the configuration so this might be the problem(?) I just want to send emails.

UPDATE: The problem might be that that Postfix is run before the Wi-Fi is connected.


Shorter answer.

With a “Host not found, try again.” it could mean that your server is having DNS resolution issues, or Postfix itself is having DNS resolution issues. But that is the core of what has to be cleaned up.

As for how to clear it up, your question doesn’t provide enough details on your base OS or setup to give a succinct answer. You seem to be running Ubuntu/Debian if you are running sudo service postfix restart, but what other details can you provide?

Longer answer.

Possibly connected to resolv.conf mysteriously disappearing.

Based on the error:

Host or domain name not found. Name service error for name=smtp.gmail.com type=A: Host not found, try again.

It seems like you are using Gmail’s SMTP servers for outgoing mail. Unsure what your base OS is, but based on this answer on Ubuntu Forums this seems to be an issue with a missing resolv.conf on reboot; bold emphasis is mine:

I have the same problem on Ubuntu 14.04 LTS. When postfix is installed it copies /etc/resolv.conf to /var/spool/postfix/etc/resolve.conf. but for some reason after a reboot/restart the file is not copied and you get the blank file with only the header.

The suggested temporary solution is to copy the main OS resolv.conf to Postfix’s directory:

sudo cp /etc/resolv.conf /var/spool/postfix/etc/resolv.conf

This isn’t a permanent fix it seems but at least it’s something to check out.

Possibly connected to inet_protocols settings.

Also this answer on Server Fault explains a similar situation which focuses on IPv6 support. Pretty sure your issue is not IPv6-related since the error is about a “type=A” record which is IPv4 and for IPv6 it would be “type=AAAA.” But that said, it might worth experimenting with adjusting the inet_protocols setting in your Postfix config file. Here is what the official Postfix documentation explains:

When IPv4 support is enabled via the inet_protocols parameter, Postfix will look up DNS type A records, and will convert IPv4-in-IPv6 client IP addresses (::ffff: to their original IPv4 form ( The latter is needed on hosts that pre-date IPV6_V6ONLY support (RFC 3493).

When IPv6 support is enabled via the inet_protocols parameter, Postfix will do DNS type AAAA record lookups.

When both IPv4 and IPv6 support are enabled, the Postfix SMTP client will choose the protocol as specified with the smtp_address_preference parameter. Postfix versions before 2.8 attempt to connect via IPv6 before attempting to use IPv4.


  • inet_protocols = ipv4
  • inet_protocols = all (DEFAULT)
  • inet_protocols = ipv6
  • inet_protocols = ipv4, ipv6

Assuming you are on an Ubuntu/Debian setup open up the config here:

sudo nano /etc/postfix/main.cf

And find—or set the value—to the inet_protocols line to be either this:

inet_protocols = ipv4

Or be this:

inet_protocols = all

Then restart the Postfix service—or the whole server—and see if that clears things up:

sudo service postfix restart

The problem is that Postfix checks /etc/resolv.conf before the WiFi is connected. Therefore, /var/spool/etc/postfix/resolv.conf stays empty after the boot and mails cannot be sent.

To solve the problem, I disabled postfix service:

sudo update-rc.d postfix disable

…and I wrote this script to wait the end of the Wi-Fi connection before to start Postfix (saved in /usr/local/bin/postfix_wifi.sh):



until nc $host $port -w 5
    sleep 10

sudo service postfix start
exit 0

…and I added this line to /etc/rc.local so that the script is run at boot:

/usr/local/bin/postfix_wifi.sh &
  • Very, very nice! Cool to see you solved this on your own. – Giacomo1968 Sep 20 '15 at 19:26
  • Thanks! This solution is in the same vein as yours and solved it for me: unix.stackexchange.com/a/272512/195308 – Peter Becich Jul 26 '17 at 3:45
  • For those coming late to the party, the path for me was at: /var/spool/postfix/etc/resolv.conf so postfix and etc swapped places. – Roger Lehmann Oct 14 '20 at 10:58

For me it was error with AWS SES:

Host or domain name not found. Name service error for name=email-smtp.us-west-2.amazonaws.com type=AAAA: Host not found, try again

I able to resolve it by telling to Postfix to use Google DNS , right after Installing postfix:

echo 'nameserver' >> /var/spool/postfix/etc/resolv.conf

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.