Fix: Set the smtp default port in config to allow connect to port 25 with TLS (#1564)
Co-authored-by: Adrià Casajús <adria.casajus@proton.ch>
This commit is contained in:
parent
0a197313ea
commit
48ae859e1b
|
@ -111,11 +111,15 @@ POSTFIX_SERVER = os.environ.get("POSTFIX_SERVER", "240.0.0.1")
|
|||
DISABLE_REGISTRATION = "DISABLE_REGISTRATION" in os.environ
|
||||
|
||||
# allow using a different postfix port, useful when developing locally
|
||||
POSTFIX_PORT = int(os.environ.get("POSTFIX_PORT", 25))
|
||||
|
||||
# Use port 587 instead of 25 when sending emails through Postfix
|
||||
# Useful when calling Postfix from an external network
|
||||
POSTFIX_SUBMISSION_TLS = "POSTFIX_SUBMISSION_TLS" in os.environ
|
||||
if POSTFIX_SUBMISSION_TLS:
|
||||
default_postfix_port = 587
|
||||
else:
|
||||
default_postfix_port = 25
|
||||
POSTFIX_PORT = int(os.environ.get("POSTFIX_PORT", default_postfix_port))
|
||||
POSTFIX_TIMEOUT = os.environ.get("POSTFIX_TIMEOUT", 3)
|
||||
|
||||
# ["domain1.com", "domain2.com"]
|
||||
|
|
|
@ -117,14 +117,12 @@ class MailSender:
|
|||
return True
|
||||
|
||||
def _send_to_smtp(self, send_request: SendRequest, retries: int) -> bool:
|
||||
if config.POSTFIX_SUBMISSION_TLS and config.POSTFIX_PORT == 25:
|
||||
smtp_port = 587
|
||||
else:
|
||||
smtp_port = config.POSTFIX_PORT
|
||||
try:
|
||||
start = time.time()
|
||||
with SMTP(
|
||||
config.POSTFIX_SERVER, smtp_port, timeout=config.POSTFIX_TIMEOUT
|
||||
config.POSTFIX_SERVER,
|
||||
config.POSTFIX_PORT,
|
||||
timeout=config.POSTFIX_TIMEOUT,
|
||||
) as smtp:
|
||||
if config.POSTFIX_SUBMISSION_TLS:
|
||||
smtp.starttls()
|
||||
|
@ -170,7 +168,7 @@ class MailSender:
|
|||
LOG.e(f"Ignore smtp error {e}")
|
||||
return False
|
||||
LOG.e(
|
||||
f"Could not send message to smtp server {config.POSTFIX_SERVER}:{smtp_port}"
|
||||
f"Could not send message to smtp server {config.POSTFIX_SERVER}:{config.POSTFIX_PORT}"
|
||||
)
|
||||
self._save_request_to_unsent_dir(send_request)
|
||||
return False
|
||||
|
|
Loading…
Reference in a new issue