Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

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 all is quiet...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (7)
As of 2017-02-27 19:54 GMT
Find Nodes?
    Voting Booth?
    Before electricity was invented, what was the Electric Eel called?

    Results (392 votes). Check out past polls.