Email::Valid does not actually attempt delivery. From its documentation:

This module determines whether an email address is well-formed, and optionally, whether a mail host exists for the domain.

Please note that there is no way to determine whether an address is deliverable without attempting delivery (for details, see perlfaq 9).

So, let's start today's SMTP lesson:

  1. When you send an e-mail message, you check to see if there's an MX record in DNS for the domain. If there isn't, you check to see if there's an A record in DNS.
  2. You then attempt to connect to port 25 of whatever host you found.
  3. Once you connect, you send HELO host.domain.tld (I won't get into EHLO (extended hello) at this time).
  4. In the old days (before spammers started abusing it), you could use VRFY or EXPN to test an e-mail address. But it's a rare chance of that happening these days. So, we have to send a message. You start by telling who the message is being sent from: MAIL FROM: sender@your.domain.tld
  5. In the next line, you tell who it's going to: RCPT TO: recipient@host.domain.tld
  6. And then you send you message. You send the line DATA and then the header of your message, a blank line, the body of the message, and then, on a line by itself, a single period.
  7. You then disconnect, by sending QUIT (unless you have more mail for that domain, in which case, you go back to 'MAIL FROM:').

Depending if the address is valid, you may get a response back from the mail server immediately (or you may not find a host, or be able to connect to port 25, letting you know something's wrong). It's also possible that the server you connected to has no idea about the final mail delivery, and is just there for load balancing, virus scanning, spam filtering, or something else where it doesn't know at this point that the recipient is over quota.

(of course, you wouldn't actually do all that by hand, I just needed to explain the steps... you should use Net::SMTP or one of the other mail sending modules in CPAN ... see How do I send e-mail from my Perl Program?)

If the email is found to be undeliverable, it will send a message to the envelope-from. (that's the email address in the 'MAIL FROM' line, which doesn't necessarily need to be the same as the 'From' header.) So, you have to send out the messages with a valid e-mail address as the recipient from, and then have some sort of process to connect to that account (see Net::POP3 or Net::IMAP::Simple) and check for errors. (or spam collecting up). You could also use something to process the mail on the mail server, potentially (see What're some good ways of notifying a perl script of an incoming email?)

So um...you'd probably do better just reading perlfaq9

Update: I should probably mention -- most e-mail servers will attempt to deliver messages to servers that are down. (ie, you can't connect on port 25). You might get a message that it's having problems after a few hours, but you can't depend on it. Sendmail (which is so widespread we'll use as our standard) sends its final 'I've given up' message after 5 days. You also run the risk of the e-mail being dropped by any server, thinking that your message is spam, or a virus, or just because of problems. So remember -- it can take almost a week to go through, and you can't be sure that you'll get an error message if it doesn't go through.


In reply to Re^2: Yet Another E-mail Validation Question by jhourcle
in thread Yet Another E-mail Validation Question by tanger

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.