add forgot password page

This commit is contained in:
David Rodenkirchen
2024-08-26 23:31:27 +02:00
parent 4a6b09f41c
commit 704184d6f9
5 changed files with 128 additions and 17 deletions
+15 -16
View File
@@ -1,7 +1,6 @@
import logging
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from smtplib import SMTP
from email.message import EmailMessage
import aiosmtplib
from src.ez_lan_manager.types.ConfigurationTypes import MailingServiceConfiguration
@@ -11,20 +10,20 @@ class MailingService:
def __init__(self, configuration: MailingServiceConfiguration):
self._config = configuration
def send_email(self, subject: str, body: str, receiver: str) -> None:
# ToDo: Check with Rio/FastAPI if this needs to be ASYNC
async def send_email(self, subject: str, body: str, receiver: str) -> None:
try:
msg = MIMEMultipart()
msg['From'] = self._config.sender
msg['To'] = receiver
msg['Subject'] = subject
msg.attach(MIMEText(body, 'plain'))
with SMTP(self._config.smtp_server, self._config.smtp_port) as server:
server.starttls()
server.login(self._config.username, self._config.password)
server.sendmail(self._config.sender, receiver, msg.as_string())
message = EmailMessage()
message["From"] = self._config.sender
message["To"] = receiver
message["Subject"] = subject
message.set_content(body)
await aiosmtplib.send(
message,
hostname=self._config.smtp_server,
port=self._config.smtp_port,
username=self._config.username,
password=self._config.password
)
except Exception as e:
logger.error(f"Failed to send email: {e}")