sub SMTPMail { use Net::SMTP; # Not all versions of SMTO support authentication. my ($to, $from, $subj, $msg, $smtpserver) = @_; my $body = ""; my $error; eval { require MIME::Base64; require Authen::SASL; }; if ($@) { $error = system("ppm install MIME::Base64"); $error = system("ppm install Authen::SASL"); } ; my @dayofweek = (qw(Sun Mon Tue Wed Thur Fri Sat)); my @monthnames = (qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec)); my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday) = localtime(); $year += 1900; #Create an RFC compliant time stamp my $Date = sprintf("%s, %02d %3s %04d %02d:%02d:%02d CST",$dayofweek[$wday],$mday,$monthnames[$mon],$year,$hour,$min,$sec); # Make $to into an array if it's not one already if (!ref($to)) { @$to = split(/[,;]\s*/, $to); } # Make Email Header $body = "MIME-Version: 1.0\n" . "From: $from\n" . "To: " . join(',', @$to) . "\n" . "Date: ".$Date."\n" . "Subject: $subj\n\n" # Double \n . $msg . "\n"; my $smtp; # Open a SMTP session if(!($smtp = Net::SMTP->new($smtpserver))) { return "Could not connect to SMTP Server: $smtpserver "; } if (length($EmailAuth) > 0 && length($EmailPassword) > 0 ) { &LogFile("Email","Auth $EmailAuth"); my $error = $smtp->auth($EmailAuth,$EmailPassword) ; if (! $error) { return "Cannot authenticate as user $EmailAuth and/or bad Password for Email - Error $error - Check System Settings "; } } # Pass the 'from' email address, exit if error if (! ($smtp->mail( $from ) ) ) { return "Bad 'From', check your Account Information"; } # Pass the recipient address(es) if (!($smtp->recipient(@$to))) { return "Bad 'EmailTo'"; } # Send the msg $smtp->data( $body ); $smtp->quit; return 0; }