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

I'm trying to send a csv file as an attachment. The email sends just fine, and has the attachment, but some of the file is removed. It's almost like there is a size limit and it truncates the end of the file. The original is 56KB the emailed file is 48KB. I have tried with multiple different, though the same type of files.

Here is the code I'm using to send the email... though obviously with valid email addresses.

use MIME::Lite; MIME::Lite->send("smtp","mail.mine.com"); my $msg = MIME::Lite->new( From => 'some@thing.com', To => 'me@mine.com', Subject => 'A Report', Type => 'multipart/mixed', ); $msg->attach( Type =>'TEXT', Data => "This is your pretty report", ); $msg->attach( Type => 'text/csv', Path => 'file.csv', Filename => 'file.csv', Disposition => 'attachment' ) or die "Error adding file \n"; $msg->send;

Replies are listed 'Best First'.
Re: Email attachment being truncated.
by Neighbour (Friar) on Sep 12, 2012 at 13:08 UTC
    Make sure the filehandle (if generated from another place in the same script, or another script) is closed before you're trying to send it. Otherwise you'll be missing whatever's left in the file-io-buffer.
      I faced the same issue and closing the filehandle, just before sending mail, worked. Thanks!
      Thank you! That works!!
Re: Email attachment being truncated.
by Anonymous Monk on Sep 12, 2012 at 00:28 UTC

    Hi

    Have you tried sending different csv files? Have they all bveen truncated to the same size?
    What about ordinary text files?

    J.C.

Re: Email attachment being truncated.
by swampyankee (Parson) on Sep 12, 2012 at 01:49 UTC

    First would be to make sure that you're not having trouble with buffering: make sure the file is flushed. If that isn't the problem, try zipping the file.


    Information about American English usage here and here. Floating point issues? Please read this before posting. — emc

Re: Email attachment being truncated.
by nextguru (Scribe) on Sep 12, 2012 at 07:41 UTC
    I ran your code (with obvious changes of from/to addresses) and it worked fine for me with a 110kb csv file when sent to/from yahoo, gmail and corporate account. Can you try different email accounts to rule out that aspect?