#!/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 hosti.\"}" 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 username for this e-mail provider.\"}" exit 1 fi