Files
i-buy.properties/checkMail.sh
2017-02-08 00:20:51 -05:00

49 lines
893 B
Bash
Executable File

#!/bin/bash
#set -x
testhost=webthink.net
testuser=webmaster@${testhost}
#logfile=~/mailqueryfail.log
mail=$1
hostPart=${mail/*@/}
if [ hostPart != "localhost" ]
then host=$(dig +short $hostPart MX | sort -n | head -n1 | cut -d " " -f 2)
if [ -z ${host} ]
then echo -e "{\"status\":\"err\", \"error\":\"Unknown mail host\"}"
exit 1
fi
else
host=localhost
fi
result=$((cat << EOE
set timeout 60
spawn nc $host 25
expect "220" {
send "EHLO ${testhost}\r"
expect "250 " {
send "MAIL FROM:<${testuser}>\r"
expect "250" {
send "RCPT TO:<${mail}>\r"
expect "250" {
send "QUIT\r"
} -re \[\n\r\]5.*$ {
exit 1 1
close
}
}}}
EOE
) | expect -f - | grep -e '^5')
if [ -z "${result}" ]
then echo "OK : " $mail >> /dev/null # $logfile
echo -e "{\"status\":\"ok\"}"
exit 0
else echo $mail ":" $result >> /dev/null # $logfile
echo -e "{\"status\":\"err\", \"error\":\"Unknown User\"}"
exit 1
fi