Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

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 => 'WirelessDataServices@dobson.net', 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/vnd.ms-excel', Path => '/usr/local/reports/wds/tims_rept/WDS.xls', Id => 'WDS.xls', ); $msg->send('smtp','smtp.dobson.net');

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
jim-dot-babcock-at-usa-dot-com

Comment on Mime::Lite attach issue
Download Code
Re: Mime::Lite attach issue
by Anonymous Monk on Mar 12, 2013 at 18:33 UTC
    This was found here: http://www.unix.com/shell-programming-scripting/12995-perl-emailing-multiple-files-attachment.html 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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (16)
As of 2014-09-30 19:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (383 votes), past polls