#!/usr/bin/perl -w use strict; use vars qw ($line $list $flag); $flag = 0; # modules # use diagnostics; # debug use Data::Dumper; # debug use MIME::Lite; # open address file, read in address file, convert to useful form for email: open FIN," ) ) { chomp $line; if ($flag == 0) { $list = $line; $flag = 1; } else { $list .= ",$line"; } } close (FIN); # now we have all the names, comma-separated, in $list # group into sets of five my $i=0; # counter my $j=0; # key for %HoA my @wholelist; my $individual; my @fives; my $fives; my %HoA; my $HoA; @wholelist = split/,/,$list; shuffle(\@wholelist); # sub to randomize before grouping for $individual(@wholelist) { push @fives, $individual; if (defined ($fives[4]) ) { push(@{$HoA{$j}}, @fives); undef(@fives); $i = 0; $j++; # reset $i; ++ j to have next @fives go into a new key } else { $i++; } } print "\n\nDumping \%HoA:\n"; # debug print Dumper(%HoA); # debug $j=0; #reusing key for ($j=0; $j<4; $j++) { #20 emails in wholelist, so 0..3 keys in %HoA #### use vars qw ( %params ); %params = ( "To" => "ww\@disadvantage.org", "Bcc" => "%HoA{$j}", "Subject" => "A test from ww", "Reply-To" => "ww\@disadvantage.org", "body" => "This is just some simple test text from ww. When you receive it please simply 'FORWARD' it (do NOT 'REPLY') to me at \n\n'wheelerw\@disadvantage.org' \n\nso I can confirm that my test ran properly.\n\nThanks, in advance, for your help!\n", ); print "\n\n +++++++++++\n\nDumping \%params next:\n\n"; # debug print Dumper (%params); # debug print "\n Done dumping \%params\n\n +++++++++++\n\n"; # debug print "\n\n \$HoA{$j}' is: @{ $HoA{$j} }\n\n"; # debug exit; # debug =head sendmail ( ${ %params } ); =cut sleep (2); #120 in production } #### SUBS ##### # suffle array (Fisher-Yates) to minimize having any domain get all of a single batch. sub shuffle { my $individual = shift; my $i; for ($i = @$individual; --$i; ) { my $j = int rand ($i+1); next if $i == $j; @$individual[$i,$j] = @$individual[$j,$i]; } } sub sendmail { $params{Type} = 'text/plain' if ! exists $params{Type}; $params{From} = 'Postmaster@createyouradvantage.com' if ! exists $params{From}; print "\n\n======================================\n\n"; print Dumper (%params); print "\n======================================\n\n"; print Dumper (@{ $HoA{$j} }); print "\n======================================\n\n"; # my $msg = MIME::Lite->new (%params{$j}); print "\n\n -------------------------------\n"; my $msg->print_header(\*STDOUT); print "\n\n -------------------------------\n"; # $msg->send ('smtp', "fake.disadvantage.org", Timeout=>90) or die "Message send failed: $!"; # error ^: "no data in this part" return; } #### Dumping %HoA: $VAR1 = '1'; $VAR2 = [ 'guer@yapot.com', 'cd@cdef.com', 'jrn@foo.com', 'greg@confcall.net', 'gecko@yapoo.com' ]; $VAR3 = '3'; $VAR4 = [ 'donm@foo.com', 'Dolly@yankeeone.org', 'Postmaster@foo.com', 'Fred.Walters@nevasink.org', 'delbert.cubby@cmail.com' ]; $VAR5 = '0'; $VAR6 = [ 'jrn@aql.com', 'ksmith@foo.com', 'bdm@prover.net', 'Donl@aql.com', 'mrod@beachball.com' ]; $VAR7 = '2'; $VAR8 = [ 'KAM@charles.net', 'de2@ulmail.ljw.edu', 'ab@abc.net', 'de1@cdef.net', 'bill@fghresearch.com' ]; +++++++++++ Dumping %params next: $VAR1 = 'body'; $VAR2 = 'This is just some simple test text from ww. When you receive it please simply \'FORWARD\' it (do NOT \'REPLY\') to me at \'wheelerw@disadvantage.org\' so I can confirm that my test ran properly. Thanks, in advance, for your help! '; $VAR3 = 'Subject'; $VAR4 = 'A test from ww'; $VAR5 = 'Reply-To'; $VAR6 = 'ww@disadvantage.org'; $VAR7 = 'To'; $VAR8 = 'ww@disadvantage.org'; $VAR9 = 'Bcc'; $VAR10 = '%HoA{0}'; Done dumping %params +++++++++++ $HoA{0}' is: jrn@aql.com ksmith@foo.com bdm@prover.net Donl@aql.com mrod@beachball.com #### F:\_wo_cya>perl ugly.pl >ugly_out2.txt syntax error at ugly.pl line 115, near "%params{" Execution of ugly.pl aborted due to compilation errors. #### use vars qw (%params); %params = ( "cc:" => "%HoA{$j}", "Subject" => "A test from ww", "body" => "This is just some simple test text from ww. When you receive it please simply 'FORWARD' it (do NOT 'REPLY') to me at \n\n'ww\@ldisadvantage.org' \n\nso I can confirm that my test ran properly.\n\nThanks, in advance, for your help!\n" ); ( ...debugs removed) sendmail (%params); sleep (120); } (...sub shuffle removed for brevity) sub sendmail { # local %params = @_; $params{Type} = 'text/plain' if ! exists $params{Type}; $params{From} = 'Postmaster@disadvantage.com' if ! exists $params{From}; my $msg = MIME::Lite->new (%params); ### Format as a string: my $str = $msg->as_string; ## error ^ : "no data in this part at mailerww1.pl line 199" print "\n\n\$str is:\n $str \n"; print "\n\n\$str is:\n $$msg \n"; # $msg->send () or die "Message send failed"; return; } #### Reference found where even-sized list expected at mailerww.pl line 165. $msg is: MIME::Lite=HASH(0x1c0162c) F:\_wo_cya>perl mailerww1.pl $HoA{0}' is: (...the expected 5 email addresses) no data in this part at mailerww1.pl line 207