Hi all,
I have a script that basically waits for 2 files to be delivered to it,
then it processes the 2 files, inserts them into the database and then
starts sending information. After information is sent, it deletes the record
from the database and increments a counter. I do a fork in the subroutine
that does the sending / deleting portion. What I've come to notice is that
if I do this once, it sends everything fine and the data is correctly erased
from the database. The next time I do this, it runs, doesn't complain about
any errors but it doesn't do the send and it doesn't perform the delete.
Here is the sending portion of the code:
sub Send_Mail
{
my @fields = ();
my $ServerName = "mail.dat-e-base.net";
my $retry_counter = 0;
my $sender = new Mail::Sender;
foreach $item (@_)
{
chomp;
push(@fields,$item);
}
$temp = scalar @fields;
### Get HTML ###
$html_message = "";
$query_html = "SELECT HTML_MESSAGE FROM broadcast where EMAIL_ID =
'$fields[9]'";
$sth_html = $dbh->prepare($query_html);
$rc_html = $sth_html->execute;
while(($Temp) = $sth_html->fetchrow)
{
$html_message = $Temp;
$html_message =~s/\\\'/'/g;
}
$temp_html = $html_message;
$rc_html = $sth_html->finish;
### Get TEXT ###
$text_message ="";
$query_text = "SELECT TEXT_MESSAGE FROM broadcast where EMAIL_ID =
'$fields[9]'";
$sth_text = $dbh->prepare($query_text);
$rc_text = $sth_text->execute;
while(($Temp) = $sth_text->fetchrow)
{
$text_message = $Temp;
$text_message =~s/\\\'/'/g;
}
my $temp_text = $text_message;
my $rc_text = $sth_text->finish;
unless ($pid = fork)
{
### Get Info To Match ###
my $counter = 0;
if($fields[8] ne "T")
{
$temp_text =~s/##NAME##/$fields[3]/g;
$temp_text =~s/##EU##/$fields[6]/g;
do
{
if(eval {($sender)
->Open({smtp => $ServerName,
to => $fields[4],
from=> '[EMAIL PROTECTED]',
fake_from=>$fields[1],
subject => $fields[0]})
->SendLineEnc($temp_text)
->Close
}) { $retry_counter = 4;} # success
else { $retry_counter++;}
} until $retry_counter >= 2;
}
else # mixed html and plain text
{
$temp_html =~s/##NAME##/$fields[3]/g;
$temp_html =~s/##EU##/$fields[6]/g;
$temp_text =~s/##NAME##/$fields[3]/g;
$temp_text =~s/##EU##/$fields[6]/g;
MIXED:
do
{
if(eval {($sender)
->OpenMultipart({smtp=>$ServerName,
to => $fields[4],
from=> '[EMAIL PROTECTED]',
fake_from=>$fields[2] . "<$fields[1]>",
subject => $fields[0],
multipart => 'alternative',
Boundary =>'----_MIME-Boundary-1_--'})
->Body({ctype=>'text/plain',msg => $temp_text})
->Body({ctype=>'text/html',msg => $temp_html})
->Close
} > 0) {
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime;
$year = $year + 1900;
my $finish_date = $year . "-" . $mon . "-" . $mday;
### Insert into Log Table ###
my $querylog = "insert into log
(LOG_ID,EU,EMAIL,DATE_PROCESSED) values(NULL,?, ?, ?)";
my $sthlog = $dbh->prepare($querylog);
my $rclog =
$sthlog->execute($fields[6],$fields[4],$finish_date);
$retry_counter = 4;
$counter++;
} # success
else
{
$retry_counter++;
if ($retry_counter >=2)
{
$counter++;
}
else
{
goto MIXED;
}
}
} until $retry_counter >= 2;
}
########### Remove User Info From Database ##############
my $query3 = "DELETE FROM maildata WHERE EU = '$fields[6]' and
EMAIL_ID='$fields[9]'";
my $sth3 = $dbh->prepare($query3);
my $rc3 = $sth3->execute();
$retry_counter = 0;
exit 0;
}
waitpid($pid,0);
}
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]