Dear Monks,

I have a daemonized Script (using Daemon::Simple) that uses Mail::Sender to send mails, mostly with one PDF doc as attachment.

The script normally works fine, but once in while it hangs in the Attach method, and does nothing until I restart it.

Below is the method in the script, that sends the mails, it is called from the scripts main loop and uses an external SMTP server. Have you any suggestions?

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.$servi +ce_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 = <FILE>; close FILE; local $/ = $linesep; my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = local +time($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) && ret +urn (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) && re +turn (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 localtim +e ($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::Send +er::Error\n".Dumper($rc)); } } else { $Log->error("cannot open file for reading: $tpl_email_feedback: +$!"); $retcode = (0==1) } return $retcode; }

Thanks in advance, Michael

In reply to Mail::Sender hangs once in a while by MichaelMeyer

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.