Solved

Sending a file as an attachment Mime:Lite file corrupt

Posted on 2009-07-09
5
547 Views
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     => 'me@mydomain.com',

           To       => 'someone@otherdomain.com,

           Subject  => "PDF file",

           Type     => "multipart/mixed",

           Data     => "pdf file attached");
 

$message->attach(

           Type     => "application/pdf",

           #Encoding => "base64",

           Disposition => 'Attachement',

           Path     => "/tmp",

           Filename => "HelloWorld.pdf");

$message->send;

Open in new window

0
Comment
Question by:ricuff
  • 3
  • 2
5 Comments
 
LVL 9

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()...

Cheers...
Suhas

#!/usr/bin/perl

use MIME::Lite;

 

            my $message = MIME::Lite->new(

 

                        From     => 'abc@abc.com' ,

                        To       => 'abc@abc.com' ,

                        #Bcc                 => 'xyz@xyz.com',

                        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

            $message->send;

Open in new window

0
 

Author Comment

by:ricuff
ID: 24812290
Hi I tried your code but it gives the same error
0
 
LVL 9

Accepted Solution

by:
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

cheers...
Suhas




0
 

Author Comment

by:ricuff
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

thanks
0
 
LVL 9

Expert Comment

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

Cheers...
Suhas
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

932 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

10 Experts available now in Live!

Get 1:1 Help Now