Mail Tester Script

The script is based on zenity and the Postfix mail generator smtp-source. It is meant for testing mail-relays and what they return if something goes wrong. Or if you just need a lot of test mails send quickly.

There are a couple of more options available but I don't need them at the time. If you need them you can use this as a starting point and then just add them yourself.

#!/bin/bash

# Basic variables
OUTFILE="/tmp/smtp-source.out"
rm $OUTFILE 2>/dev/null
DATETIME=`date +%H\:%M`
# -f
FROM="test@nixgeek.org"
# -t
RECIPIENT="nouser@lnxgeek.org"
# -m
MSGCOUNT=10
# -M
HELOHOST="mail.lnxgeek.org"
# -S
SUBJECT="Test_Mail_$DATETIME"
HOST=""

# Check if Postfix is installed
INSTALLED=`which smtp-source`
if [ "$INSTALLED" == "" ] 
then
	zenity --error  --text="Postfix Not Installed! \n\nTo install run 'sudo apt-get install postfix'"
	exit 0
fi

# Ask for the host
HOST=`zenity --entry-text=$HOST --entry --text="Mail-Relay (host:port)"`

# Breakout if no host is specified
if [ "$HOST" == "" ] 
then
	exit 0
fi

# Ask for a sender address
FROM=`zenity --entry-text=$FROM --entry --text="Sender Address"`

# Ask for recipient
RECIPIENT=`zenity --entry-text=$RECIPIENT --entry --text="Recipient Address"`

# Ask for messagecount
MSGCOUNT=`zenity --entry-text=$MSGCOUNT --entry --text="No. of Messages to Send"`

# Ask for helo host
HELOHOST=`zenity --entry-text=$HELOHOST --entry --text="Helo hostname"`

# Ask for subject
SUBJECT=`zenity --entry-text=$SUBJECT --entry --text="Subject"`

# Collect command
CMD="smtp-source -f $FROM -t $RECIPIENT -m $MSGCOUNT -M $HELOHOST -S $SUBJECT $HOST"

# Executing commands
$CMD 2>$OUTFILE | zenity --progress --pulsate --auto-close

# Test result
SIZE=`ls -lh $OUTFILE | awk '{print $5}'`
if [ $SIZE -gt 0 ]
then
	cat $OUTFILE | zenity --text-info --width 530
	exit 0
fi

echo "*SUCCESS*" | zenity --text-info 	

rm $OUTFILE