diff --git a/admin/app/services/email/service.py b/admin/app/services/email/service.py index 5db4b0e..fedc876 100644 --- a/admin/app/services/email/service.py +++ b/admin/app/services/email/service.py @@ -1,6 +1,7 @@ +import logging import os import smtplib -import logging +import ssl from email.message import EmailMessage from app.config import Config @@ -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 @@ -49,5 +50,3 @@ def send_email( message.set_content(template_content) server.send_message(message) - finally: - server.quit()