Skip to content

Commit 8b51643

Browse files
committed
set a configurable timeout for SMTP server: default = 10 sec
1 parent 34f1718 commit 8b51643

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

sources/README-dockerhub-orthanc-auth-service.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ in authorization headers that will be checked by the [Authorization plugin](http
3232
| EMAILS_SMTP_SERVER_HOSTNAME | - | The hostname of the SMTP Server |
3333
| EMAILS_SMTP_SERVER_PORT | - | The port of the SMTP Server |
3434
| EMAILS_SMTP_SERVER_USES_TLS | true | Weither SMTP Server requires TLS |
35+
| EMAILS_SMTP_SERVER_TIMEOUT | 10 | The timeout, in seconds, to use to connect to the SMTP Server |
3536
| EMAILS_SMTP_SERVER_USER_NAME | - | The username used to connect to the SMTP Server |
3637
| EMAILS_SMTP_SERVER_PWD | - | The password used to connect to the SMTP Server |
3738
| EMAILS_SENDER_ADDRESS | - | The email address that is used to send the email from |

sources/orthanc_auth_service/app.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@
9696
smtp_password = get_secret_or_die("EMAILS_SMTP_SERVER_PWD")
9797
smtp_hostname = get_secret_or_die("EMAILS_SMTP_SERVER_HOSTNAME")
9898
smtp_port = int(get_secret_or_die("EMAILS_SMTP_SERVER_PORT"))
99-
smtp_enable_ssl = get_secret_or_die("EMAILS_SMTP_SERVER_USES_TLS") != 'false'
99+
smtp_enable_tls = get_secret_or_die("EMAILS_SMTP_SERVER_USES_TLS") != 'false'
100+
smtp_timeout = float(os.environ.get("EMAILS_SMTP_SERVER_TIMEOUT", "10"))
100101

101102
else:
102103
logging.warning("EMAIL support is disabled")
@@ -345,8 +346,8 @@ def send_email(request: SendEmailRequest):
345346

346347
# Send the email
347348
try:
348-
with smtplib.SMTP(smtp_hostname, smtp_port) as server:
349-
if smtp_enable_ssl:
349+
with smtplib.SMTP(smtp_hostname, smtp_port, timeout=smtp_timeout) as server:
350+
if smtp_enable_tls:
350351
server.starttls()
351352
server.login(smtp_login, smtp_password)
352353
server.sendmail(email_sender, split_emails(request.destination_email), message.as_string())

0 commit comments

Comments
 (0)