Hi All,
Background: We use SendMail function (given below) to send emails to users. The email address are obtained as ouptut of a stored procedure in sybase.
We have defined a SendMail function as below in a .pm file and it is used in a .pl script.
Code Snippet:
sub SendMail
{
my (
$Message ,
$Subject ,
$To,
$CC
) = @_;
my ($sec, $min, $hour, $mday, $mon, $year) = localtime(time) ;
my $PgmName = "$hour:$min:$sec" ;
Log( "\nRecepients To: << $To >>\n" ) ;
Log( "\nRecepients CC: << $CC >>\n" ) ;
open(SENDMAIL, "|/usr/lib/sendmail -oi -t")
|| die "Can't fork for sendmail: $!\n";
#Content-Transfer-Encoding: quoted-printable
print SENDMAIL << "EOF";
From: $MAIL_FROM
Date: $PgmName
To: $To
CC: $CC
Subject: $Subject
Content-Type: text/html; charset="iso-8859-1"
$Message
EOF
close(SENDMAIL) || die "sendmail didn't close nicely";
if( $? !=0 )
{
Log("System Mail Failed");
}
else
{
Log ("Mail Sent Successfully");
}
}
The above SendMail is called in a perl script.
Issue:
Lets say we have 10 email address to which emails has to be send, and the 5th email address's mail box is no longer available though the email address is a valid one. Henceforth the sendmail function fails with "
sendmail didn't close nicely " message and email is not send to the rest of the people.
Expected Resolution Options
i) Validate whether the mailbox is still active. OR
ii) Prevent the sendmail from failing & continue to send the mail to the other people.
Kindly provide a possible solution. Thanking All in advance for your time.