Initial checkin
This commit is contained in:
48
checkMail.sh
Normal file
48
checkMail.sh
Normal file
@@ -0,0 +1,48 @@
|
||||
#!/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 >> $logfile
|
||||
echo -e "{status:'ok'}"
|
||||
exit 0
|
||||
else echo $mail ":" $result >> $logfile
|
||||
echo -e "{status:'err', error:'Unknown User'}"
|
||||
exit 1
|
||||
fi
|
||||
Reference in New Issue
Block a user