Skip to content

Commit

Permalink
Add secure email connections
Browse files Browse the repository at this point in the history
  • Loading branch information
flavien-hugs committed Aug 17, 2024
1 parent a5086d8 commit 0dd8b22
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/shared/send_email.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import logging
import smtplib
import ssl
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText

Expand Down Expand Up @@ -53,7 +54,8 @@ async def send_email(self, receiver_email: list[EmailStr], subject: str, body: s

try:
with smtplib.SMTP(host=self.smtp_server, port=self.smtp_port) as server:
server.starttls()
server.ehlo()
server.starttls(context=ssl.create_default_context())
server.login(user=self.email_address, password=self.email_password)
server.sendmail(from_addr=self.email_address, to_addrs=receiver_email, msg=message.as_string())
server.quit()
Expand Down

0 comments on commit 0dd8b22

Please sign in to comment.