Made SMTP logging optional and added notification creation log

This commit is contained in:
Daniel Schick 2026-01-27 09:27:20 +01:00
parent 7365949fb5
commit 81bbad018b
3 changed files with 17 additions and 1 deletions

View File

@ -83,6 +83,8 @@ def create_app(test_config=None, instance_path=None):
if app.config.get("SECRET_KEY"):
os.environ["SECRET_KEY"] = app.config["SECRET_KEY"]
defs.SMTP_DEBUG_LEVEL = app.config.get("SMTP_DEBUG_LEVEL", defs.SMTP_DEBUG_LEVEL)
local_db.initPool(os.path.dirname(app.instance_path), config=app.config)
logging.info('App started')

View File

@ -18,3 +18,6 @@ shipcall_types = {
3: "Shifting"
}
# Email transport logging (0 = quiet, 1 = verbose)
SMTP_DEBUG_LEVEL = 0

View File

@ -142,7 +142,11 @@ def SendEmails(email_dict):
conn = smtplib.SMTP_SSL(defs.email_credentials["server"], defs.email_credentials["port"])
else:
conn = smtplib.SMTP(defs.email_credentials["server"], defs.email_credentials["port"])
conn.set_debuglevel(1) # set this to 0 to disable debug output to log
try:
smtp_debug_level = int(defs.SMTP_DEBUG_LEVEL)
except (TypeError, ValueError):
smtp_debug_level = 0
conn.set_debuglevel(1 if smtp_debug_level else 0)
conn.ehlo()
if encryption_norm in ("STARTTLS", "STARTSSL"):
conn.starttls()
@ -306,6 +310,13 @@ def SendNotifications():
pass
# mark as sent
logging.info(
"Notification finalized (level=2): id=%s shipcall_id=%s participant_id=%s type=%s",
notification.id,
notification.shipcall_id,
notification.participant_id,
notification.type,
)
commands.execute("UPDATE notification SET level = 2 WHERE id = ?id?", param={"id":notification.id})
# send emails (if any)