Email address check function

TMGB bennettt at am.appstate.edu
Wed Dec 8 19:41:22 EST 1999


I don't know if this helps but I've used a form that mails the results
of a form to different people and the form uses the user's own
mailserver to send it from.  That way if it is an invalid email address
I don't get the error message and don't get invalid data to deal with. 
In the snippet below, the "sentfrom" value is suppose to be the user's
email address then the mail server is set to the value of the string
starting from the end of the string all the way up to the @ symbol but
not including the @.  This is assumed to be the mail server for that
user.  This is using SMTPlib of course.

# Asign MAILTO results from form to mailto values   
#   mailserver=form["mserver"].value
#   first get user's domain from email address and use their server to
mail from
  
mailserver=form["sentfrom"].value[string.find(form["sentfrom"].value,"@")+1:]
   mailrecip=form["sendto"].value
   subject=form["subject"].value
   sender=form["sentfrom"].value
   message=form["message"].value
   

   mail=smtplib.SMTP(mailserver)
   mail.sendmail(sender,mailrecip,message)
   mail.quit


Thomas

Gerrit Holl wrote:
> 
> Andrew M. Kuchling wrote:
> > Gerrit Holl <gerrit.holl at pobox.com> writes:
> > > I'm writing some CGI scripts and I want the user to fill in their real email
> > > address. Checking this is more difficult than just look if it contains an '@'.
> >
> > Definitely.  In _Mastering Regular Expressions_, Jeffrey Frield
> > derives a regular expression for matching valid RFC-822 email
> > addresses.  Perl versions can be downloaded from
> > http://public.yahoo.com/~jfriedl/regex/code.html.
> 
> Perl :-(... Well, I'll play with re.compile().
> 
> > The version in the PCRE test suite begins:
> >
> > /[\040\t]*                    # Nab whitespace.
> > (?:
> > \(                              #  (
> > [^\\\x80-\xff\n\015()] *                             #     normal*
> > (?:                                 #       (
> [cut]
> >
> > ... and so on, lasting for 593 lines in all.
> 
> 593 lines!? I think I'll be happy with the input some faster then, the
> server it runs on has only 90 mHZ...
> 
> > But of course you can't
> > verify an address like foo at bar.com without actually sending e-mail to
> > it and seeing if it bounces.
> 
> Of course not. But people entering a wrong adres, just won't get answer. But
> mail with an address not matching the above, sometimes bounces.
> 
> regards,
> Gerrit.
> 
> --
> "People get annoyed when you try to debug them."
> 
>   -- Larry Wall (Open Sources, 1999 O'Reilly and Associates)
>   8:57pm  up  7:30, 14 users,  load average: 1.30, 1.23, 1.11

-- 
--------------------------------------------------------------------
                      Rock and Rule
             Zope Rocks -- http://www.zope.org
           Python Rules  -- http://www.python.org    
--------------------------------------------------------------------
Thomas McMillan Grant Bennett      Appalachian State University
Computer Consultant II             University Library
bennettt at am.appstate.edu          
http://www.library.appstate.edu/webmaster/
Voice:  828 262 6587	           FAX:    828 262 3001

Windows 95 is a 32-bit extension to a 16-bit patch for an 8-bit
operating system that was originally coded for a 4-bit microprocessor.
 - Chris Dunphy     Boot Magazine



More information about the Python-list mailing list