Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Yet another tool for sending out newsletters

by Aristotle (Chancellor)
on Aug 13, 2002 at 00:33 UTC ( [id://189683]=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 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(vpolyakov@katrillion.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{errorlo +g} -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; @address = map { $_->[0] } sort { $a->[1] cmp $b->[1] } map { $_, lc((split /\@/)[-1]) } @address; 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; $bulk = Mail::Bulkmail->new( LIST => \@address, Message => $mail, From => $option{f} || $default{fromaddr}, Subject => $option{s} || $default{subject}, BAD => catfile($dir, $option{e} || $default{errorlog}), GOOD => catfile($dir, $option{l} || $default{successlo +g}), ERRFILE => catfile($dir, $option{e} || $default{errorl +og}), HTML => 1, use_envelope => 1, ); $bulk->HFM(1); $bulk->envelope_limit(1000); $bulk->header(qw(Content-type text/html)); $bulk->bulkmail;
Of course you can get past the same-directory limitation by passing something like -a ../addresses.txt

Makeshifts last the longest.

Replies are listed 'Best First'.
Re: Re: Yet another tool for sending out newsletters
by vxp (Pilgrim) on Aug 13, 2002 at 02:58 UTC
    Aristotle, with your code i get the following errors:
    Useless use of a constant in void context at /usr/local/share/perl/5.6 +.1/Mail/Bulkmail.pm line 1173. Use of uninitialized value in string comparison (cmp) at ./bulkmail.pl + line 38.

    Edited: ~Wed Aug 14 22:25:41 2002 (GMT) by footpad: Replaced <tag> tags with <code> tags, per Consideration

      Hmm.. no idea. :-) I don't actually have the module installed myself, just wrote the above source from the Mail::Bulkmail POD and the bits you provided. I'm not sure why this happens, although I figure it's because rather than a filename it's passing an array reference as the address list. According to the documentation, that is allowed (as would have been passing a coderef). If I had the module, I'd look into it.. maybe tonight when I'm home again.

      Update: Duh, of course.

      Makeshifts last the longest.

        'read my $mail, $mailfile, -s $mailfile;'
        should be
        'read $mailfile, my $mail, -s $mailfile;'

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (5)
As of 2024-03-28 20:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found