52 lines
1.0 KiB
Bash
Executable File
52 lines
1.0 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
set -x
|
|
|
|
testhost=webthink.net
|
|
testuser=webmaster@${testhost}
|
|
logfile=./checkMailQueryfail.log
|
|
#echo -e "{\"status\":\"err\", \"path\":\"`pwd`\"}"
|
|
#exit 0
|
|
|
|
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 "`date` - ERR : " $mail ": Unknown Host" >> $logfile
|
|
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 "`date` - OK : " $mail >> $logfile
|
|
echo -e "{\"status\":\"ok\"}"
|
|
exit 0
|
|
else echo "`date` - ERR : " $mail ":" $result >> $logfile
|
|
echo -e "{\"status\":\"err\", \"error\":\"Unknown username for this e-mail provider.\"}"
|
|
exit 1
|
|
fi
|