Sending a file as an attachment Mime:Lite file corrupt

Posted on 2009-07-09
Last Modified: 2012-05-07
I Iam trying to send an email with a PDF attachment, my script works but when I get the mail and I try to open it it says message was corrupted and itdoes not open it, I tried plaing with the Encoding trying different setting with no luck, could you help me?

use MIME::Lite;
$message = MIME::Lite->new(
           From     => '',
           To       => ',
           Subject  => "PDF file",
           Type     => "multipart/mixed",
           Data     => "pdf file attached");
           Type     => "application/pdf",
           #Encoding => "base64",
           Disposition => 'Attachement',
           Path     => "/tmp",
           Filename => "HelloWorld.pdf");

Open in new window

Question by:ricuff
  • 3
  • 2

Expert Comment

by:Suhas .
ID: 24812040
can you try with attached code format

the only difference is

a line added in code with MIME::Lite->send()...


use MIME::Lite;
            my $message = MIME::Lite->new(
                        From     => '' ,
                        To       => '' ,
                        #Bcc                 => '',
                        Subject  => 'your attachment in this mail',
                        Type     => 'text/plain',
                        Encoding => '8bit',
                        Data     => "Dear Sirs,\nBest regards,\nbla bla"
    my ($mime_type, $encoding) = ('application/octet-stream', 'base64');
            $message->attach (
                        Type     => $mime_type ,
                        Encoding => $encoding ,
                        Path     => '/absolute/path/to/the/folder/containing/my.xls',
                        Filename => 'MyExcel.xls'
             MIME::Lite->send('smtp', 'external path', Timeout => 20);#should enter the internet smtp address

Open in new window


Author Comment

ID: 24812290
Hi I tried your code but it gives the same error

Accepted Solution

Suhas . earned 125 total points
ID: 24812371
it worked without any issues for me for pdf,xls and txt format.

in 25th line of my code type '/tmp/helloworld.pdf' instead of '/tmp'

and in line 29 for 'external path' you need to mention the smtp address



Author Comment

ID: 24812505
yes It works, after chenging the line "in 25th line of my code type '/tmp/helloworld.pdf' instead of '/tmp'" as you said it sends the attachment and it opens regiularly with acreobat reader


Expert Comment

by:Suhas .
ID: 24812538
Thanks for the points..


Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
hard perl script 16 156
Convert grep lines to perl 6 35
PHP pack() : What exactly is meant by signed char and unsigned char? 7 103
quoting a comma separated list 20 84
I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
In a recent question ( here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

815 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now