#!/usr/local/bin/perl use CGI qw(:all); use Net::SMTP; # Checks email to see if it's active print header; gatheremails(); results(); ## GATHERS EMAILS sub gatheremails { # The first element of the array is my valid email, the others are dummies. @emails = ('jhess@wilcoxassoc.com','jhess1@wilcoxassoc.com','jhess2@wilcoxassoc.com'); foreach $email(@emails){ checkit(); } } ## CHECK THE EMAIL BY DOING A MAILSEND ## WITHOUT REALLY SENDING ANYTHING sub checkit{ ## SMTP BEGIN $smtp = Net::SMTP->new('mail.wilcoxassoc.com'); # connect to an SMTP server $smtp->mail('webmaster@wilcoxassoc.com'); # use the sender's address here $smtp->to($email) || addinvalid($email); # recipient's address # $smtp->data(); # Start the mail $smtp->quit; # Close the SMTP connection # If the flag shows it's not a bad email # then put in $email into the @valid array. if ($emailisbad ne "1"){ # GROWS AN ARRAY OF VALID EMAILS push(@valid,$email); } # Reset the flag to 0 for next email $emailisbad = "0"; } # PRINTS THE RESULTS TO THE BROWSER sub results{ print "

Check for Active Emails

"; print "

Active Email Addresses:"; print "
----------------------
"; if (@valid){ foreach $valid(@valid){ print "

  • $valid
  • "; } } print "

    Inactive Email Addresses:"; print "
    ----------------------
    "; if (@invalid){ foreach $invalid(@invalid){ print "

  • $invalid
  • "; } } } # GROWS AN ARRAY OF EMAILS THAT ARE INVALID sub addinvalid{ my ($errmsg) = @_; push(@invalid,$email); $emailisbad = "1"; }