From 38af1f50ec848a000d2a29b248eefe703a4bfe48 Mon Sep 17 00:00:00 2001 From: rootzoll Date: Sun, 25 Apr 2021 15:14:28 +0100 Subject: [PATCH] switch to mstmp --- home.admin/XXsendNotification.py | 10 +++--- home.admin/config.scripts/blitz.notify.sh | 38 +++++++++++------------ 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/home.admin/XXsendNotification.py b/home.admin/XXsendNotification.py index 808f2ed6..27feede2 100755 --- a/home.admin/XXsendNotification.py +++ b/home.admin/XXsendNotification.py @@ -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: diff --git a/home.admin/config.scripts/blitz.notify.sh b/home.admin/config.scripts/blitz.notify.sh index d474641a..88a0ded7 100755 --- a/home.admin/config.scripts/blitz.notify.sh +++ b/home.admin/config.scripts/blitz.notify.sh @@ -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