$smtp->recipients(@addresses, { Notify => ['SUCCESS','FAILURE','DELAY'] }); #### #!/usr/bin/perl # Use strictures use strict; use warnings; # Additional modules use Socket; use Net::DNS; use Net::SMTP; # At launch, ask for an email address print "Please enter an email address: "; my $address = ; # Break apart the address and do MX lookup against the # domain our ($userpart, $domainpart) = split /@/, $address; our $res = Net::DNS::Resolver->new(); our @mx = mx($res, $domainpart) or die "Cannot resolve $domainpart: $!\n"; #### for my $rr (@mx) { print $rr->preference, " ", $rr->exchange,"\n"; } #### # We assume that @mx contains something, since the die() # during MX resolution would have killed us by now for (@mx) { # It *would* be more elegant to test the primary server # in the event of round-robin MX or pick one in the # event of load-balanced MX, but I want to test for # any disparities in replies. my @mailservers = $rr->exchange; for my $mailserver (@mailservers) { # Connection plus EHLO my $smtp = Net::SMTP->new( Host => $mailserver, Hello => some.server.tld, Timeout => 30, Debug => 0 ) or die "Cannot connect to $mailserver!\n"; # MAIL FROM: $smtp->mail('me@somewhere.com'); # RCPT TO: my $response = $smtp->recipient($address); # Now go looking for response codes. On my system, # 1 = user valid, 0 = user invalid if ($response == 1) { # Do something, or return() something } else { # Do something, or return() something } # Be polite, RSET and QUIT properly $smtp->reset(); $smtp->quit(); # Slow down the rate between probes sleep(2); } }