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

Runs with perl -d, but ...

by notsoevil (Pilgrim)
on Apr 08, 2003 at 17:59 UTC ( [id://249023] : perlquestion . print w/replies, xml ) Need Help??

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

Very curious about this one -- enough so that this is my first post at the Monastery in a LONG time. Anyway, I have the following bit of code (which is in the sub &sendmail):
use MIME::Lite; my $to = 'anthony@currentmarketing.com'; my $fax = '/tmp/1049811816.pdf'; # Start with a simple text message: my $msg = MIME::Lite->new( From =>'anthony@domain.com', To =>$to, Subject =>'FAX for you.', Type =>'TEXT', Data =>"Here is a fax for you!\n\n:)" ); print "created msg\n"; # Attach a part ... the make the message a multipart automatically: $msg->attach(Type =>'application/pdf', Path =>$fax, Filename =>'fax.pdf', ); print "attached pdf\n"; # Now send? $msg->send_by_smtp('216.26.151.48'); print "sent by smtp worked\n"; print "Sent $fax to $to\n";
When I run it via the command line, I get the following output:
[notsoevil@dragon anthony]# ./convert2.pl created msg attached pdf
It's hanging before the send, so to help see why I run perl -d:
[notsoevil@dragon anthony]# perl -d convert2.pl Default die handler restored. Loading DB routines from perl5db.pl version 1.07 Editor support available. Enter h or `h h' for help, or `man perldebug' for more help. main::(convert2.pl:61): &sendmail(); DB<1> n created msg attached pdf sent by smtp worked Sent /tmp/1049811816.pdf to anthony@currentmarketing.com Debugged program terminated. Use q to quit or R to restart, use O inhibit_exit to avoid stopping after program termination, h q, h R or h O to get additional info. DB<1> q
Er, so it runs via the perl debugger, but not normally via the command line. If I comment out the 'attach' section and just send the text, it does run from the command line. So, needless to say, I'm now totally confused.

--
notsoevil
--
Jeremiah 49:32 - And their camels shall be a booty. . .

Replies are listed 'Best First'.
Re: Runs with perl -d, but ...
by RMGir (Prior) on Apr 08, 2003 at 18:55 UTC
    Wierd stuff...

    I use very similar code with MIME::Lite myself, and haven't seen similar misbehaviour.

    The only difference I see between your code and mine is that I use "multipart/mixed" and then attach the text data using

    $msg->attach(Type=>"TEXT",Data=>"Here's your fax");
    before attaching the file.

    I can't see that making a difference, though. I don't see why MIME::Lite would care, or why -d would change anything.

    Does the send under the debugger actually work? I mean, I see that your code things it worked, but does anthony@wherever actually get the file?
    --
    Mike

    EDIT: Added note about multipart/mixed

      Yep, the send actually works -- the file comes through just fine to me, attachment and all. Which is why I don't think it is the format of the MIME::Lite code ... but I'm still at a loss.

      --
      notsoevil
      --
      Jeremiah 49:32 - And their camels shall be a booty. . .

        Did you try explicitly setting multipart/mixed?

        The docs seem to imply that's what the "attach to singlepart" hack does, anyways.
        --
        Mike

Re: Runs with perl -d, but ...
by notsoevil (Pilgrim) on Apr 09, 2003 at 14:49 UTC
    Okay, code is now:
    sub sendmail() { # my $to = shift; # my $fax = shift; my $to = 'anthony@currentmarketing.com'; my $fax = '/tmp/1049811816.pdf'; ### Create the multipart "container": my $msg = MIME::Lite->new( From => 'anthony@currentmarketing.com', To => $to, Subject => 'FAX for you.', Type => 'multipart/mixed' ); print "created msg\n"; ### Add the text message part: ### (Note that "attach" has same arguments as "new"): $msg->attach( Type =>'TEXT', Data =>"Here is a fax for you!\n\n:)" ); print "added text part\n"; ### Add the pdf part: $msg->attach(Type =>'application/pdf', Path => $fax, Filename => 'fax.pdf', Disposition => 'attachment' ); print "attached pdf\n"; ### Now send? $msg->send_by_smtp('216.26.151.48'); print "sent by smtp worked\n"; print "Sent $fax to $to\n"; }
    But guess what? It still doesn't work, unless run via the debugger. RMGir, thanks for the advice though. Anyone else have an idea?

    Here is the output when it hangs (with new prints in there):

    [anthony]# ./convert2.pl created msg added text part attached pdf

    --
    notsoevil
    --
    Jeremiah 49:32 - And their camels shall be a booty. . .