Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: About validating mail id

by Corion (Patriarch)
on Feb 03, 2010 at 12:14 UTC ( [id://821137]=note: print w/replies, xml ) Need Help??


in reply to About validating mail id

Why? http://com.com is a valid web address and I suppose they also accept mail, so data@com.com could be a valid email address as could data@mach.com.com.

The best way to validate an email address is to send mail to it and have the recipient click a link in the mail.

Replies are listed 'Best First'.
Re^2: About validating mail id
by tirwhan (Abbot) on Feb 03, 2010 at 12:23 UTC
    data@com.com could be a valid email address as could data@mach.com.com

    Neither com.com nor mach.com.com have a valid MX record, and the A record IP for these domains does not accept an SMTP connection, so at the moment they are not valid email addresses. Unless, of course, a local mail server rewrites these addresses into something different, or someone turns on the mail server at those addresses in five minutes, in which case they most certainly are :-).

    I agree completely with the general point that these are "syntactically" correct email addresses and that testing for validity in the way the OP is doing is next to useless. For a more useful approach, he should see Email::Valid. For a regular expression that checks the syntactic validity of an email, check out the Mastering Regular Expressions book (warning, IIRC the regex has approximately the length of an entire page of printed text).


    All dogma is stupid.
      Neither com.com nor mach.com.com have a valid MX record, and the A record IP for these domains does not accept an SMTP connection, so at the moment they are not valid email addresses. Unless, of course, a local mail server rewrites these addresses into something different, or someone turns on the mail server at those addresses in five minutes, in which case they most certainly are :-)
      Just because an MX record isn't propagated to you doesn't mean it doesn't exists. Many companies and organisations have a DNS that looks differently internally than externally. Heck, even my local network consisting of a whopping 3 machines has an internal DNS different from the outside world.

      It's not possible to determine a given address exists. What you can do is check whether a given address is syntactically valid (surprisingly many strings are valid addresses - a valid address doesn't have to contain a '@' - this posting will contain many, many valid addresses). But it doesn't mean that an address that is syntactically (according to RFC 822 or any of its successors) invalid isn't deliverable.

      Another alternative is to send a message to see what happens. If you get a reply that looks like it was written by a human, it's probably a valid address. (Of course, it may have become invalid after the reply was send....). If you get a bounce, it may be invalid (but I can bounce messages from mutt).

      ucbvax!ibm4java!dec4javafan!javafan

        OK, I acknowledge I probably deserved getting the nits picked on my nitpicking node...

        Just because an MX record isn't propagated to you doesn't mean it doesn't exists.

        Which, to me, is irrelevant. If I can't resolve the MX and can't send mail to the A record of the domain, the email address is invalid (to me). If your point was that there is no such thing as a globally valid email address then we are in violent agreement.

        a valid address doesn't have to contain a '@'

        This is incorrect for email addresses. You can have a syntactically valid mailbox address (which may be delivered locally or rewritten/forwarded to a valid email address by your MTA) without the @, but a syntactically valid email address requires the @ to separate the local and domain part. See RFC5322.

        But it doesn't mean that an address that is syntactically (according to RFC 822 or any of its successors) invalid isn't deliverable.

        Weeell, most MTAs I know do check for syntactic validity(at least in the SMTP transaction, if not the message headers) and will not deliver to a syntactically invalid address. So regarding a syntactically invalid email address as generally undeliverable is good practice IMO, special circumstances for weird mail setups notwithstanding.


        All dogma is stupid.
A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://821137]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (5)
As of 2024-03-28 17:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found