Validating an email address

Discussion in 'Python' started by Tom Anderson, Dec 9, 2005.

  1. Tom Anderson

    Tom Anderson Guest

    Hi all,

    A hoary old chestnut this - any advice on how to syntactically validate an
    email address? I'd like to support both the display-name-and-angle-bracket
    and bare-address forms, and to allow everything that RFC 2822 allows (and
    nothing more!).

    Currently, i've got some regexps which recognise a common subset of
    possible addresses, but it would be nice to do this properly - i don't
    currently support quoted pairs, quoted strings, or whitespace in various
    places where it's allowed. Adding support for those things using regexps
    is really hard. See:

    http://www.ex-parrot.com/~pdw/Mail-RFC822-Address.html

    For a level to which i am not prepared to stoop.

    I hear the email-sig are open to adding a validation function to the email
    package, if a satisfactory one can be written; i would definitely support
    their doing that.

    tom

    --
    Women are monsters, men are clueless, everyone fights and no-one ever
    wins. -- cleanskies
     
    Tom Anderson, Dec 9, 2005
    #1
    1. Advertising

  2. Tom Anderson

    Ben Finney Guest

    Tom Anderson <> 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
     
    Ben Finney, Dec 9, 2005
    #2
    1. Advertising

  3. Tom Anderson

    Tom Anderson Guest

    On Sat, 10 Dec 2005, Ben Finney wrote:

    > Tom Anderson <> 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 IETF must have updated that RFC between you posting the link and me
    reading it, because that's not what it says. What it says that the syntax
    for local parts is complicated, and many of the variations are actually
    used for reasons i can't even imagine, so they should be permitted. It
    doesn't say anything about not validating the local part against that
    syntax.

    > 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,


    Absolutely not - it's up to the IETF, and their decision is recorded in
    RFC 2822.

    tom

    --
    Whose house? Run's house!
     
    Tom Anderson, Dec 10, 2005
    #3
  4. Tom Anderson

    Mike Meyer Guest

    Tom Anderson <> writes:
    > On Sat, 10 Dec 2005, Ben Finney wrote:
    >> 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,

    > Absolutely not - it's up to the IETF, and their decision is recorded
    > in RFC 2822.


    Wrong. The IETF dictates what your MTA *must* accept, not what it will
    accept. It's perfectly legal to accept more than what the IETF says is
    legal. In fact the rule of thumb for interoperability (on the off
    chance that anyone still cares about such) is "be generous in what you
    accept, and strict in what you send", so you're even encouraged to
    accept more than what the IETF says you have to.

    If you didn't generate the address, you have no way of knowing if the
    the receiving MTA will accept it or not without actually trying
    it. Rejecting an address because you don't like it could break
    perfectly functional email addresses.

    <mike
    --
    Mike Meyer <> http://www.mired.org/home/mwm/
    Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
     
    Mike Meyer, Dec 10, 2005
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    2
    Views:
    5,944
  2. cemcat
    Replies:
    1
    Views:
    9,164
    Siva M
    Dec 19, 2005
  3. Jean-Paul Calderone

    Re: Validating an email address

    Jean-Paul Calderone, Dec 9, 2005, in forum: Python
    Replies:
    0
    Views:
    354
    Jean-Paul Calderone
    Dec 9, 2005
  4. Zeynel
    Replies:
    1
    Views:
    583
    alex23
    Dec 6, 2010
  5. Replies:
    5
    Views:
    275
    Dr John Stockton
    Dec 23, 2005
Loading...

Share This Page