Skip to content

Commit

Permalink
smtp cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Schimpf committed Mar 4, 2024
1 parent a85a6d7 commit a5379b5
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions admin/app/services/email/service.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import logging
import os
import smtplib
import logging
import ssl
from email.message import EmailMessage

from app.config import Config
Expand All @@ -26,10 +27,10 @@ def send_email(
logger.info('Skipping email...')
return

server = smtplib.SMTP_SSL(host=Config.SMTP_HOST, port=Config.SMTP_PORT)
try:
server.ehlo()
server.login(user=Config.SMTP_HOST, password=Config.SMTP_PASSWORD)
context = ssl.create_default_context()
with smtplib.SMTP(host=Config.SMTP_HOST, port=Config.SMTP_PORT) as server:
server.starttls(context=context)
server.login(user=Config.SMTP_USER, password=Config.SMTP_PASSWORD)

message = EmailMessage()
message['Subject'] = subject
Expand All @@ -49,5 +50,3 @@ def send_email(
message.set_content(template_content)

server.send_message(message)
finally:
server.quit()

0 comments on commit a5379b5

Please sign in to comment.