mailer 676 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
#!/bin/sh

if [ $# -ne 4 ]; then
    echo "$0 subject from bcc-addr addressfile"
    echo "f.i. $0 'How are you?' 'Some Body <from@example.com>' 'another@example.com' ./addresses "
    echo "Address file format: | Name | Mail |"
    exit 1
fi

subject=$1; shift
from=$1; shift
bcc=$1; shift
addresses_file=$1; shift


while read line; do
    name=$(echo $line | awk -F '|' '{ print $2 }' | sed -e 's/^ *//' -e 's/ *$//')
    email=$(echo $line | awk -F '|' '{ print $3 }' | sed -e 's/^ *//' -e 's/ *$//')

    sed "s/PERSON/$name/" mail | \
        mail -s "$subject" \
             -r "$from" \
             -b "$bcc" \
             "$name <$email>"
done < "$addresses_file"