mirror of
https://github.com/FAUSheppy/flask-json-dream-website
synced 2025-12-06 08:11:35 +01:00
fix: smtp check crash
In a container, the smtp check would fail, even if SMTP_MUST_BE_CONNECTED was false, because no address was bindable
This commit is contained in:
11
smtp.py
11
smtp.py
@@ -5,6 +5,10 @@ import email.message
|
|||||||
def checkSMTPConnection(app):
|
def checkSMTPConnection(app):
|
||||||
'''Check connection and login on SMTP server configured in app config'''
|
'''Check connection and login on SMTP server configured in app config'''
|
||||||
|
|
||||||
|
if not app.config["SMTP_MUST_BE_CONNECTED"]:
|
||||||
|
print("Warning: SMTP unusable: {}".format(e), file=sys.stderr)
|
||||||
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if not all([ x in app.config and app.config[x] for x in ["TARGET_SMTP", "TARGET_EMAIL"]]):
|
if not all([ x in app.config and app.config[x] for x in ["TARGET_SMTP", "TARGET_EMAIL"]]):
|
||||||
raise smtplib.SMTPException("Missing Configuration.")
|
raise smtplib.SMTPException("Missing Configuration.")
|
||||||
@@ -13,11 +17,8 @@ def checkSMTPConnection(app):
|
|||||||
smtp.login(app.config["TARGET_SMTP_USER"], app.config["TARGET_SMTP_PASSWORD"])
|
smtp.login(app.config["TARGET_SMTP_USER"], app.config["TARGET_SMTP_PASSWORD"])
|
||||||
smtpTarget.quit()
|
smtpTarget.quit()
|
||||||
except (smtplib.SMTPException, ConnectionRefusedError) as e:
|
except (smtplib.SMTPException, ConnectionRefusedError) as e:
|
||||||
if app.config["SMTP_MUST_BE_CONNECTED"]:
|
print(e, file=sys.stderr)
|
||||||
print(e, file=sys.stderr)
|
sys.exit(1)
|
||||||
sys.exit(1)
|
|
||||||
else:
|
|
||||||
print("Warning: SMTP unusable: {}".format(e), file=sys.stderr)
|
|
||||||
|
|
||||||
def sendMailFromHtmlForm(app, htmlForm):
|
def sendMailFromHtmlForm(app, htmlForm):
|
||||||
'''Take the app config and the contact HTML-form and send a mail accordingly'''
|
'''Take the app config and the contact HTML-form and send a mail accordingly'''
|
||||||
|
|||||||
Reference in New Issue
Block a user