Hackuin
07-25-2011, 03:00 PM
Recently, we had a seminar for computational criminology. And, we had collected various people e-mail, addresses and we are about have a seminar again next month. We had to send invitation to selected members, but the list go too high numbered, and to my astonishment, I had sent them email, but, mail box dumped with "Mailer Demon-Failure", to the stupidity of humans haunt us at most of the times, plenty of people have either misspelled there E-mail Addresses or supplied wrong E-mail address.
So, to avoid, these situations again, I taught of wring a script to verify e-mail address, before sending E-mails/Just to send e-mails to valid address.
#!/bin/bash
#:
#: e-mail.verify.sh
#:
#: Date: 2011/23/07 08:20:58 PM IST
#: Author: Hackuin _at_ Ymail com
#: Discription: Verify (or) Validate the G-Mail Adresses.
#:
#: Copyright (c) 2011 Under GPL License.
#:
if [ ! $# == 1 ]
then
echo "Usage: $0 Filename"
exit 0
fi
cd /tmp
cat $1 | while read LINE; do
{
FILENAME="i*"
NULL="/dev/null"
rm -rf i*
#: At first I tryied this URI, but, it limited to 5 mail verification
#: per hour it seems :/
#: wget "http://www.email-unlimited.com/tools/verify-email.aspx?Email=$LINE&B1=Verify"
wget "http://my-addr.com/free-email-verification-tool/verify-email-address/reverse-email-lookup/verify_email.php/?mail=$LINE&x=15&y=13"
grep "e-mail exist" $FILENAME >$NULL
if [ "$?" -eq "0" ]
then
echo -e "$LINE" > VALIDEMAIL
else
echo -e "$LINE" > $NULL
fi
}
done
#: END
However, instead of using/calling, other peoples tool, I mean the existing "my-addr.com" script, I again taught of writing our own script, verify.
#!/bin/bash
#:
#: e-mail.verify.sh
#:
#: Date: 2011/22/07 09:40:28 PM IST
#: Author: Hackuin _at_ Ymail com
#: Discription: Verify (or) Validate the G-Mail Adresses.
#:
#: Copyright (c) 2011 Under GPL License.
#:
#: First we create a Expect script to be sourced for us.
#:
if [ ! $# == 1 ]
then
echo "Usage: $0 Filename"
exit 0
fi
#: Verifying the G-mail adressess.
#: First verify the network Connections
C_R="\e[01;31m" ## Colors
C_B="\e[01;30m"
C_G="\e[01;32m"
C_END="\e[00m"
SMTPSERV=`host -t mx gmail.com |grep 5 |cut -d " " -f 7| sed 's/\.$//'`
ping -c1 $SMTPSERV >/dev/null
if [ "$?" -eq 0 ]
then
echo -e "Internet Connection" "\t\t\t\t\t\t$C_G[ OK ]$C_END"
echo -e "$SMTPSERV is AVAILABLE."
echo -n "Verifing"
for (( i=0; i<5; i++ ))
do
echo -n ".."
sleep 1
done
echo
else
echo -e "Internet Connection:" "\t\t\t\t\t\t$C_R[ FAIL ]$C_END" ""
echo -e "$SMTPSERV is Unavialable."
echo -e "Check your Network settings."
exit 0
fi
# Checking Expect is available or not.
expect -v >/dev/null
if [ "$?" -eq 0 ]
then
echo -e "Expect:" "\t\t\t\t\t\t\t$C_G[ OK ]$C_END" ""
else
echo -e echo -e "Expect:" "\t\t\t\t\t\t\t$C_R[ FAIL ]$C_END" ""
echo -e "sudo apt-get install -y expect"
fi
COUNT=0
RM_FILE="validemails.txt"
rm -rf $RM_FILE
cat $1 | while read LINE; do
{
MAFR="MAIL FROM: <EXPECT@SCRIPT.COM>"
MATO="RCPT TO: <$LINE>"
#: ^variablies declared for not get escaped in the next cat command, where
#: we set the $MAFR in the expect script.
cat << __EOF > e-veri1
#!/bin/expect
#:
#: Date: 2011/22/07 09:23:44 PM IST
#: Author: Hackuin _at_ Ymail com
#: Discription: Expect Script to Verify/Validate the G-Mail Adresses.
#:
set VMAFR "$MAFR"
set VMATO "$MATO"
spawn nc gmail-smtp-in.l.google.com 25
expect "ESMTP"
send "HELO\r"
expect "service"
send "\$VMAFR\r"
expect "OK"
send "\$VMATO\r"
expect "OK"
send "quit\r"
expect eof
__EOF
#: Running the expect script and extracting the Results.txt
expect e-veri1 > Results.txt
grep 550 Results.txt >/dev/null
if [ "$?" -eq 0 ]
then
echo -e $LINE >/dev/null #invalid E-mails
else
echo -e "$LINE" >> validemails.txt
fi
}
done
echo -e "Valid E-mail have been saved to $C_R[ validemails.txt ]$C_END"
#: END
Below are screen shots:
http://img1.imagehousing.com/91/c8d8deca52c62622684c6219a133a111.png
-Hackuin
So, to avoid, these situations again, I taught of wring a script to verify e-mail address, before sending E-mails/Just to send e-mails to valid address.
#!/bin/bash
#:
#: e-mail.verify.sh
#:
#: Date: 2011/23/07 08:20:58 PM IST
#: Author: Hackuin _at_ Ymail com
#: Discription: Verify (or) Validate the G-Mail Adresses.
#:
#: Copyright (c) 2011 Under GPL License.
#:
if [ ! $# == 1 ]
then
echo "Usage: $0 Filename"
exit 0
fi
cd /tmp
cat $1 | while read LINE; do
{
FILENAME="i*"
NULL="/dev/null"
rm -rf i*
#: At first I tryied this URI, but, it limited to 5 mail verification
#: per hour it seems :/
#: wget "http://www.email-unlimited.com/tools/verify-email.aspx?Email=$LINE&B1=Verify"
wget "http://my-addr.com/free-email-verification-tool/verify-email-address/reverse-email-lookup/verify_email.php/?mail=$LINE&x=15&y=13"
grep "e-mail exist" $FILENAME >$NULL
if [ "$?" -eq "0" ]
then
echo -e "$LINE" > VALIDEMAIL
else
echo -e "$LINE" > $NULL
fi
}
done
#: END
However, instead of using/calling, other peoples tool, I mean the existing "my-addr.com" script, I again taught of writing our own script, verify.
#!/bin/bash
#:
#: e-mail.verify.sh
#:
#: Date: 2011/22/07 09:40:28 PM IST
#: Author: Hackuin _at_ Ymail com
#: Discription: Verify (or) Validate the G-Mail Adresses.
#:
#: Copyright (c) 2011 Under GPL License.
#:
#: First we create a Expect script to be sourced for us.
#:
if [ ! $# == 1 ]
then
echo "Usage: $0 Filename"
exit 0
fi
#: Verifying the G-mail adressess.
#: First verify the network Connections
C_R="\e[01;31m" ## Colors
C_B="\e[01;30m"
C_G="\e[01;32m"
C_END="\e[00m"
SMTPSERV=`host -t mx gmail.com |grep 5 |cut -d " " -f 7| sed 's/\.$//'`
ping -c1 $SMTPSERV >/dev/null
if [ "$?" -eq 0 ]
then
echo -e "Internet Connection" "\t\t\t\t\t\t$C_G[ OK ]$C_END"
echo -e "$SMTPSERV is AVAILABLE."
echo -n "Verifing"
for (( i=0; i<5; i++ ))
do
echo -n ".."
sleep 1
done
echo
else
echo -e "Internet Connection:" "\t\t\t\t\t\t$C_R[ FAIL ]$C_END" ""
echo -e "$SMTPSERV is Unavialable."
echo -e "Check your Network settings."
exit 0
fi
# Checking Expect is available or not.
expect -v >/dev/null
if [ "$?" -eq 0 ]
then
echo -e "Expect:" "\t\t\t\t\t\t\t$C_G[ OK ]$C_END" ""
else
echo -e echo -e "Expect:" "\t\t\t\t\t\t\t$C_R[ FAIL ]$C_END" ""
echo -e "sudo apt-get install -y expect"
fi
COUNT=0
RM_FILE="validemails.txt"
rm -rf $RM_FILE
cat $1 | while read LINE; do
{
MAFR="MAIL FROM: <EXPECT@SCRIPT.COM>"
MATO="RCPT TO: <$LINE>"
#: ^variablies declared for not get escaped in the next cat command, where
#: we set the $MAFR in the expect script.
cat << __EOF > e-veri1
#!/bin/expect
#:
#: Date: 2011/22/07 09:23:44 PM IST
#: Author: Hackuin _at_ Ymail com
#: Discription: Expect Script to Verify/Validate the G-Mail Adresses.
#:
set VMAFR "$MAFR"
set VMATO "$MATO"
spawn nc gmail-smtp-in.l.google.com 25
expect "ESMTP"
send "HELO\r"
expect "service"
send "\$VMAFR\r"
expect "OK"
send "\$VMATO\r"
expect "OK"
send "quit\r"
expect eof
__EOF
#: Running the expect script and extracting the Results.txt
expect e-veri1 > Results.txt
grep 550 Results.txt >/dev/null
if [ "$?" -eq 0 ]
then
echo -e $LINE >/dev/null #invalid E-mails
else
echo -e "$LINE" >> validemails.txt
fi
}
done
echo -e "Valid E-mail have been saved to $C_R[ validemails.txt ]$C_END"
#: END
Below are screen shots:
http://img1.imagehousing.com/91/c8d8deca52c62622684c6219a133a111.png
-Hackuin