#!/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 # we read the columns from $MEMBER_DATA file into these variables # variables are used in script and also overhanded to erb while IFS="," read -r lineno nick email fingerprint passwort do echo "Displaying Record-$lineno" echo "Nick: $nick" echo "email: $email" echo "fingerprint: $fingerprint" # echo "passwort: $passwort" echo "-------" if [ -z "$DRYRUN" ] ; then # we take over nick and passwort into the erb template # TODO this is not a generic solution !!! # the file $TEMPLATE contains the erb template # # gpg uses the trust-model always # # swaks uses the other variables for sending per SMTP # to mailhost erb nick="$nick" passwort="$passwort" $TEMPLATE \ | gpg2 -vvv --trust-model always\ -u vorstand@wtf-eg.de \ --no-emit-version \ -eas -r ${fingerprint// /} \ | swaks --to "$email" \ --from "vorstand@wtf-eg.de" \ -tls \ --auth LOGIN \ --server $SMTPHOST \ --auth-user $SMTPUSER \ --auth-password $SMTPPASSWORD \ --header "Subject: $SUBJECT" --body - else erb nick="$nick" passwort="$passwort" $TEMPLATE erb nick="$nick" passwort="$passwort" $TEMPLATE \ | gpg2 -vvv --trust-model always\ -u vorstand@wtf-eg.de \ --no-emit-version \ -eas -r ${fingerprint// /} fi done < $MEMBER_DATA