Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

Mime::Lite attach issue

by jimbus (Friar)
on Apr 05, 2007 at 19:10 UTC ( #608534=perlquestion: print w/replies, xml ) Need Help??
jimbus has asked for the wisdom of the Perl Monks concerning the following question:

Update: This was solved with bart's help. I wasn't closing the file after I generated it. Thanks bart!

Hello, I've got a script that generates an Excel file using Spreadsheet::WriteExcel as well as some graphs with GD::Graph and tries to email them out using Mime:Lite.

The Excel document creates correctly, I can FTP it over and open it correctly, but the document attached to the email, though, is empty. Outlook claims the attachment is 64kb, but when I save it to disk, it is 0kb. The graphs all display in-line and the CSVs I'd been sending just as attachments before the requirements changed worked.

use MIME::Lite; my $msg = MIME::Lite->new( From => '', To => $props->{maillist}, Subject => "Wireless Data Weekly Report for $time\n", Type => 'multipart/mixed' ); $msg->attach(Type => 'text/html', Data => qq{ <img src="cid:sms.gif"><br> <img src="cid:wsb.gif"><br> <img src="cid:mms.gif"><br> <img src="cid:byte.gif"><br> <img src="cid:frate.gif"><br> } ); $msg->attach(Type => 'image/gif', Path => '/usr/local/reports/wds/tims_rept/sms.gif', Id => 'sms.gif', ); $msg->attach(Type => 'image/gif', Path => '/usr/local/reports/wds/tims_rept/wsb.gif', Id => 'wsb.gif', ); $msg->attach(Type => 'image/gif', Path => '/usr/local/reports/wds/tims_rept/mms.gif', Id => 'mms.gif', ); $msg->attach(Type => 'image/gif', Path => '/usr/local/reports/wds/tims_rept/byte.gif', Id => 'byte.gif', ); $msg->attach(Type => 'image/gif', Path => '/usr/local/reports/wds/tims_rept/frate.gif', Id => 'frate.gif', ); $msg->attach(Type => 'application/', Path => '/usr/local/reports/wds/tims_rept/WDS.xls', Id => 'WDS.xls', ); $msg->send('smtp','');

Above is the relavent code... if anyone has any ideas why I can't email this, please let me know... BTW, ls -l on the Path for the offending item shows a file sized 21504.

--Jimbus aka Jim Babcock
Wireless Data Engineer and Geek Wannabe

Replies are listed 'Best First'.
Re: Mime::Lite attach issue
by Anonymous Monk on Mar 12, 2013 at 18:33 UTC
    This was found here: This was really hard to find (google-fu may have been weak) so thought I should spread it around.. Make your message Type "multipart/mixed" and for the attachment:
    ... $msg->attach( 'Type' => 'application/octet-stream', 'Encoding' => 'base64', 'Path' => "<some Excel file here>" );

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://608534]
Approved by Corion
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (9)
As of 2016-10-26 08:42 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (337 votes). Check out past polls.