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: - 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.
- You then attempt to connect to port 25 of whatever host you found.
- Once you connect, you send HELO host.domain.tld (I won't get into EHLO (extended hello) at this time).
- 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
- In the next line, you tell who it's going to: RCPT TO: recipient@host.domain.tld
- 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.
- 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.
| [reply] |
Also, I've been hearing a lot about Email::valid on this board, but no one seems to recommend using Email::Valid::Loose.
I suspect that's because most e-mail addresses are genuinely valid, and Email::Valid is fine for most circumstances.
Doesn't it make more sense since it can verify a whole entire range of e-mail addresses?
According to the Email::Valid::Loose docs the kind of invalid addresses it accepts are often used by Japanese telcos for e-mailing mobile phones. They don't seem to be common anywhere else, so I guess most people (especially those not running Japanese-targetted websites) don't worry about this.
I know a few people who have e-mail addresses that containt "." afront of the "@" , ex. joe.smith@comcast.com
The dot in that address is valid, because there is "smith" between it and the at sign. It's very easy to check that Email::Valid does indeed accept it as valid (and hence that Email::Valid::Loose isn't necessary to allow it through):
$ perl -wMEmail::Valid -le "print scalar Email::Valid->address('joe.smith@example.com')"
Whereas the sample invalid address from the Email::Valid::Loose docs does not validate with Email::Valid:
$ perl -wMEmail::Valid -le "print scalar Email::Valid->address('read_rfc822.@docomo.ne.jp')"
Apparently Email::Valid::Loose would allow that through, but I've never felt the desire to check: putting a dot directly before the at sign seems completely pointless to me, and since it violates the standard I'm not going out of my way to assist anybody doing this.
Smylers
| [reply] [d/l] [select] |