Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Re^3: MIME::Lite and Multipart

by jakobi (Pilgrim)
on Sep 29, 2009 at 17:53 UTC ( #798169=note: print w/replies, xml ) Need Help??

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

Hmm. I kind of ignored the 'no data', as I HAD PROPER data/mails and no errors as soon as I had your scrap working with the bits you omitted.

below is postfix' impression of 2 runs of your code

Sep 29 17:39:15 anuurn postfix/smtpd[18818]: connect from localhost[12 +] Sep 29 17:39:15 anuurn postfix/smtpd[18818]: 5B1D9404F6: client=localh +ost[] Sep 29 17:39:15 anuurn postfix/smtpd[18818]: lost connection after DAT +A (506 bytes) from localhost[] Sep 29 17:39:15 anuurn postfix/smtpd[18818]: disconnect from localhost +[] Sep 29 17:39:15 anuurn postfix/cleanup[18821]: 5B1D9404F6: message-id= +<20090929153915.5B1D9404F6@anuurn.compact> Sep 29 17:39:53 anuurn postfix/smtpd[18818]: connect from localhost[12 +] Sep 29 17:39:53 anuurn postfix/smtpd[18818]: A5E45404F6: client=localh +ost[] Sep 29 17:39:53 anuurn postfix/smtpd[18818]: lost connection after DAT +A (506 bytes) from localhost[] Sep 29 17:39:53 anuurn postfix/smtpd[18818]: disconnect from localhost +[] Sep 29 17:39:53 anuurn postfix/cleanup[18821]: A5E45404F6: message-id= +<20090929153953.A5E45404F6@anuurn.compact>

update META: keeping this one in <pre> intentionally; or is the line-broken version really preferrable even for non-code illustration not intended for use/reuse?? -> there's a nice profile setting to not wrap code lines on viewing. Less pain for me. (And you, if you've similar profile settings).

Actually this doesn't happen, if you comment out the attachment block: it sends a proper email.

With the attachement code, you see some debug output and the 'no data' at the very point my postfix reports loss of connection. What happens is that ::Lite happily emits a mail header, blank line and possibly the text and html variable content as mime parts (you did set them, right?). Which are the first 500 or so bytes of the partial message.

However, ::Lite doesn't check in advance that it can create a proper email and it is NOW ::Lite aborts IF THE ATTACHEMENT FILE doesn't exist(?) or is undef(your scrap!). Which is what postfix is unhappy about and thus postfix rejects the already received partial mail as well.

So with the variables being undef, I of course did never see a mail nor the exact problem scenario you have. With the missing bits added all I see is proper mails and no problems at all.

Summary: use strict; use warnings; use diagnostics; would have pinpointed the trouble for both of us: the undefined (or not found?) $upload_file among others, which lead to your 'no data' observation. Also testing the rc of the send operation would have made the issue more obvious.

needless to say, I also did the mistake to test the code w/o the use strict; ...

Replies are listed 'Best First'.
Re^4: MIME::Lite and Multipart
by Analog (Novice) on Sep 29, 2009 at 18:55 UTC
    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 = ''; 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); }

      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.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://798169]
[LanX]: so the mayor of London should be better named First Minister of the London region and is on a comparable level like Nicola Sturgeon
[LanX]: ?

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (10)
As of 2017-12-15 18:10 GMT
Find Nodes?
    Voting Booth?
    What programming language do you hate the most?

    Results (440 votes). Check out past polls.