Validating an email address

Ben Finney bignose+hates-spam at benfinney.id.au
Fri Dec 9 17:59:40 EST 2005


Tom Anderson <twic at urchin.earth.li> wrote:
> A hoary old chestnut this - any advice on how to syntactically
> validate an email address?

Yes: Don't.

    <URL:http://www.apps.ietf.org/rfc/rfc3696.html#sec-3>

The only validation you should be doing before sending the message is
on the domain part. Since there are records available in DNS to
verify, you can check those. Is there an MX record? Is the address
valid? Do the mappings both way for that record make sense?

Please, don't attempt to "validate" the local-part. It's not up to you
to decide what the receiving MTA will accept as a local-part, and
(short of asking the MTA which most of them disable due to abuse by
spammers) you can't find out without just delivering the message.

So, once you've determined that you can reach the MX host, and that it
actually *is* the MX host for the domain, just deliver the message.

-- 
 \     "Those who can make you believe absurdities can make you commit |
  `\                                         atrocities."  -- Voltaire |
_o__)                                                                  |
Ben Finney



More information about the Python-list mailing list