Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

mime lite

by grashoper (Monk)
on Apr 27, 2009 at 18:18 UTC ( #760391=perlquestion: print w/replies, xml ) Need Help??

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

I must be perl-tarded but here goes. i am trying to setup and send a simple email and fooey no emails working yet, I have replaced the servername and username password stuff, they did have valid values what I do get is the number of processes and no errors aside from global variable $msg requires explicit package name. I am on a windows system 2003 server, using mime:lite and trying to use smtp but probably doing it wrong here is my code. ok you can give me a hard time if you want I just want to understand what is wrong aside from the complaining about that variable which is because of warnings and strict being on, cause everybody says to use warnings and strict. my shebang line has -w trust me it does.. I also want to loop this check so that it runs for several hours once an hour this should do for about 30 hours right?
use Win32::Process::List; use Mail::Sender; use MIME::Lite; use strict; my $numloops=0; my $timer=6000; while($numloops>30){ $numloops++ sleep $timer; my $P = Win32::Process::List->new(); if($P->IsError == 1) { print "an error occured: " . $P->GetErrorText . "\n"; } my %list = $P->GetProcesses(); my $anz = scalar keys %list; print "Anzal im Array= $anz\n"; my $count = 0; foreach my $key (keys %list) { # $list{$key} is now the process name and $key is the PID #print sprintf("%20s has PID %10s", $list{$key}, $key) . "\n"; $count++; } print "Number of processes: $count\n"; my $process = "mmdrv.exe"; my %hPIDS = $P->GetProcessPid($process); print keys (%hPIDS) . "\n"; if(%hPIDS) { foreach (keys %hPIDS) { print "$_ has PID " . $hPIDS{$_} . "\n"; } } else { print "Process(s) not found\n"; #exit; my $test= MIME::Lite->send('smtp', "", AuthUser=>"$username",AuthPass=>"$Pass" ); my $msg = MIME::Lite->new( From =>'', To =>'', Cc =>',', Subject =>'Hello testing email from perl heartbeat monitor sc +ript', Data =>"Loadrunner is running!" ); } }

Replies are listed 'Best First'.
Re: mime lite
by Anonymous Monk on Apr 27, 2009 at 18:31 UTC
    See MIME::Lite to learn how to add error checking and turn on debugging.
      I am trying to add error checking for Mime::Lite too, however the documentation only shows this:
      $msg->send || die "you DON'T have mail!";
      however that does not say what was wrong, it does not give the exception error, so that we know what happened, other than it did not send the email, which would be obvious if we did this:
      if($msg->send()) { # Say that the message was sent... or if in a subroutine just: return 1; } else { # Give error message but what do we show to actually put what happene +d? if in a subroutine return 0; but set an error such as: #$Mime::Lite::error or something similar... }

      Any clues how to get the errors message to figure out what went wrong?

        I found something that may work, however, the way he was handling it was a little different that what I need: using Test::Trap

        What will make this work?
        use Test::Trap qw/ :output(systemsafe) /; $_sendError = ""; trap { $msg->send('smtp', '', AuthUser=> +'', AuthPass=>'$_encEmPass') || $_sendErro +r = $@ }; $_ and $_sendError = $_ for $trap->die, $trap->stdout, $trap->stde +rr; if($_sendError) { return 0; } else { return 1; }
        I don't want to print anything, I just need to catch the error IN a variable so that I can have my system continue. It emails me any errors that the programming catches.

        Thank you for any advice you can offer for this to work.
        Right now I get this error:
        Can't modify logical or (||) in scalar assignment at /path/to/data/fil +e/ line 39, near "$@ }" # That code is above...
        Thanks again in advance.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (5)
As of 2022-01-27 09:48 GMT
Find Nodes?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:

    Results (70 votes). Check out past polls.