Summary: There are numerous services and scripts that can check if an SMTP, POP or IMAP server is running both from within and without, but just because your mail daemon is running doesn’t mean email is actually being delivered. This script from Alertra checks actual delivery.
The Problem
We use various monitoring techniques at WATSYS to ensure our and our customer’s servers are running well. Some monitoring scripts are run internally (like those that keep an eye on the email queues, for example) and some are run externally (like those that ensure web pages are being served up). While these are all good things, just because a daemon is answering the phone doesn’t mean everything is OK.
Email is especially hairy because once an email is received at a server, it is typically pummeled to death to ensure it is not spam before being delivered to the recipient. Spamassassin, antivirus, and Procmail are but a few of the things that a typical email is passed through on its journey within the receiving server and a misconfiguration in any one of those can cause email to disappear into the ether.
The solution, therefore, it to not only check if email daemons are running, but to actually check if email is being delivered to the recipient.
The Solution
I sat down today to write a script that would run internally and check that the modification time of an IMAP inbox has changed every 15 minutes. A second part of the script would run on another server and would send an email to this account every 15 minutes. So, the logic goes, if the mod time of the inbox on the receiving server changes every 15 minutes, then one can assume that the email has been delivered.
I wasn’t all that happy with this logic as there are a million holes in it. The sending server could fail to send the email for some reason or the account on the receiving server may get over quota and not accept the email just to name a few. With doubts like that, a prudent coding sessions should begin with a Google search to see who has gone down this path before and what they have done.
Turns out that Alertra has been down this path before and they have written and published a simple little script that is much more robust than my fledgling idea. It runs on a single external server and sends an email to a dedicated test account on a remote server. It then logs into the remote server and checks if the email has arrived. Brilliant and so simple.
I am re-publishing the script here just in case Alertra decides to take it offline at some point. The original link is here.
################################################## # This is a standard SMTP/POP3 checking # script. Just change the variables below # to refelect those appropriate to your # scenario. # # You can change this to SMTP/IMAP by # changing all the "pop3" commands to "imap". ################################################## set USER="pop3user" set PASSWD="pop3pass" set EMAIL="pop3@example.com" set SENDER="myaddress@example.com" set SMTP_SERVER="www.example.com" set POP3_SERVER="www.example.com" timeout "120" dns $POP3_SERVER tcp $POP3_PORT # Clear out any messages in the mail box pop3 clear $USER $PASSWD # Send a test message dns $SMTP_SERVER tcp $SMTP_PORT smtp sendmail $SENDER $EMAIL "Ignore: SMTPTest" "SMTP test message" wait 1 # Get the number of messages in the box, should be 1 dns $POP3_SERVER tcp $POP3_PORT pop3 msgcount $USER $PASSWD # If at least 1 message found, then we are done if not $CONTENT = "0" then goto exit wait 2 pop3 msgcount $USER $PASSWD # If at least 1 message found, then we are done if not $CONTENT = "0" then goto exit wait 5 pop3 msgcount $USER $PASSWD # If no messages found, then throw an error if $CONTENT = "0" then error "Email not received" :exit dns $POP3_SERVER pop3 clear $USER $PASSWD
Note: I should look a little closer at things. Turns out this is written in Alertra Scripting Language which is useless to me. I am now sourcing or writing a PHP script…
October 20, 2008
1 person has left a comment
[...] recently wrote about using a script from Alertra to monitor email delivery. It seems that I didn’t look at the script closely enough. This became obvious when I sat [...]