This commit is contained in:
2026-01-25 14:36:01 +01:00
commit fdf1e0e8ed
22 changed files with 1269 additions and 0 deletions

45
backend/services/email.py Normal file
View File

@@ -0,0 +1,45 @@
import aiosmtplib
from email.message import EmailMessage
import os
SMTP_HOST = os.getenv("SMTP_ADDRESS", "smtp.gmail.com")
SMTP_PORT = int(os.getenv("SMTP_PORT", 587))
SMTP_USER = os.getenv("SMTP_USER_NAME", "support@nabd-co.com")
SMTP_PASSWORD = os.getenv("SMTP_PASSWORD", "zwziglbpxyfogafc")
async def send_email(to_email: str, subject: str, body: str):
message = EmailMessage()
message["From"] = SMTP_USER
message["To"] = to_email
message["Subject"] = subject
message.set_content(body)
try:
await aiosmtplib.send(
message,
hostname=SMTP_HOST,
port=SMTP_PORT,
username=SMTP_USER,
password=SMTP_PASSWORD,
start_tls=True,
)
print(f"Email sent to {to_email}")
except Exception as e:
print(f"Failed to send email to {to_email}: {e}")
async def send_welcome_email(to_email: str, username: str, password: str):
subject = "Welcome to ASF SSO"
body = f"""
Hello {username},
Your account has been created/updated on the ASF SSO platform.
Username: {username}
Password: {password}
Please login to change your password if needed.
Regards,
ASF Team
"""
await send_email(to_email, subject, body)