Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Yet another tool for sending out newsletters

by Anonymous Monk
on Aug 13, 2002 at 15:25 UTC ( [id://189824]=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

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

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

    No recent polls found