in reply to Creating a web application in Perl

Pinging a domain name is not an especially good indicator - there are a number of scenarios where a domain name will not respond to pings, but can accept mail.

So don't ping the domain. Use a Perl module like Net::DNS::Resolver to look up an MX record for the host; if there is no MX record, then look for an A/AAAA/CNAME record; if you've still not found a matching DNS entry, then the domain name probably can't receive mail.

use Net::DNS::Resolver; my $domain = 'example.com'; my $dns = Net::DNS::Resolver->new; my $valid = $dns->query($domain, 'MX') || gethostbyname($domain); printf( "You could %s send mail to %s.\n", ($valid ? "maybe" : "not"), $domain, );

Replies are listed 'Best First'.
Re^2: Creating a web application in Perl
by cavac (Prior) on Jan 07, 2012 at 13:37 UTC

    On a sidenote: Even if you the MX entry is valid, the mailserver is reachable and you are even to validate the email address by sending one one those "click here to validate" links, you can't besure it will work for more than a few minutes. There are more and more of this one-time email-address services available to avoid SPAM and all these annoying "you have registered at our site a few years ago so we constantly bombard you with our 'newsletter'" thingies.

    I'm currently teaching my private mailservers how to do that onetime address thingy for the same reasons...

    "Believe me, Mike, I calculated the odds of this succeeding against the odds I was doing something incredibly stupid… and I went ahead anyway." (Crow in "MST3K The Movie")