Email address verification script


Login or Register for Dates, Times and to Reply

 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Email address verification script
# 1  
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
# 2  
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

Last edited by Krrishv; 01-14-2007 at 09:31 AM..
# 3  
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
# 4  
Thanx both of you Smilie

I will try it out.

Thanx once again

Regards
Ram
# 5  
Ok guys it worked like magic Smilie

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
Login or Register for Dates, Times and to Reply

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #638
Difficulty: Easy
The original iPhone had 16GB of memory.
True or False?

10 More Discussions You Might Find Interesting

1. OS X (Apple)

SHA1 verification script

Hi guys! Me again! ... I'm trying to build (on MacOS directly) a bash script that will help me verify a SHA1 digest (to verify downloads and so on and so forth). So first off, here's my version of BASH under OSX: bash-4.4$ And here's my version of Sierra (macOS): 10.12.3 (16D32) ... (2 Replies)
Discussion started by: Ardzii
2 Replies

2. Shell Programming and Scripting

Field verification script help

Hello again unix.com I need some help regarding a script. I have: function checkform ( form ) { if (form.pass.value.length < 6) { alert( "Error." ); form.pass.focus(); document.getElementById('pass').style.backgroundColor="#FFFFFF"; return... (2 Replies)
Discussion started by: galford
2 Replies

3. Shell Programming and Scripting

Verification on shell script

hello i have writing a shell script to download and run some packages the only way that i use to verify download pack is , limit users ip to download from main server, if wget can download file (verified) then script run by execute it sh pack76.sh else show and error (stupid solution ha?) ... (8 Replies)
Discussion started by: nimafire
8 Replies

4. Shell Programming and Scripting

Sending email from a script & specifying the "from" address

Hello all, I have a requirement to send an email from a shell script. Simple enough. A google search gives thousands of examples. But here's the catch. I need to be able to specify the "from" address, and none of the examples I've found allow for that. When I used the mail or mailx commands,... (2 Replies)
Discussion started by: lupin..the..3rd
2 Replies

5. Shell Programming and Scripting

Script Verification

Hi eveyone I am planning to use crontab to delete all files in my donwloads directory that are older than one hour I will be using crontab to run this script find /home/kee/downloads/* -daystart -mmin +59 -type f -name -exec rm -r {}\; could you please let me know if the above... (1 Reply)
Discussion started by: k33k00
1 Replies

6. Shell Programming and Scripting

how to write script to change email address

we have 4000 html pages that need an email address changed. eg) company@yahoo.com to company@hotmail.com we only want the file modified date to be changed when there has been a change to the file. Should I be using grep? I fairly new to UNIX and was told to using something like... (2 Replies)
Discussion started by: mchelle_99
2 Replies

7. Shell Programming and Scripting

UNIX Script to query Active Directory: give cn (NT login name) and receive mail (Email address)

Hi folks I need to write UNIX script (with ldapsearch) to query Active Directory. Input is NT login name and output is Email address. Attached a screenshot of Sysinternals "AD Explorer". I need to do the same in CLI. http://i.imgur.com/4s6FB.png I am absolute LDAP/ldapsearch noob. (0 Replies)
Discussion started by: slashdotweenie
0 Replies

8. Shell Programming and Scripting

EMail Address Validation (Shell Script)

Hi, Can anyone provide me the code snippet for EMail Address Validation. User is going to enter the email address in form window. I need to validate the format is correct. Thanks in Advance BS (3 Replies)
Discussion started by: balajiora
3 Replies

9. UNIX for Dummies Questions & Answers

Verification of a script already running - where to do it

Hi, I have a script I want to run as a background process. Where would I add a bit of script so that a check can be performed to see it this is already running and, where it isn't, to then run it? I know how to do this... I just don't know where I can put the initial part of the check script so... (2 Replies)
Discussion started by: miwinter
2 Replies

10. UNIX for Dummies Questions & Answers

Send email where # is in the email address - Using Unix

Hi All, How do I send an email using malix where email address contains a #. I have a email address like this : #test@test.com I want to send email like malix -s "TEST" #test@test.com < SOMEFILE I tried \# but doesn't work. Please let me know how we can achieve this? I am in... (1 Reply)
Discussion started by: jingi1234
1 Replies

Featured Tech Videos