Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Add SMTP Timeout #4437

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions mealie/services/email/email_senders.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@

from mealie.services._base_service import BaseService

SMTP_TIMEOUT = 10
"""Timeout in seconds for SMTP connection"""


@dataclass(slots=True)
class EmailOptions:
Expand Down Expand Up @@ -55,13 +58,13 @@ def send(self, to: str, smtp: EmailOptions) -> SMTPResponse:
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:
Expand Down
Loading