#!/usr/local/bin/perl ####################################################################### # Perl program to distribute a personalized message to a mailing list # contained in a name and address file. Dave O'Hallaron. Oct, 1997. # # Each line in the name and address file has the format: # # :: # # note: If we know the first name, e.g., # droh@cs.cmu.edu:Dave: # then we include a salutation. If is empty, e.g., # droh@cs.cmu.edu:: # then we omit the salutation. # # note: The program is not very robust. Blank or empty lines at the # end of the file will crash the program. ####################################################################### # # always flush stdout # select((select(STDOUT), $| = 1)[0]); # # are there the right number of arguments # if ($#ARGV != 1) { print "usage: ", $0, " \n"; exit(0); } $msgfilename = @ARGV[0] . ".msg"; $dstfilename = @ARGV[0] . ".dst"; $subject = @ARGV[1]; # # open the input message file # open(INFILE, $msgfilename) || print "error: couldn't open ", $msgfilename, "\n"; # # read the input message file into a string that will appear in each # mail message. # $msg = ""; while () { $msg .= $_; } close(INFILE); # # now open the file containing the email addresses and first names # open(INFILE, $dstfilename) || print "error: couldn't open ", $dstfilename, "\n"; # # send mail to each person in the name and address file # while () { @line = split(':', $_); $addr = shift(@line); $name = shift(@line); # create the message open(OUTFILE, ">/tmp/stuff") || print "error opening stuff\n"; if ($name ne "") { print OUTFILE $name, ",", "\n\n"; } print OUTFILE $msg; close(OUTFILE); # mail the message print "mailing to ", $addr, "\n"; $mail = sprintf("mail -s \"%s\" %s < /tmp/stuff", ($subject, $addr)); system($mail); unlink "/tmp/stuff"; }