Merge pull request #179 from SamR1/fix-email

Fix sending email w/ TLS
This commit is contained in:
Sam 2022-04-23 07:29:47 +02:00 committed by GitHub
commit 637df2c3b3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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()