Handle exceptions when sending mail
This commit is contained in:
parent
5262c64244
commit
4ef3efbc68
|
@ -21,6 +21,7 @@ import ldap3
|
||||||
from . import db
|
from . import db
|
||||||
|
|
||||||
def mail(rcpt, subject, body):
|
def mail(rcpt, subject, body):
|
||||||
|
try:
|
||||||
msg = email.message.EmailMessage()
|
msg = email.message.EmailMessage()
|
||||||
msg['Subject'] = f'friwall: {subject}'
|
msg['Subject'] = f'friwall: {subject}'
|
||||||
msg['From'] = f'{getpass.getuser()}@{socket.getfqdn()}'
|
msg['From'] = f'{getpass.getuser()}@{socket.getfqdn()}'
|
||||||
|
@ -28,6 +29,8 @@ def mail(rcpt, subject, body):
|
||||||
msg.set_content(body)
|
msg.set_content(body)
|
||||||
with smtplib.SMTP('localhost') as server:
|
with smtplib.SMTP('localhost') as server:
|
||||||
server.send_message(msg)
|
server.send_message(msg)
|
||||||
|
except Exception as e:
|
||||||
|
syslog.syslog(f'error sending mail: {e}')
|
||||||
|
|
||||||
def init_app(app):
|
def init_app(app):
|
||||||
app.cli.add_command(generate)
|
app.cli.add_command(generate)
|
||||||
|
|
Loading…
Reference in a new issue