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

mime lite

by grashoper (Monk)
on Apr 27, 2009 at 18:18 UTC ( [id://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', "servername@mydomain.com", AuthUser=>"$username",AuthPass=>"$Pass" ); my $msg = MIME::Lite->new( From =>'validemail@mydomain.com', To =>'validemail@mydomain.com', Cc =>'some@other.com, some@more.com', 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?

      Thanks
        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', 'mail.wholewellnessclub.com', AuthUser=> +'somemailuser@somedomain.com', 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/Send_Mime_Lite_Email.data line 39, near "$@ }" # That code is above...
        Thanks again in advance.

Log In?
Username:
Password:

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

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

    No recent polls found