Unix – Sendmail is slow to send mail

Problem
SendMail / PHPMail() commands are taking more than 30seconds to complete.

Solution
Review the maillog file

tail -f /var/log/maillog

adminuser@mywebserver:/$ tail -f /var/log/mail.log
Oct 7 15:41:01 mywebserver sm-msp-queue[12250]: unable to qualify my own domain name (mywebserver) — using short name
Oct 7 16:00:01 mywebserver sm-msp-queue[12937]: My unqualified host name (localhost) unknown; sleeping for retry
Oct 7 16:00:13 mywebserver sendmail[13000]: My unqualified host name (localhost) unknown; sleeping for retry

Oct 7 16:01:13 mywebserver sendmail[13000]: u97K1Dij013000: from=adminuser, size=39, class=0, nrcpts=1, msgid=<201610072001.u97K1Dij013000@localhost>, relay=adminuser@localhost
Oct 7 16:01:13 mywebserver sm-mta[13068]: u97K1DSc013068: from=<adminuser@localhost>, size=308, class=0, nrcpts=1, msgid=<201610072001.u97K1Dij013000@localhost>, proto=ESMTP, daemon=MTA-v4, relay=localhost [127.0.0.1]
Oct 7 16:01:13 mywebserver sendmail[13000]: u97K1Dij013000: to=michael@xdomainx.com, ctladdr=adminuser (1000/1000), delay=00:00:00, xdelay=00:00:00, mailer=relay, pri=30039, relay=[127.0.0.1] [127.0.0.1], dsn=2.0.0, stat=Sent (u97K1DSc013068 Message accepted for delivery)
Oct 7 16:01:13 mywebserver sm-mta[13070]: STARTTLS=client, relay=mx1.efwmx.net., version=TLSv1/SSLv3, verify=FAIL, cipher=ECDHE-RSA-AES256-SHA384, bits=256/256
Oct 7 16:01:14 mywebserver sm-mta[13070]: u97K1DSc013068: to=<michael@xdomainx.com>, ctladdr=<adminuser@localhost> (1000/1000), delay=00:00:01, xdelay=00:00:01, mailer=esmtp, pri=120308, relay=mx1.efwmx.net. [192.203.239.71], dsn=2.0.0, stat=Sent (Message received OK [id=B0050364618@AAAIBPV02.800onemail.com])

The highlighted part of the logs shows a local domain name resolution issue. This requires an appropriate hosts file entry for the unqualified hostname, that is the short version returned by the hostname command, which points to the local loop-back IP rather than it’s external IP like so:

127.0.0.1 localhost.localdomain localhost yourhostname

Example of the actual entry below:

127.0.0.1 mywebserver.xdomainx.com localhost mywebserver

Use hostname command to view your hostname

Once it shows up ok, then restart the apache service

adminuser@mywebserver:/$ sudo service apache2 restart
* Restarting web server apache2 [Fri Oct 07 16:04:57 2016] [warn] NameVirtualHost *:80 has no VirtualHosts
… waiting [Fri Oct 07 16:04:58 2016] [warn] NameVirtualHost *:80 has no VirtualHosts [ OK ]
adminuser@mywebserver:/$

Tested Platform
Ubuntu 14
Apache

Leave a Reply