Beefy Boxes and Bandwidth Generously Provided by pair Networks RobOMonk
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Problems with MIME::Lite Attachements

by BaldPenguin (Friar)
on Aug 11, 2005 at 13:23 UTC ( [id://483050]=perlquestion: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.

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

Fellow Monks, I am trying to send an email with an attachment. The attachment is an ExcelML (XML) file:
## snippet-begin ## my $msg = MIME::Lite->new( 'From' => $param{'from'}, 'To' => $param{'email'}, 'Subject' => 'Your Report - '.$param{'startdate'}.' to '.$param{'e +nddate'}, 'Type' => 'mulitpart/mixed', ); $msg->attach( 'Type' => 'TEXT', 'Data' => 'Here is the Report requested for dates '.$param{'startdate'}. +' to '.$param{'enddate'}, ); $msg->attach( 'Type' => $mime_type, 'Disposition' => 'attachment', 'Encoding' => 'quoted-printable', 'Filename' => 'provider_report'.$param{'format'}, 'Data' => $attachment, ); $msg->send; ## snippet-end ##
$attachment is the XML data, $mime_type has been tried as 'application/vnd.ms-excel', 'text/xml', and 'text/plain', I have also tried binary, base64, and 8bit encoding in addition to quoted-printable.

I get the error 'no data in this part', when running my script. According to the module, that error is sent when the data cannot be encoded.

I have also tried sending the data as a filehandle, and have tried sending plain old XML

Anyone else seen/overcome this error?

Don
WHITEPAGES.COM | INC
Everything I've learned in life can be summed up in a small perl script!

Replies are listed 'Best First'.
Re: Problems with MIME::Lite Attachements
by BaldPenguin (Friar) on Aug 11, 2005 at 13:40 UTC
    Answering my own question, the error was actualy indicating that the primary message was blank. In error I tried to attach to attachments to a blank message.
    my $msg = MIME::Lite->new( 'From' => $param{'from'}, 'To' => $param{'email'}, 'Subject' => 'Your Report - '.$param{'startdate'}.' to '.$param{'e +nddate'}, 'Type' => 'mulitpart/mixed', 'Data' => 'Here is the Report requested for dates '.$param{'startdate'}. +' to '.$param{'enddate'}, );
    Changing the initial instantiation to the above fixed the error!

    Don
    WHITEPAGES.COM | INC
    Everything I've learned in life can be summed up in a small perl script!
Re: Problems with MIME::Lite Attachements
by borisz (Canon) on Aug 11, 2005 at 13:44 UTC
    I guess your attachment file is in utf8 format. Try to read the data in raw format. with binmode.
    my $attachment; { open my $fh, "<$filename" or die $!; binmode $fh; local $/; $attachment = <$fh>; }
    Boris
      You are correct that the data is in utf-8, but the data is generated without any file reads. The filehandle I tried was IO::Scalar.

      Don
      WHITEPAGES.COM | INC
      Everything I've learned in life can be summed up in a small perl script!
Re: Problems with MIME::Lite Attachements
by dorko (Prior) on Aug 11, 2005 at 14:32 UTC
    Was the file you were trying to attach open in MS Excel at the point in time you ran the script? If so, sometimes Excel locks the file such that other programs can't read it and they end up with a "file" with nothing in it.

    It might not be your problem, but it's worth thinking about.

    Cheers,

    Brent

    -- Yeah, I'm a Delt.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://483050]
Approved by kwaping
help
Sections?
Information?
Find Nodes?
Leftovers?
    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.