Merge branch 'fix-notify' of https://github.com/frennkie/raspiblitz into frennkie-fix-notify

This commit is contained in:
rootzoll 2021-09-14 12:58:23 +02:00
commit ecb5f67a12
2 changed files with 24 additions and 24 deletions

View File

@ -79,33 +79,33 @@ source /mnt/hdd/raspiblitz.conf 2>/dev/null
if [ "$1" = "1" ] || [ "$1" = "on" ]; then
echo "switching the NOTIFY ON"
# install sstmp if not already present
if ! command -v ssmtp >/dev/null; then
# install mstmp if not already present
if ! command -v msmtp >/dev/null; then
[ -z "$(find -H /var/lib/apt/lists -maxdepth 0 -mtime -7)" ] && sudo apt-get update
sudo apt-get install -y ssmtp
sudo apt-get install -y msmtp
fi
# install python lib for smime into virtual env
sudo -H /usr/bin/python3 -m pip install smime
# write ssmtp config
cat << EOF | sudo tee /etc/ssmtp/ssmtp.conf >/dev/null
#
# Config file for sSMTP sendmail
#
# The person who gets all mail for userids < 1000
# Make this empty to disable rewriting.
Root=${notifyMailTo}
cat << EOF | sudo tee /etc/msmtprc >/dev/null
# Set default values for all following accounts.
defaults
port 587
tls on
tls_trust_file /etc/ssl/certs/ca-certificates.crt
# hostname of this system
Hostname=${notifyMailHostname}
account mail
host ${notifyMailServer}
from ${notifyMailFromAddress}
auth on
user ${notifyMailUser}
password ${notifyMailPass}
# Set a default account
account default : mail
# relay/smarthost server settings
Mailhub=${notifyMailServer}
AuthUser=${notifyMailUser}
AuthPass=${notifyMailPass}
UseSTARTTLS=YES
FromLineOverride=YES
EOF
# edit raspi blitz config
@ -137,7 +137,7 @@ if [ "$1" = "send" ]; then
exit 1
fi
if ! command -v ssmtp >/dev/null; then
if ! command -v msmtp >/dev/null; then
echo "please run \"on\" first"
exit 1
fi

View File

@ -11,7 +11,7 @@ try:
except ImportError:
raise ImportError("Please install missing package: python3 -m pip install smime")
SSMTP_BIN = "/usr/sbin/ssmtp"
SMTP_BIN = "/usr/bin/msmtp"
def main():
@ -107,7 +107,7 @@ def mail(recipient: str = None, message: str = None, subject: str = None, cert:
'From: {} <{}>'.format(from_name, from_address),
"Subject: {}".format(subject),
"",
"{}".format(message.encode('utf8'))
"{}".format(message)
]
with open(cert, 'rb') as pem:
@ -126,11 +126,11 @@ def mail(recipient: str = None, message: str = None, subject: str = None, cert:
msg_to_send = msg.as_bytes()
# send message via e-Mail
if not os.path.exists(SSMTP_BIN):
raise Exception("File not found: {}".format(SSMTP_BIN))
if not os.path.exists(SMTP_BIN):
raise Exception("File not found: {}".format(SMTP_BIN))
try:
cmd = [SSMTP_BIN, recipient]
cmd = [SMTP_BIN, recipient]
subprocess.run(cmd, input=msg_to_send, stderr=subprocess.STDOUT)
except subprocess.CalledProcessError as err: