This repository has been archived on 2021-04-27. You can view files and clone it, but cannot push or open issues or pull requests.
mail2members/mail2members.sh

102 lines
2.4 KiB
Bash
Raw Normal View History

#!/bin/sh
usage()
{
echo "usage"
echo "====="
echo ""
echo "reads a csv-file with member-data and a text-template from template"
echo "uses erb to fill the template with data, encrpyt and sign the mail with the members public pgp key and send it via swaks(swiss army knife for smtp)"
echo ""
echo "./$0"
echo "\t-h --help"
echo "\t--member-data=member-data.csv"
echo "\t--template=template.erb"
echo "\t--subject=subject"
echo "\t--smtphost=smtphost"
echo "\t--smtpuser=smtpuser"
echo "\t--smtppassword=smtppassword"
echo ""
}
while [ "$1" != "" ]; do
PARAM=`echo $1 | awk -F= '{print $1}'`
VALUE=`echo $1 | awk -F= '{print $2}'`
case $PARAM in
-h | --help)
usage
exit
;;
-n)
DRYRUN=1
;;
--member-data)
MEMBER_DATA=$VALUE
;;
--template)
TEMPLATE=$VALUE
;;
--subject)
SUBJECT=$VALUE
;;
--smtphost)
SMTPHOST=$VALUE
;;
--smtpuser)
SMTPUSER=$VALUE
;;
--smtppassword)
SMTPPASSWORD=$VALUE
;;
*)
echo "ERROR: unknown parameter \"$PARAM\""
usage
exit 1
;;
esac
shift
done
if [ -z "$MEMBER_DATA" ] ; then
echo "parameter member-data missing"
echo ""
usage
exit
fi
if [ -z "$TEMPLATE" ] ; then
echo "parameter template missing"
echo ""
usage
exit
fi
if [ -z "$SUBJECT" ] ; then
echo "parameter userid missing"
echo ""
exit
fi
echo "MEMBER_DATA = "$MEMBER_DATA
echo "TEMPLATE = "$TEMPLATE
echo "SUBJECT = "$SUBJECT
if [ -z "$DRYRUN" ] ; then
echo "real run"
erb column1=Column1 column2=Column2 column3=Column3 $TEMPLATE\
| gpg2 --batch --yes -vvv -u vorstand@wtf-eg.de \
--no-emit-version -eas -r "42152130EE5C8BED881AB911D65BA8BC7E8B9302" \
| swaks --to frank.landgraf@web.de \
--from "vorstand@wtf-eg.de" \
-tls \
--auth LOGIN \
--server $SMTPHOST \
--auth-user $SMTPUSER \
--auth-password $SMTPPASSWORD \
--header "Subject: $SUBJECT" --body -
else
echo "dry run"
erb column1=Column1 column2=Column2 column3=Column3 $TEMPLATE
erb column1=Column1 column2=Column2 column3=Column3 $TEMPLATE|gpg2 --batch --yes -vvv -u vorstand@wtf-eg.de --no-emit-version -eas -r "42152130EE5C8BED881AB911D65BA8BC7E8B9302"
fi