Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

OK.. So I cleaned up a few things from the recommendations that some of you made. (thanks) I then got FunkyMonk's Message and I must say that I did read the documentation on Mail::Sender (I had to since I am new to perl and needed to know how it initially worked) I guess the real problem is that I wasn't 100% sure what they meant by "This parameter may be either a comma separated list of email addresses or a reference to a list of addresses." Initially, I had created a list of comma separated addresses(within the script) and it worked. When I moved that list to the new file, it didn't work. I assume that this is where the "reference to a list of addresses" comes in at. Perhaps Someone can give me the right syntax since I still cannot get it to work. (for the push part). Here is my "real" code that I have modified so far. Since my script is over 1000 lines therefore I am only posting a portion of it and it's very likely that I may be missing stuff. This is not my final code, this is my code in progress. ( so commented out stuff that i tried is also in there too ) Either way, the code works when within the script, it just doesn't work outside of it. Here it is:

The options file:

# Configuration File for Script # Set Alarm Thresholds by count of reoccurance based on 5 minutes cron + job. LowAlarmThreshold = 3 MediumAlarmThreshold = 2 HighAlarmThreshold = 1 # Set the Email Options # Email addresses are in comma separated values # To = emailaddress@yahoo.ca,someotheremailaddress@ +yahoo.ca To = emailaddress@yahoo.ca To = someotheremailaddress@yahoo.ca # To = emailaddress@yahoo.ca From = Script@domain.com SMTP_Server = smtp.isp.com # Set the Hour at which daily log rotation will happen (accepted range + is 0 - 23) LogRotateHour = 0

The Script File:

#!/usr/bin/perl use warnings; use Mail::Sender; &ReadConfig; &ActuallySendEmail; sub ReadConfig { $ConfigFile = "/srv/script/etc/ConfigFile.conf"; # open(CONFIGFILE, "<", $ConfigFile) or die "ERROR: Unable to open +$ConfigFile for reading"; # open $CONFIGFILE, '<', $ConfigFile or die "ERROR: Unable to open +'$ConfigFile' for reading $!"; #use feature qw(say); # while (<MCONFIGFILE>){ # next if !~ m/^To\s*=\s*(.*)/; # if $Line =~ m/^To\s*=\s*(.*)/; # say "To = <$1>\n"; # } if (!open(CONFIGFILE,$ConfigFile)) { print "ERROR: Unable to open Configuration File: $ConfigFile"; print "Fix the filepath or the file itself"; exit(); } @To = (); foreach $Line (<CONFIGFILE>) { next if ($Line =~ m/^#/); # Get Alarm Thresholds Values if ($Line =~ m/LowAlarmThreshold\s*=\s*(.*)/) { $LowAlarmThreshold = $1; print "Low Alarm Threshold = <$LowAlarmThreshold>\n"; } if ($Line =~ m/MediumAlarmThreshold\s*=\s*(.*)/) { $MediumAlarmThreshold = $1; print "Medium Alarm Threshold = <$MediumAlarmThreshold>\n" +; } if ($Line =~ m/HighAlarmThreshold\s*=\s*(.*)/) { $HighAlarmThreshold = $1; print "High Alarm Threshold = <$HighAlarmThreshold>\n"; } # Get Email Attributes Values if ($Line =~ m/To\s*=\s*(.*)/) { $To = $1; push(@To,$To); print "To = <@To>\n"; } if ($Line =~ m/From\s*=\s*(.*)/) { $From = $1; print "From = <$From>\n"; } if ($Line =~ m/SMTP_Server\s*=\s*(.*)/) { $SMTP_Server = $1; print "SMTP Server = <$SMTP_Server>\n"; } # Get LogRotate Hour Value if ($Line =~ m/LogRotateHour\s*=\s*(.*)/) { $LogRotateHour = $1; print "Log Rotate Hour = <$LogRotateHour>\n"; } } close(CONFIGFILE); } sub ActuallySendEMail { ($Flag) = @_; close(TEMPEMAILMESSAGEFILE); $TempEMailMessageFile =~ s/^>//; # $To = 'someemail@yahoo.com,exampleemailaddress@yahoo.ca'; # $To = 'exampleemailaddress@yahoo.ca'; # @Message = <TEMPEMAILMESSAGEFILE>; $Sender = new Mail::Sender({ smtp => 'smtp.isp.com', from => "\'$From\'", }); if ($Flag eq "TempEmailMessageFileOpenError") { $Subject = 'Script - Temporary email message open error'; } elsif ($Flag eq "TempEmailMessageFileLockError") { $Subject = 'Script - Temporary email message lock error'; } elsif ($Flag eq "Recovered") { $Subject = 'Script - has recovered from one or more errors'; } else { $Subject = 'Script encountered errors..'; }; print "to <@To>\n"; $Sender->OpenMultipart({ to => \@To, subject => "$Subject", }); $Sender->Body; $Sender->SendLineEnc("Script has encountered errors:"); $Sender->SendLineEnc("-----------------------------------\n"); if ($Flag eq "TempEmailMessageFileOpenError") { $Sender->SendLineEnc("ERROR: Unable to open file for writing: +$TempEMailMessageFile"); } elsif ($Flag eq "TempEmailMessageFileLockError") { $Sender->SendLineEnc("ERROR: Unable to lock file: $TempEMailMe +ssageFile"); } elsif (!open(TEMPEMAILMESSAGEFILE,$TempEMailMessageFile)) { print "\nERROR: Unable to open temporary email message file: $ +TempEMailMessageFile\n"; &PrintLog("ERROR: Unable to open temporary email message file: + $TempEMailMessageFile"); return $FAILURE; } else { @Message = <TEMPEMAILMESSAGEFILE>; print "Message = <@Message>\n"; $Sender->SendLineEnc(@Message); close(TEMPEMAILMESSAGEFILE); }; if (($Flag eq "")&&(-e $PDFile)) { $Sender->Attach({ description => 'PDF file', ctype => 'application/pdf', encoding => 'Base64', disposition => attachment; filename="File.pdf"; type="PDF"', file => "$PDFFile", }); } $Sender->Close(); return $SUCCESS; }

So I beleive FunkyMonk is on the right track to what I am looking for. Thanks.


In reply to Re^2: Sending Email to a list of people using Mail::Sender by mlebel
in thread Sending Email to a list of people using Mail::Sender by mlebel

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (5)
As of 2024-04-24 12:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found