Skip to content

Commit

Permalink
adds starttls parameter into smtp
Browse files Browse the repository at this point in the history
  • Loading branch information
kartaris authored Jan 30, 2025
1 parent a864ddc commit e914f76
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions fief/services/email/smtp.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ def __init__(
password: str | None = None,
port: int = 587,
ssl: bool | None = True,
starttls: bool | None = True,
) -> None:
self.username = username
self.password = password
self.host = host
self.port = port
self.ssl = ssl
self.starttls = starttls

def send_email(
self,
Expand All @@ -49,8 +51,10 @@ def send_email(
if text is not None:
message.add_alternative(text, subtype="plain")

with smtplib.SMTP(self.host, self.port) as server:
if self.ssl:
SMTP = smtplib.SMTP if self.ssl and self.starttls else smtplib.SMTP_SSL

with SMTP(self.host, self.port) as server:
if self.ssl and self.starttls:
context = ssl.create_default_context()
server.starttls(context=context)
if self.username and self.password:
Expand Down

0 comments on commit e914f76

Please sign in to comment.