Fix for slow SMTP to localhost: mailhost entry in /etc/hosts

Support and queries relating to all previous versions of ZoneMinder
Locked
haus
Posts: 213
Joined: Thu Oct 11, 2007 5:10 am

Fix for slow SMTP to localhost: mailhost entry in /etc/hosts

Post by haus »

I've had a maddening issue since I started using localhost as my mail transport from ZM. An almost *exact* two-minute delay in zmfilter.log between "Sending notification email..." and "Notification email sent". This would occur every time I had a ZM email notification. I'm using Ubuntu 7.10 and old mail modules (the default for 1.23.3 as of this writing). Here's a piece of zmfilter.log:

Code: Select all

root@zoneminder:/tmp# tail -f zmfilter.log
01/09/09 15:08:12.668611 zmfilter[4831].INF [Scanning for events]
01/09/09 15:10:47.984449 zmfilter[4831].INF [Creating notification email]
01/09/09 15:10:47.985024 zmfilter[4831].INF [Sending notification email 'West_Pathway Alarm - 2009-01-09 15:10:30']
01/09/09 15:12:48.207334 zmfilter[4831].INF [Notification email sent]
I've been around long enough to know that anything that sits idle for exactly two minutes has a high probability of being a DNS lookup failure. Also, my command line mail experiences no delay (I use an SMTP auth smarthost with exim4). Running netstat -nt while ZM was trying to send mail revealed my box was trying to connect to port 25 of my public IP address rather than localhost. My exim config doesn't listen on port 25 from anything other than 127.0.0.1, and port 25 is blocked by a hardware router. So of course that connection failed after two minutes, and then it would fall back to 127.0.0.1:25 and the mail would immediately go through.

The line in zmfilter.pl that was causing the delay was $mail->smtpsend; I found a blurb online about the order in which smtpsend checks for mail hosts, and at least on my system it doesn't appear to be honoring the "Host" directive that ZM is trying to pass to it. So I added a line in my /etc/hosts:

Code: Select all

127.0.0.1 mailhost
and here's the latest from zmfilter.log:

Code: Select all

01/09/09 15:13:18.221506 zmfilter[4831].INF [Creating notification email]
01/09/09 15:13:18.221892 zmfilter[4831].INF [Sending notification email 'West_Pathway Alarm - 2009-01-09 15:12:57']
01/09/09 15:13:18.293129 zmfilter[4831].INF [Notification email sent]
Hooray! No more delays sending mail.


And a quick thank you to Ross in this thread:

http://www.zoneminder.com/forums/viewto ... t=mailhost

I didn't discover that thread until after I'd done all this work, because I didn't know to search for the word "mailhost", but had I seen that thread sooner it might have clued me in faster.
Locked