Email address verification script

Hi Group,

Please forgive in case this is discussed.

I need help regarding a simple script to verify if the give address exist in the Ldap directory. If the email exists the script should exit with a 0 status or else a non zero status.

I am currently using the following script (and it is working ).
-----
# cat email_rcpt.sh

#!/bin/bash
# Email verification
sleep 1
LDAP_LOOKUP="/var/qmail/bin/qmail-ldaplookup -m"
EMAIL=$1
export $LDAP_LOOKUP $EMAIL
$LDAP_LOOKUP $EMAIL
---------------------------------
# ./email_rcpt.sh foo@bar.com
# echo $?
# 0
----

This script is working correctly. Except that I have a few domains which have catchall addresses & a few whoes email addresses are not maintained in our LDAP ( external domains). I have a file called /var/qmail/control/goodmailaddr which has list of all such domains whoes email address verifications is skipped .

I need to some how modify the above script to recognise this file . My current work-around for this problem is by adding an catchall entry of all the external domains in my LDAP.

Here is how I need to do this .
when the email address is supplied as argument split the domain part and check if it is present in the goodmailaddr file. If present exit with 0 , if not continue with the lookup.

Thanx in advance for help

Regards
Ram

eg : abc@yahoo.com is the email address.

t=`echo $1|cut -d "@" -f2`
k=`grep "$t" <goodmailaddr file>`
if [ $? -eq 1 ]; then
do lookup
else
echo "this is a external address"
exit 0
fi

grep -q "${EMAIL#*@}" /var/qmail/control/goodmailaddr \
&& exit 0

Regards
Dimitre

P.S. If the -q option is not available for your grep version, use this:

grep "${EMAIL#*@}" /var/qmail/control/goodmailaddr > /dev/null 2>&1 \
&& exit 0

Thanx both of you :wink:

I will try it out.

Thanx once again

Regards
Ram

Ok guys it worked like magic :slight_smile:

Here is the final thing. The "sleep 1" is for reducing the no of concurrent lookups on the LDAP server.

-----
#!/bin/bash
sleep 1
LDAP_LOOKUP='/var/qmail/bin/qmail-ldaplookup -m '
GOODMAILADDR='/var/qmail-outside/control/goodmailaddr'
export $LDAP_LOOKUP $GOODMAILADDR
t=`echo $1|cut -d "@" -f2`
k=`grep "^@$t$" $GOODMAILADDR`
if [ $? -eq 1 ]; then
$LDAP_LOOKUP $1
else
echo "this is a external address"
exit 0
fi
-----

Warm Regards
Ram