in reply to Re^3: MIME::Lite and Multipart
in thread MIME::Lite and Multipart

I actually do use all those things, Its just all part of a larger mod_perl script and it isn't as easy to make workable snippet out of.

But if that would do it, here it is... I have the same exact problem when I run the below, whenever I try to set the type as I go, it fails with that "no data in this part". If I set the type to "multipart/alternative" when I create "my $message...." it works (but I don't get the attachment if there is one because it doesn't get switched to multipart/mixed)

#!/usr/bin/perl -w ###################################################################### # Libraries # --------- use strict; use warnings; use diagnostics; use MIME::Lite; use Email::Valid; # If we have a valid email address. my $to_email = 'youremail@somedomain.com'; my $email_valid = Email::Valid->new(mxcheck => 1,tldcheck + => 1); if ($email_valid->address($to_email)) { # Everything looks good, make up our message my $message = MIME::Lite->build ( From => $to_email, To => $to_email, Subject => 'This is the subject', #Type => 'multipart/alternative' If I default to thi +s then it never gets updated with a attachment. ); # Did we get a attachment? my $attachment = '/tmp/38293132401.pdf'; if (-e $attachment) { #$message->replace(Type => ''); # Tried this #$message->replace(Type => 'multipart/mixed'); # Tri +ed this $message->add(Type => 'multipart/mixed'); $message->attach( Type => 'AUTO', Path => $attachment, Filename => '38293132401.pdf', Disposition => 'attachment' ); } else { $message->add(Type => 'multipart/alternative'); } my $text_email = 'yadda yadda yadda'; my $html_email = '<em>yadda</em> <strong>yadda</strong> <u>yad +da</u>'; # Do up the message $message->attach(Type => 'TEXT', Data => $text_email ); $message->attach(Type => 'text/html', Data => $html_email ); $message->send('smtp','###.###.###.###',Debug=>1,Timeout=>60,P +ort=>26); }

Replies are listed 'Best First'.
Re^5: MIME::Lite and Multipart
by jakobi (Pilgrim) on Sep 29, 2009 at 19:38 UTC

    using use strict and then skipping it for a small code scrap is A TRAP. And this one got both of us.

    Re^3 actually _is_ the answer you were looking for. Let's rephrase it a bit, and I'll use your original scrap for speed's sake:


    Now why did you run in trouble with your scrap from Re^4: To me it looks like ::Lite HATES to be invoked without a Type. Resulting in an excess dummy mime part with undef'd data (this is a new, different bug apart from our initial issue), which isn't silently suppressed by send (finally triggering the same abort as before). Which IMHO should be considered a bug in Mime::Lite.

    Note the use of Data::Dumper for debugging (or use perl -d and suitable breakpoints, but I'm too lazy for that)

      Thanks Jakobi, I understand the issues with the first bit of code I posted, I didn't realize the importance of making sure it was actual code that could be copied, pasted and run.

        If you intend "actual" (in "I didn't realize the importance of making sure it was actual code that could be copied, pasted and run.") to mean your entire problem script then you err. What the Monks need to see is a minimal, compilable script that exhibits the same problem as your larger script.

        Don't forget to play a bit with your 2nd scrap and my diff against it. Have a look at the output of Data::Dumper, esp. the parts of the data structure containing the mime sub-parts and the effects on those when you move the "active" ...add(Type=>...) statement around.

        That way you see the sudden appearance of the excess mime part with it's undef'd Data and the subsequent abort of send(). Dumper is a worthwile addition to your bag-of-tricks.

        cu
        Peter