Skip to content

Check if an email address exists without sending any email, written in Rust. Comes with a ⚙️ HTTP backend.

Improve script

Amaury Martiny310a9871ec65
diff --git a/checkEmail.sh b/checkEmail.sh
index 78fa2499..1914d69a 100755
--- a/checkEmail.sh
+++ b/checkEmail.sh
@@ -2,21 +2,21 @@
# Set useful variables
EMAIL="$1";
-HOST=`cut -d "@" -f 2 <<< "$1"`;
-PORTS=(587 25 465); # The PORTS to test our telnet on, in this order
+DOMAIN=`cut -d "@" -f 2 <<< "$1"`;
+MX_HOSTS=(`nslookup -q=mx $DOMAIN | grep mail | cut -d " " -f 5`) # Find MX hosts of our domain
+PORTS=(25 587 465); # The PORTS to test our telnet on, in this order
-for PORT in ${PORTS[@]}
+for HOST in ${MX_HOSTS[@]}
do
- OUTPUT=`expect expectTelnet.sh $EMAIL $HOST $PORT`;
- if [[ `echo $OUTPUT | grep "2.1.5"` ]]; # 2.1.5 means address exists
- then
- echo true;
- exit 0;
- elif [[ `echo $OUTPUT | grep "5."` ]]; # 5.*.* are error codes
- then
- echo false;
- exit 1
- fi
+ for PORT in ${PORTS[@]}
+ do
+ OUTPUT=`expect expectTelnet.sh $EMAIL $HOST $PORT`;
+ if [[ `echo $OUTPUT | grep "2.1.5"` ]]; # 2.1.5 means address exists
+ then
+ echo true;
+ exit 0;
+ fi
+ done
done
echo false;
diff --git a/expectTelnet.sh b/expectTelnet.sh
index 7b12c985..d52525a3 100644
--- a/expectTelnet.sh
+++ b/expectTelnet.sh
@@ -8,9 +8,11 @@ set port [lindex $argv 2]
# Start a Telnet communication
spawn telnet $host $port;
expect "220"
-send "MAIL FROM: [email protected]\r";
+send "HELO Hi\r";
expect "250"
-send "RCPT TO: $email\r";
+send "MAIL FROM: <[email protected]>\r";
+expect "250"
+send "RCPT TO: <$email>\r";
expect "*"
send "QUIT\r"
expect eof