mirror of
https://github.com/simple-login/app.git
synced 2025-09-09 16:14:21 +08:00
Set the timeout after connect
This commit is contained in:
parent
b03d8c5798
commit
0dedb6ae9c
1 changed files with 2 additions and 12 deletions
|
@ -9,7 +9,7 @@ import uuid
|
||||||
from concurrent.futures import ThreadPoolExecutor
|
from concurrent.futures import ThreadPoolExecutor
|
||||||
from email.message import Message
|
from email.message import Message
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
from smtplib import SMTP, SMTPException, SMTPConnectError
|
from smtplib import SMTP, SMTPException
|
||||||
from typing import Optional, Dict, List, Callable
|
from typing import Optional, Dict, List, Callable
|
||||||
|
|
||||||
import newrelic.agent
|
import newrelic.agent
|
||||||
|
@ -194,19 +194,9 @@ class MailSender:
|
||||||
else:
|
else:
|
||||||
server_host = server_split[0]
|
server_host = server_split[0]
|
||||||
server_port = server_split[1]
|
server_port = server_split[1]
|
||||||
with SMTP() as smtp:
|
with SMTP(host=server_host, port=server_port) as smtp:
|
||||||
# We connect externally because we don't want to apply the overall timeout to fail fast if a server is down
|
|
||||||
(code, msg) = smtp.connect(server_host, server_port)
|
|
||||||
if code != 220:
|
|
||||||
smtp.close()
|
|
||||||
LOG.w(
|
|
||||||
f"Could not connect to server {server_host}:{server_port} code={code} msg={msg}"
|
|
||||||
)
|
|
||||||
raise SMTPConnectError(code, msg)
|
|
||||||
smtp.timeout = config.POSTFIX_TIMEOUT
|
smtp.timeout = config.POSTFIX_TIMEOUT
|
||||||
|
|
||||||
# Needed for TLS to work
|
|
||||||
smtp._host = server_host
|
|
||||||
if config.POSTFIX_SUBMISSION_TLS:
|
if config.POSTFIX_SUBMISSION_TLS:
|
||||||
smtp.starttls()
|
smtp.starttls()
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue