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

Problem with Mime::lite and .doc files

by Anonymous Monk
on May 19, 2007 at 14:27 UTC ( [id://616323]=perlquestion: print w/replies, xml ) Need Help??

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

I'm trying to write a test script that will send a .doc file using the mime::lite. I had it working with a text file, but when I try with a .doc file, nothing happens. This is my code:
$msg = MIME::Lite->new( From =>'...@myhost.com', To =>'edja...@quirkyjapan.or.tv', Subject =>'A message with 2 parts...', Type =>'multipart/mixed'); ### Add parts (each "attach" has same arguments as "new"): $msg->attach(Type =>'BINARY', Data =>"Here's the GIF file you wanted"); $msg->attach(Type =>'application/msword', Path =>'test.doc'); $text = $msg->as_string; $msg->send; print "done";
I assume the mistake is in this line: $msg->attach(Type =>'application/msword', Thanks in advance.

Replies are listed 'Best First'.
Re: Problem with Mime::lite and .doc files
by pKai (Priest) on May 19, 2007 at 16:33 UTC

    The Type is only a hint to the receiving MUA. You can specify foo/bar and everything is fine, as long as the receiver knows what to do with objects of that type.

    You didn't specify your error symptoms beyond (…nothing happens…), but I would guess your MUA does not show you the generated "inline" Word document, which is an understandable decision.

    You might try to attach the document by

    $msg->attach(Type =>'application/msword', Path =>'test.doc', Disposition => 'attachment', );

    instead.

    At least the generated mail looks good to my eyes. Though it is a bit weird to send the main text base64-coded (i. e. BINARY). I would rather use Type => 'TEXT' there.

Re: Problem with Mime::lite and .doc files
by marto (Cardinal) on May 19, 2007 at 16:15 UTC
    The documentation for this module is very good IMHO. Try something like:
    #!/usr/bin/perl use strict; use warnings; use MIME::Lite; my $msg = MIME::Lite->new( From => 'sender@host.com', To => 'recipient@host.com', Subject => 'Word document attached', Type => 'multipart/mixed'); $msg->attach(Type =>'TEXT', Data => "Here's the Word document you wanted" ); $msg->attach(Type => 'application/msword', Path => 'test.doc'); $msg->send; print "done";

    I don't have Word installed, I tested this by sending it to my Gmail account which allowed me to open the word document in google docs. Your code has a variable $text which you don't seem to be doing anything with (in the code provided at least). Adding use strict; and use warnings; is always a good idea when you are having problems with your code. Check out PerlMonks FAQ if you have not already done so. If the code above results in any error messages post a reply letting us know what they are and someone will try to help you.

    Hope this helps

    Martin
Re: Problem with Mime::lite and .doc files
by wjw (Priest) on May 19, 2007 at 16:08 UTC
    After checking the docs for MIME::Lite which pointed to RFC-2046 (google search), it seems the suggested type might be application/octet-stream. Check out -> RFC-2046 which was pointed at by This.

    I did not dig into this much and assume you can get further details on your own.

    Good luck! :-)

    • ...the majority is always wrong, and always the last to know about it...
    • The Spice must flow...
    • ..by my will, and by will alone.. I set my mind in motion

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (3)
As of 2024-04-19 17:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found