I think what I would do is first write a small test script to see if the config file was being read correctly. Something like (using your config file)
#!/usr/bin/perl use strict; use warnings; use Data::Dumper; my $cnf_file = q{config.txt}; my %cnf = read_config($cnf_file); print Dumper \%cnf; sub read_config { my $file = shift; open my $fh, q{<}, $file or die qq{cant open *$file* to read: $!}; my %cnf; while (my $line = <$fh>){ chomp $line; next unless $line; next if $line =~ /^#/; my ($key, $value) = split /\s+=\s+/, $line; if ($key eq q{To}){ push @{$cnf{$key}}, $value; } else{ $cnf{$key} = $value; } } return %cnf; }
output
$VAR1 = { 'MediumAlarmThreshold' => '2', 'SMTP_Server' => 'smtp.isp.com', 'LowAlarmThreshold' => '3', 'LogRotateHour' => '0', 'To' => [ 'emailaddress@yahoo.ca', 'someotheremailaddress@yahoo.ca' ], 'HighAlarmThreshold' => '1', 'From' => 'Script@domain.com' };
As you can see, the To key holds an array ref. Which is, apparently, what Mail::Sender requires.

If the output is indeed as you expect I would consider a second test script which just sends a dummy email to those email addresses.

This approach has many advantages. You take on one problem at a time (which is my top limit :-) and you end up with a collection of subs you are confident with. Also, if you hit a particular snag with one of the subs you have a simple script that you can post here and which monks can download and run. This approach, in my experience, will result in a lot more help and solutions.

Try the script above. If it appears ok, write your test_send_email and see if that's ok.

If there are still snags, you know where we live. :-)


In reply to Re^3: Sending Email to a list of people using Mail::Sender by wfsp
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":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.