[Zope] Email address validator?
Bruce Eckel
Bruce@EckelObjects.com
Sun, 25 Nov 2001 07:53:55 -0800
>Bruce Eckel wrote:
>
>>Thanks! I spent a bit of time refactoring it. Also, I decided that if it
>worked it would return the address, otherwise it would return None to
>indicate failure.
>>
>[refactored code snipped]
>
>Interesting style! Thanks! Always good to learn a new thing or two.
> Do you plan to work on the other part about querying the SMTP server
>about whether it accepts mail for [email_address]?
>
>-- Jim Washington
Actually, that part is relatively automatic: when you try to send an email=
it will throw various types of exceptions, and if there's something wrong=
with the sender name, you get a SMTPSenderRefused exception. So this code:
try:
self.MailHost.send("This is a test",
'Bruce@EckelObjects.com', form_data['email'],
"%s\n\n" % form_data['seminar-id'])
except smtplib.SMTPSenderRefused:
get_transaction().abort()
return "Invalid email address: please press your browser's=
'back' key and correct it"
(Or something fancier -- I've forgotten how to set up the return value so=
that it's HTML) will do the trick. Notice the
get_transaction().abort() which Chris Withers told me about -- it causes=
the transaction to be rolled back, which would normally occur when an=
exception goes through, but since I'm catching the exception I have to do=
it myself.
I'm not sure who is throwing the SMTPSenderRefused -- it may just be some=
code in the MailHost object that's checking the address, or it may be the=
mailer itself, in which case one could argue that the other code we've=
been bouncing around may not be necessary.
Most current information can be found at:
http://www.mindview.net/Etc/notes.html
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
Bruce Eckel http://www.BruceEckel.com
Contains free electronic books: "Thinking in Java 2e" & "Thinking in C++=
2e"
Please subscribe to my free newsletter -- just send any email to:
join-eckel-oo-programming@earth.lyris.net
My schedule can be found at:
http://www.mindview.net/Calendar
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D