in reply to Yet another tool for sending out newsletters

#!/usr/bin/perl -w use strict; use Mail::Bulkmail; use Mail::AddressSort; use File::Spec::Functions; use Getopt::Std; my %default = ( dir => ".", addrfile => "addresslist.txt", mailfile => "mail.txt", errorlog => "error.log", successlog => "success.log", subject => q(Default subject), fromaddr => q(email@domain.com), ); getopts('a:d:e:hf:l:m:s:', \my %option); $option{h} && die << "HELPMSG"; usage: bulkmail [-a addrfile] [-d directory] [-e errorlog] [-h] [-f fromaddr] [-l successlog] [-m mailfile] [-s subject] All files must reside in the same directory. defaults: -a $default{addrfile} -d $default{dir} -e $default{errorlog} -f $default{fromaddr} -l $default{successlog} -m $default{mailfile} -s $default{subject} HELPMSG my $dir = $option{d} || $default{dir}; open(my $listfile,"<",catdir($dir, $option{a} || $default{addrfile})) or die "Couldn't open address list: $!\n"; chomp(my @address = <$listfile>); close $listfile; my $list=Mail::AddressSort->new(); $list->input(@address); (@address)=$list->sorted(); open(my $mailfile,"<",catdir($dir, $option{m} || $default{mailfile})) or die "Couldn't open message file: $!\n"; read $mailfile, my $mail, -s $mailfile; close $mailfile; my $bulk = Mail::Bulkmail->new( 'LIST' => \@address, 'Message' => $mail, 'From' => $option{f} || $default{fromaddr}, 'Reply-to' => $option{f} || $default{fromaddr}, 'Subject' => $option{s} || $default{subject}, 'BAD' => catfile($dir, $option{e} || $default{errorlog}), 'GOOD' => catfile($dir, $option{l} || $default{successlog}) +, 'ERRFILE' => catfile($dir, $option{e} || $default{errorlog}), 'HTML' => 1, 'use_envelope' => 1, 'envelope_limit'=> 1000 ) or die Mail::Bulkmail -> error(); $bulk->header(qw(Content-type: text/html)); $bulk->bulkmail;

Replies are listed 'Best First'.
Re: Re: Yet another tool for sending out newsletters
by vxp (Pilgrim) on Aug 13, 2002 at 15:35 UTC
    Anonymous Monk, your code gives these errors:
    Useless use of a constant in void context at /usr/lib/perl5/site_perl/ +5.005/Mail/Bulkmail.pm line 1173. Too many arguments for open at ./ds4.pl line 39, at end of line Too many arguments for open at ./ds4.pl line 48, near "))

    Edited: ~Wed Aug 14 22:27:32 2002 (GMT) by footpad: Added <code> tags, per Consideration

      The first warning has to do with 'strict' inside Bulkmail, and will appear even with their test case. Dunno there, without going deeper. It will run however to deliver the mail as is.

      Check your line wrap on the other two. Those 'or die' cases are identical to previous post. Try removing the line break.
      should work fine otherwise.