ttcuberat has asked for the wisdom of the Perl Monks concerning the following question:

Here's a fun one. Hoping someone has seen this issue before. I use the code below to create simple messages and attache .xls documents. The problem is that if there are multiple files attached to the email....the last file in the list will be truncated. It loses a few rows off the end during the transmission. The file is complete on the filesystem, but when opened from the email...it is not. Anyone ever seen this before?
$From = "\"$From_Name\" <$From_Who>"; + $msg = MIME::Lite->new( From => $From, To => $Recipient, Subject => $From_Msg, Type => 'TEXT', Data => $From_Body ); foreach (@files) { $msg->attach(Type => 'BINARY', Path => "$dir/$_", Filename => $_, Disposition => 'attachment' ); } $msg->send("sendmail", "/usr/lib/sendmail -t -oi -oem");

Replies are listed 'Best First'.
Re: mime::lite Problem
by vek (Prior) on Apr 10, 2003 at 07:10 UTC
    ttcberat, how many attachments are we talking about? I send 3 spreadsheets as attachments using code not too dissimilar to the following:
    my $mail = MIME::Lite->new(Subject => 'some_subject', Type => 'multipart/mixed'); # non MIME::Lite code here... my $msgBody = "some foo message"; $mail->attach(Type => 'TEXT', Data => $msgBody); #more non MIME::Lite code here... for my $attachment (@attachments) { my ($filePath, $fileName) = split (/:/, $attachment); $mail->attach(Type => 'application/octet-stream', Path => $filePath, Filename => $fileName, Disposition => 'attachment'); }
    To try and find out what is causing the problem, try dumping the 'non-sent' mail to a file:
    # necessary file opening code here... print SOME_FILEHANDLE $mail->as_string;
    The attachments should be base64 encoded, so you could try parsing the dumped file and use MIME::Base64 to decode the attachments and dump them to files. Then you can check to see if all attachments are complete. If they are then you know it's not your code or MIME::Lite that's the problem and can start looking at sendmail as the culprit.

    That idea is completely untested by the way so the usual YMMV disclaimer applies ;-)

    -- vek --
Re: mime::lite Problem
by bbfu (Curate) on Apr 09, 2003 at 23:09 UTC

    Some things to try might be to look at the source of the email. Perhaps the Content-Length is incorrect. You could also try using a different module, such as Mail::Sender, Mail::Send, etc. They should all have methods to attach files to the messages, and most of them are pure Perl (ie, they don't call out to sendmail).

    If a different module also exhibits the same problem, it might be caused by server problems.

    bbfu
    Black flowers blossom
    Fearless on my breath