68 lines
1.9 KiB
Python
68 lines
1.9 KiB
Python
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)
|
|
|
|
async def send_request_received_email(to_email: str, username: str):
|
|
subject = "Access Request Received"
|
|
body = f"""
|
|
Hello {username},
|
|
|
|
We have received your request for access to the ASF SSO platform.
|
|
An administrator will review your request shortly.
|
|
|
|
Regards,
|
|
ASF Team
|
|
"""
|
|
await send_email(to_email, subject, body)
|
|
|
|
async def send_admin_notification_email(username: str):
|
|
to_email = "admin@nabd-co.com" # Default admin email
|
|
subject = "New Access Request"
|
|
body = f"""
|
|
A new access request has been submitted by {username}.
|
|
Please log in to the admin portal to review it.
|
|
"""
|
|
await send_email(to_email, subject, body)
|