Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Corrupted ZIP file using MIME::Lite

by rlambert7 (Acolyte)
on Dec 30, 2007 at 17:21 UTC ( [id://659645]=perlquestion: print w/replies, xml ) Need Help??

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

I'm am sending an email with an attached ZIP file to my AOL email address using MIME::Lite. I do receive the email with the ZIP file attached, but the ZIP file is corrupted. :(

Now, what probably comes first to mind is that the ZIP file must have been created in a corrupted state, or that AOL is corrupting it. Well, I've checked that. My application also FTP's the ZIP file to an FTP site. If I manually connect to the FTP site, download the ZIP to my PC, I can open it, and extract the contents, and all of it is just as I would expect. If I email the ZIP file from my PC at work to my AOL account using MS Outlook, I can logon to AOL, open the email, download the attached ZIP file, and open it. If I email, using my MIME::Lite code, the ZIP file to my work email address, Outlook says the ZIP file is corrupted. So, that seems to me to leave MIME::Lite as the problem.

The following is not my exact code, I won't have access to it for a while, but it's pretty close, as I pretty much cut-and-pasted this code from the example at CPAN, changing just the file names, email addresses, etc to my situation. BTW, you'll notice a "Debug=>1" in the code below. That causes a BUNCH of stuff to be spit out, and I don't see anything in that which would indicate a problem.

Final comment, for now. The "debug output" indicates that Content-Type-Encoding is 'base64'. I read somewhere else that MIME::Lite "knows" to set that based on the the "Type => 'application/zip' specification in the code.

Thanks for any insight you can provide on this

Here's the code:

### Create a new multipart message: $msg = MIME::Lite->new( From =>'me@myhost.com', To =>'you@yourhost.com', Cc =>'some@other.com, some@more.com', Subject =>'A message with 2 parts...', Type =>'multipart/mixed' ); ### Add parts (each "attach" has same arguments as "new"): $msg->attach( Type =>'TEXT', Data =>"Here's the ZIP file you wanted" ); $msg->attach( Type =>'application/zip', Path => $HOME, Filename =>'little.zip', Disposition => 'attachment' ); ### use Net:SMTP to do the sending $msg->send('smtp','some.host', Debug=>1 );

Replies are listed 'Best First'.
Re: Corrupted ZIP file using MIME::Lite
by kirillm (Friar) on Dec 30, 2007 at 19:48 UTC

    Hi,

    You're trying to attach your home directory:

    $msg->attach( Type =>'application/zip', Path => $HOME, # ^^^^^^^^^^^^^^^^^ <- here you try to attach $HOME Filename =>'little.zip', Disposition => 'attachment' );

    Probably you want Path to be "$HOME/little.zip"...

    Hope that helps.

    Greetz,
    Kirill

      No, that's not the problem. In the OP I said I am able to send and receive the email. It's just that the attached ZIP file is corrupted. Note that the MIME::Lite specification is "Path", not "Path/Filename". MIME::Lite has another specification for the file, which is "Filename".
        I believe you may be confused. The Filename attribute is only used to give the recipient a name for the attachment. The Path attribute should contain the full path to your zip file.

        For example,

        Path => '/home/rhesa/zips/small.zip', Filename => 'tiny.zip',
        would attach my file named "small.zip", but the recipient would see an attachment named "tiny.zip".

        Oh well. Here's a snip from MIME::Lite docs:

        Filename Optional. The name of the attachment. You can use this to supply a recommended filename for the end&#8208;user who is savi +ng the attachment to disk. You only need this if the filename at the end of the "Path" is inadequate, or if you’re using "Data" instead of "Path". You should not put path information in here (e.g., no "/" or "\" or ":" characters should be used). [...] Path Alternative to "Data" or "FH". Path to a file containing the data... actually, it can be any open()able expression. If it looks like a path, the last element will automatically be treated as the filename. See "ReadNow" also.

        Read these carefully...

        Have you tried my suggestion before you replied?

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2024-04-24 13:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found