API - fix sending email w/ tls

This commit is contained in:
Sam 2022-04-23 06:11:08 +02:00
parent 8c4436a0ef
commit e9885bfbff

View File

@ -131,9 +131,11 @@ class EmailService:
with self.smtp( with self.smtp(
self.host, self.port, **connection_params # type: ignore self.host, self.port, **connection_params # type: ignore
) as smtp: ) as smtp:
if self.use_tls:
smtp.ehlo()
smtp.starttls(context=context)
smtp.ehlo()
if self.username and self.password: if self.username and self.password:
smtp.login(self.username, self.password) # type: ignore smtp.login(self.username, self.password) # type: ignore
if self.use_tls:
smtp.starttls(context=context)
smtp.sendmail(self.sender_email, recipient, message.as_string()) smtp.sendmail(self.sender_email, recipient, message.as_string())
smtp.quit() smtp.quit()