Files
reminder-mails/reminder-mails.sh

35 lines
1.0 KiB
Bash
Executable File

#!/bin/bash
# This file takes care of identifying the requested mail, adding necessary
# information to the template, and piping it to msmtp to send it out.
#
# Copyright (c) 2018 Free Software Foundation Europe <contact@fsfe.org>
# Author 2018 Max Mehl <max.mehl@fsfe.org>
# SPDX-License-Identifier: GPL-3.0-or-later
function decho {
DATE=$(date +%y-%m-%d_%H:%M:%S%z)
echo "[$DATE] $*"
}
EMAIL=$1
# If argument is given, check for mail template and send it out
if [[ ! -z "$EMAIL" ]]; then
if [[ -e "${HOME}/mails/$EMAIL" ]]; then
cat "${HOME}/mails/$EMAIL" | sed "1s|^|Date: $(date -R)\n|" | sed "1s|^|Message-ID: <ReMiNdEr.$(date +%s)@fsfe.org>\n|" | msmtp -t --read-envelope-from -a fsfe
if [[ "$?" == 0 ]]; then
decho "[INFO] Mail \"$EMAIL\" has been sent successfully"
else
decho "[ERROR] There has been an error with sending \"$EMAIL\"".
exit 1
fi
else
decho "[ERROR] Mail template \"$EMAIL\" does not exist."
exit 1
fi
else
decho "[INFO] No argument given. Will not send a mail."
exit 0
fi