End-to-End Email Monitoring

One of the most requested script requests from our customers is for us to write a script that checks their e-mail server "end-to-end". This means we send a message to their SMTP server and then look for that message to arrive in their POP3 server. We have developed a generic script to do this and are making it available here.

To use the script, you have to have a "test" email account that is not used for anything else. In other words, you don't want to use this script to check your personal email account. The reason is that the script, to keep it as simple as possible, deletes all the email in the POP3 inbox before it runs. This makes it so we only have to look to see if a message has arrived, and not look for a particular message.

 

To add this script to your account, first create a new "Custom Script" device from the Devices page. Next, copy and paste this script into the "Script" field. Finally, edit the variables at the top of the script to reflect your user and server information.

Note: The script works just as good for IMAP4 as it does for POP3. Just change the "pop3" commands in the script to "imap"; they take the same parameters.

##################################################
# 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

Summary

This article shows just one of the many uses of Alertra scripting; end-to-end email monitoring. The Alertra Scripting Language is so powerful that almost no monitoring scenario is out of its reach. Here are some other articles on scripting that you may find useful: