mirror of
https://github.com/Retropex/raspiblitz.git
synced 2025-05-13 03:30:49 +02:00
Merge branch 'fix-notify' of https://github.com/frennkie/raspiblitz into frennkie-fix-notify
This commit is contained in:
commit
ecb5f67a12
@ -79,33 +79,33 @@ source /mnt/hdd/raspiblitz.conf 2>/dev/null
|
|||||||
if [ "$1" = "1" ] || [ "$1" = "on" ]; then
|
if [ "$1" = "1" ] || [ "$1" = "on" ]; then
|
||||||
echo "switching the NOTIFY ON"
|
echo "switching the NOTIFY ON"
|
||||||
|
|
||||||
# install sstmp if not already present
|
# install mstmp if not already present
|
||||||
if ! command -v ssmtp >/dev/null; then
|
if ! command -v msmtp >/dev/null; then
|
||||||
[ -z "$(find -H /var/lib/apt/lists -maxdepth 0 -mtime -7)" ] && sudo apt-get update
|
[ -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
|
fi
|
||||||
|
|
||||||
# install python lib for smime into virtual env
|
# install python lib for smime into virtual env
|
||||||
sudo -H /usr/bin/python3 -m pip install smime
|
sudo -H /usr/bin/python3 -m pip install smime
|
||||||
|
|
||||||
# write ssmtp config
|
# write ssmtp config
|
||||||
cat << EOF | sudo tee /etc/ssmtp/ssmtp.conf >/dev/null
|
cat << EOF | sudo tee /etc/msmtprc >/dev/null
|
||||||
#
|
# Set default values for all following accounts.
|
||||||
# Config file for sSMTP sendmail
|
defaults
|
||||||
#
|
port 587
|
||||||
# The person who gets all mail for userids < 1000
|
tls on
|
||||||
# Make this empty to disable rewriting.
|
tls_trust_file /etc/ssl/certs/ca-certificates.crt
|
||||||
Root=${notifyMailTo}
|
|
||||||
|
|
||||||
# hostname of this system
|
account mail
|
||||||
Hostname=${notifyMailHostname}
|
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
|
EOF
|
||||||
|
|
||||||
# edit raspi blitz config
|
# edit raspi blitz config
|
||||||
@ -137,7 +137,7 @@ if [ "$1" = "send" ]; then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ! command -v ssmtp >/dev/null; then
|
if ! command -v msmtp >/dev/null; then
|
||||||
echo "please run \"on\" first"
|
echo "please run \"on\" first"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
@ -11,7 +11,7 @@ try:
|
|||||||
except ImportError:
|
except ImportError:
|
||||||
raise ImportError("Please install missing package: python3 -m pip install smime")
|
raise ImportError("Please install missing package: python3 -m pip install smime")
|
||||||
|
|
||||||
SSMTP_BIN = "/usr/sbin/ssmtp"
|
SMTP_BIN = "/usr/bin/msmtp"
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
@ -107,7 +107,7 @@ def mail(recipient: str = None, message: str = None, subject: str = None, cert:
|
|||||||
'From: {} <{}>'.format(from_name, from_address),
|
'From: {} <{}>'.format(from_name, from_address),
|
||||||
"Subject: {}".format(subject),
|
"Subject: {}".format(subject),
|
||||||
"",
|
"",
|
||||||
"{}".format(message.encode('utf8'))
|
"{}".format(message)
|
||||||
]
|
]
|
||||||
|
|
||||||
with open(cert, 'rb') as pem:
|
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()
|
msg_to_send = msg.as_bytes()
|
||||||
|
|
||||||
# send message via e-Mail
|
# send message via e-Mail
|
||||||
if not os.path.exists(SSMTP_BIN):
|
if not os.path.exists(SMTP_BIN):
|
||||||
raise Exception("File not found: {}".format(SSMTP_BIN))
|
raise Exception("File not found: {}".format(SMTP_BIN))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
cmd = [SSMTP_BIN, recipient]
|
cmd = [SMTP_BIN, recipient]
|
||||||
subprocess.run(cmd, input=msg_to_send, stderr=subprocess.STDOUT)
|
subprocess.run(cmd, input=msg_to_send, stderr=subprocess.STDOUT)
|
||||||
|
|
||||||
except subprocess.CalledProcessError as err:
|
except subprocess.CalledProcessError as err:
|
||||||
|
Loading…
Reference in New Issue
Block a user