fix(email): handle SMTP servers without AUTH support

This commit is contained in:
c0mrade
2026-01-25 14:35:51 +03:00
parent 99c60793b8
commit 989da445be

View File

@@ -29,14 +29,21 @@ class EmailService:
def _get_smtp_connection(self) -> smtplib.SMTP:
"""Create and return SMTP connection."""
if self.use_tls:
smtp = smtplib.SMTP(self.host, self.port)
smtp.starttls()
else:
smtp = smtplib.SMTP(self.host, self.port)
smtp = smtplib.SMTP(self.host, self.port)
smtp.ehlo()
if self.use_tls:
smtp.starttls()
smtp.ehlo()
# Only attempt login if credentials are provided AND server supports AUTH
if self.user and self.password:
smtp.login(self.user, self.password)
if smtp.has_extn('auth'):
smtp.login(self.user, self.password)
else:
logger.debug(
f'SMTP server {self.host} does not support AUTH, skipping authentication'
)
return smtp