Handle exceptions when sending mail

This commit is contained in:
Timotej Lazar 2023-07-07 09:04:17 +02:00
parent 5262c64244
commit 4ef3efbc68

View file

@ -21,6 +21,7 @@ import ldap3
from . import db
def mail(rcpt, subject, body):
try:
msg = email.message.EmailMessage()
msg['Subject'] = f'friwall: {subject}'
msg['From'] = f'{getpass.getuser()}@{socket.getfqdn()}'
@ -28,6 +29,8 @@ def mail(rcpt, subject, body):
msg.set_content(body)
with smtplib.SMTP('localhost') as server:
server.send_message(msg)
except Exception as e:
syslog.syslog(f'error sending mail: {e}')
def init_app(app):
app.cli.add_command(generate)