use strict ; use Net::SMTP ; use warnings ; use Sys::Hostname ; my $SRV = hostname ; my $MAILSRV1 = "smtp1.domain.com" ; # actually smtp1.domain.com, smtp2.domain.com, smtp3.domain.com my $MAILSRV2 = "backup.domain.com" ; # the backup just incase. my $smtp = Net::SMTP->new($MAILSRV1, Hello => $SRV, Timeout => 30,Debug => 1) or print "$! \n"; if(!defined($smtp) || !($smtp)) { print "SMTP ERROR: Connection timeout\n"; my $smtp = Net::SMTP->new($MAILSRV2, Hello => $SRV, Timeout => 30,Debug => 1) or print "$! \n"; print "Trying backup email server to send email\n"; } else{ print "Using primary email server to send email\n" ; } $smtp->mail("sender\@domain.com") ; my @emails = ("reciepiant1\@domain.com", "reciepiant2\@domain.com") ; my $subject = "test subject"; my $content ="test data \n") ; my $whoareu = smtp->domain() ; $smtp->to(@emails) ; $smtp->recipient(@emails) ; $smtp->data() ; $smtp->datasend("Priority: Urgent\n") ; $smtp->datasend("Importance: high\n") ; $smtp->datasend("TO: @emails\n") ; $smtp->datasend("Subject: $subject\n") ; $smtp->datasend("$content\n") ; $smtp->datasend("$whoareu\n") ; $smtp->dataend() ; $smtp->quit ; print "The mail server that responded was $whoareu \n" ; exit ;