Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Validate Email Address Function

Status
Not open for further replies.

vetteguy69

Technical User
Feb 22, 2002
13
0
0
US
Hello,
I am creating a bash script that needs to validate email addresses. It must call a function to validate the address and see if it's on the local system or not. Then it needs to return a value and send a file to that email address provided it's valid.

Any help is greatly appreciated.
 
I would use a Perl module called Email::Valid for validating email addresses.

[tt]
use Email::Valid;
unless (Email::Valid -> address($email_addr))
{
warn "Not valid Email address\n";
return;
}[/tt]
=================
Bad Company Music
=================
 
#!/bin/sh

function validuser() {
name=$1
awk -v xx="$name" ' BEGIN {
FS = OFS = ":"
if (!xx) {
printf "error: could not read name to compare"
exit
}
}
{
if ($1 == xx) {
print "1"
}
}' /etc/passwd
return
}
val=`validuser $1`
if [ "$val" != 1 ] ; then
echo "Error: invalid user."
exit 1 > /dev/null
else
echo "Found user $1"
#/usr/bin/biabam filename [-s subject] recipient
biabam "/home/myfile" -s "testing" $1
fi

Find biabam here:
 
you could always check the output of '/lib/sendmail -bv address'

a check for 'local' would probably be safe ... however aliases for other destinations will check as being relayed ...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top