#!/bin/ksh # #---------#---------#---------#---------#---------#---------#---------#--------- # # Date: 12 Sep 2000 # Title: bulk e-mail to a list of recipients using sendmail # Creator: larg # Description: # read the email body from a file # read a list of email addresses from another file # for each address, # - make up email headers # - send the complete email to the address # Emails are sent at the rate of 1 each second. # Modifications: # #---------#---------#---------#---------#---------#---------#---------#--------- # # check command line arguments # usage_message=" usage: $0 -b body-text-file -f address-file $0 -b body-text-file -a email-address example: $0 -b ./body.txt -a \"idc@planetlarg.net\" " # no options provided? tell the punter how to use this utility if [ $# -eq 0 ]; then echo "no options were provided." echo "$usage_message" 1>&2 exit 1 fi # our default values, in case the punter doesn't supply any body_file='NOT PROVIDED' to_address_file='NOT PROVIDED' # read in the values while getopts a:b:f: arg do case $arg in a) # one address to_address_file=/tmp/email.txt echo $OPTARG > $to_address_file ;; b) # the body text body_file=$OPTARG ;; f) # the list of addresses to_address_file=$OPTARG ;; :) # a valid option was supplied, but the argument is missing echo "missing argument" echo "$usage_message" 1>&2 exit 1 ;; \?) # an invalid option was supplied echo "ignoring the option -$arg " ;; esac done # check the values if [ "$body_file" = 'NOT PROVIDED' ]; then echo "What text body do I use?" echo "$usage_message" 1>&2 exit 1 fi if [ "$to_address_file" = 'NOT PROVIDED' ]; then echo "What list of addresses do I use?" echo "$usage_message" 1>&2 exit 1 fi #---------#---------#---------#---------#---------#---------#---------#--------- # # initial stuff # echo "Have you included any extra addresses from the requester." echo "" # from address # copy the address from the "From: " header line in the body text file. # The regex works with these formats: # "From: bla bla bla " # "From: me@my.address" # "From: me@my.address (bla bla bla)" from_address=`perl -e 'if (m/^From:[^\@]*\s(\S+\@\S+)/){print $1;last;}' -n $body_file` if [ -z $from_address ]; then echo "no from address was found in the file $body_file." exit 2 fi body=$(cat $body_file) echo "reading the body text ..." 1>&2 echo " file: $body_file" 1>&2 echo " from address: $from_address" 1>&2 mail_agent="/usr/lib/sendmail -f $from_address " # # email to each address # email addresses are assumed to be one per line. # echo "sending emails ... " 1>&2 while read to_address do echo " $to_address" # date=`date "+%d %h 20%y %H:%M"` # removed 04/06/01 nsh # Date: $date # removed 04/06/01 nsh $mail_agent $to_address < /dev/null echo "done. " 1>&2