sub send_statusmail ($$$$$) { my $retcode = (0==0); my $task_id = shift; my $task_info = shift; my $errmsg = shift; my $date_sent = shift; my $time_sent = shift; my $email_server = 'smtp.xxx.net'; my $email_login = 'xxx@xxxx.xx'; my $email_pass = 'xxxxxxxx'; my $email_from = 'noreply@xxx.xx'; my $base_dir = '/path/to/workdir'; my $tpl_email_feedback = "$base_dir/tpl/email_feedback_text.$service_name.tpl"; my $subj = "Ihr Sendebericht von xxxxxx.xx"; my ($to, $adminbcc); if ($errmsg !~ /Robinson/) { $to = $task_info->{'task_statusemail'}; $adminbcc = 'xxxxx@xxx.xx'; } else { $to = 'xxxxx@xxx.xx'; $adminbcc = 'xxxxx@xxx.xx'; $subj = "$service_name: Robinson"; $task_info->{'task_statusemail_doattach'} = 1; } my $body; my $sent = ($errmsg eq 'OK' ? 'erfolgreich':'NICHT'); # create mail body if (open FILE, "<$tpl_email_feedback") { my $linesep = $/; local $/ = undef; $body = ; close FILE; local $/ = $linesep; my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($task_info->{'task_ctime'}); $mon = "0$mon" if $mon < 10; $mon = "0$mon" if $mon < 10; $mon = "0$mon" if $mon < 10; my $timestr = sprintf("%02d.%02d.%4d %02d:%02d:%02d", $mday, ++$mon, ($year + 1900), $hour,$min,$sec); $body =~ s/<-STATUS->/$sent/isg; $body =~ s/<-ERRORMSG->/$errmsg/isg; {'task_faxnummer_display'}/isge; $body =~ s/<-DATE->/$timestr/isg; $body =~ s/<-DATE-SENT->/$date_sent $time_sent/isg; $body =~ s/<-IP->/$task_info->{'task_ip'}/isge; my $attach_file = get_filename($task_id, $service_name); $Log->debug("found attach_file $attach_file"); $Log->debug("connecting to mail server..."); # now use Mail::Sender to send the status mail my $Sender = new Mail::Sender { 'smtp' => $email_server, 'auth' => 'LOGIN', 'authid' => $email_login, 'authpwd' => $email_pass, 'from' => $email_from, }; # log error and return false if not working $Log->debug(Dumper($Sender) . "\t" . $Mail::Sender::Error) && return (0==1) if not ref $Sender; $Log->debug("Creating Multipart mail..."); $retcode = $Sender->OpenMultipart({ 'to' => $to, 'bcc' => $adminbcc, 'subject' => $subj }); # log error and return false if not working $Log->debug(Dumper($retcode) . "\t" . $Mail::Sender::Error) && return (0==1) if not ref $retcode; $Sender->Body({ msg => $body }); if ($task_info->{'task_statusemail_doattach'}) { $Log->debug("attaching file..."); $Sender->Attach( {description => 'Ihr Dokument', ctype => 'application/pdf', encoding => 'Base64', disposition => 'attachment; filename="Fax '.scalar localtime ($task_info->{'task_ctime'}).'.pdf"; type="PDF Document"', file => $attach_file }); } else { $Log->debug("NOT attaching file"); } $Log->debug("sending mail to $to ($task_id)"); # actual sending if (my $rc = $Sender->Close()) { $retcode = (0==0); $Log->success("sent mail for task $task_id"); } else { $retcode = (0==1); $Log->error("could NOT send mail for task $task_id $Mail::Sender::Error\n".Dumper($rc)); } } else { $Log->error("cannot open file for reading: $tpl_email_feedback: $!"); $retcode = (0==1) } return $retcode; }