Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

email pdf file - file damaged

by madison.sacd (Novice)
on May 07, 2007 at 06:52 UTC ( [id://613890]=perlquestion: print w/replies, xml ) Need Help??

madison.sacd has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks, I am trying to send email with pdf file via catalyst::plugin::email module.
However, after I check the email and download the attatched pdf file, I just got "file damaged" message.
I am sure the original pdf file can be opened normally.
Please help me to find what is wrong with my code. Thanks!
my @parts = ( Email::MIME->create( attributes => { content_type => 'application/pdf', encoding => 'quoted-printable', name => 'document.pdf', }, body => io( 'document.pdf' )->all, ), Email::MIME->create( attributes => { content_type => "text/plain", disposition => "attachment", charset => "US-ASCII", }, body => "Hello there!", ), ); my $r = $c->email( header => [ From => 's4@student.tku.edu.au', To => 's3@student.tku.edu.au', Subject => 'Hello!' ], parts => [ @parts ], );

Replies are listed 'Best First'.
Re: email pdf file - file damaged
by Corion (Patriarch) on May 07, 2007 at 07:00 UTC

    I have my reservations about IO::All, especially once you move from a hardcoded filename to anything variable because it reopens the security hole that was fixed by introducing the three argument form of open. Additionally, my guess is that you're running all of this under Windows and that IO::All doesn't know about binmode. From delving into the code of IO::All::File and IO::All, maybe you could alleviate this by using

    body => io( 'document.pdf' )->binary(1)->all,

    but I would entirely stay away from IO::All for it heaps too much magic onto magic and relies on the undocumented assumptions made by Ingy.

    Also see Mumble file mumble corrupt by jmcnamara

      Thanks for the reply but after modify, I still couldn't open the attached pdf file. I am running this under fedora 6. Any other suggestion? BTW, If you entirely stay away from IO::All, what method would you call when you want to attach a file to email?

        I would maybe use File::Slurp::slurp or write my own file slurper:

        sub slurp { open my $fh, "<", $_[0] or die "Couldn't open '$_[0]' for reading: $!"; binmode $fh; local $/; my $result = <>; };

        Maybe your (Content-)Encoding of quoted-printable is inappropriate for the type of file you're sending? I would think a Content-Encoding that uses base64 would be better maybe, if Email::Simple supports such. But then, I use MIME::Lite for most of my mailing needs.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2025-11-11 02:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What's your view on AI coding assistants?





    Results (67 votes). Check out past polls.

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.