May 5, 2015

f Comment

Fixing Unix Postfix SMTP server error: Host or domain name not found. Name service error.

Amazon When I got a Ubuntu 14.04.1 server with DigitalOcean I had many troubles when setting up the system to be able to send emails reliably. I was trying to migrate from Amazon EC2 to DigitalOcean, and I wanted to keep using Amazon SES for delivering emails reliably. SES was working great on my EC2 instance, but was not working on my droplet.

A droplet is a server instance of DigitalOcean. DigitalOcean is a cloud hosting service.

I followed to the letter to integrate SES with the Postfix SMTP server on my droplet, But I got the following error in /var/log/mail.log when I sent an email with PHP:

postfix/smtp[3475]: 2D3A41253CA: to=<>, relay=none, delay=5.6, delays=5.6/0.02/0/0, dsn=4.4.3, status=deferred (Host or domain name not found. Name service error for type=MX: Host not found, try again)

postfix/smtp[19241]: A89AB1252C7: to=<>, relay=none, delay=218788, delays=218788/0.04/0/0, dsn=4.4.3, status=deferred (Host or domain name not found. Name service error for type=MX: Host not found, try again)

These two entries represent the same error. For some reason Postfix was not able to find the host of the relay according to the configurations I did. What was I supposed to do? I had the identical Postfix settings between my Amazon EC2 instance and my DigitalOcean droplet.

I specifically set the following in /etc/postfix/ on my droplet:

relayhost = []:25

How come the Postfix log says "relay=none"?


Here is what I did to fix this error.

1. Run this command:

$ sudo apt-get install dnsmasq

2. Add the following lines to /etc/dnsmasq.conf:


This is the name server used by my EC2 instance which I found out by running "cat /etc/resolv.conf" on it.

3. Run this command:

$ sudo service dnsmasq restart

4. Run this command:

$ sudo apt-get install network-manager

5. Run this command:

$ sudo service network-manager restart

6. I checked /var/log/syslog and verified that dnsmasq was using the nameservers I specified:

dnsmasq[1653]: using nameserver

7. Try to send the email again. When it works, you should see this message in /var/log/mail.log:

postfix/pickup[2134]: AF8BB1208CD: uid=0 from=
postfix/cleanup[2173]: AF8BB1208CD: message-id=<20150505100023.AF8BB1208CD@some.localdomain>
postfix/qmgr[2136]: AF8BB1208CD: from=, size=8338, nrcpt=1 (queue active)
postfix/smtp[2143]: AF8BB1208CD: to=,[]:25, delay=3.6, delays=0.01/0/2.2/1.4, dsn=2.0.0, status=sent (250 Ok 0000014d238550de-5580ebbd-f2d2-4749-807b-2df67e511ae7-000000)
postfix/qmgr[2136]: AF8BB1208CD: removed

8. When you have verified that email is sent successfully, change /etc/dnsmasq.conf back to the following:


This is because these two name servers were listed in the original /etc/resolv.conf on my droplet. You should use your own original name servers. Follow the same steps above to make this setting take effect. Step 8 is optional. You don't have to do it unless you run into trouble later.

In my case, once I got email to work, I stopped the service dnsmasq and network-manager, and tried sending an email again, and it still worked! I am not sure what's happening, but I am glad this issue has been fixed.

This is by far one of the hardest bugs to fix I have ever encountered. Before I wrote this article, nobody on Google knew. Now Google knows.

If you have any questions let me know and I will do my best to help you!
Please leave a comment here!
One Minute Information - by Michael Wen
ADVERTISING WITH US - Direct your advertising requests to Michael