1
0
Fork 0
mirror of https://github.com/mealie-recipes/mealie.git synced 2025-08-05 21:45:25 +02:00

fix: Add SMTP Timeout (#4437)

This commit is contained in:
Michael Genson 2024-10-24 10:58:24 -05:00 committed by GitHub
parent 34bd4a74c2
commit 2305438423
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -10,6 +10,9 @@ from html2text import html2text
from mealie.services._base_service import BaseService
SMTP_TIMEOUT = 10
"""Timeout in seconds for SMTP connection"""
@dataclass(slots=True)
class EmailOptions:
@ -55,13 +58,13 @@ class Message:
msg["MIME-Version"] = "1.0"
if smtp.ssl:
with smtplib.SMTP_SSL(smtp.host, smtp.port) as server:
with smtplib.SMTP_SSL(smtp.host, smtp.port, timeout=SMTP_TIMEOUT) as server:
if smtp.username and smtp.password:
server.login(smtp.username, smtp.password)
errors = server.send_message(msg)
else:
with smtplib.SMTP(smtp.host, smtp.port) as server:
with smtplib.SMTP(smtp.host, smtp.port, timeout=SMTP_TIMEOUT) as server:
if smtp.tls:
server.starttls()
if smtp.username and smtp.password: