Spaces:
Sleeping
Sleeping
Refactor OTP handling to continue with email fallback on SMS failure; add timeout parameter to email OTP function and improve SMS client initialization
9e0fc4a Download app/utils/email_utils.py from bmsadmin/bookmyservice-ums: direct link, hf CLI and curl.
- Browser
- Download file 609 Bytes
-
https://huggingface.co/spaces/bmsadmin/bookmyservice-ums/resolve/main/app/utils/email_utils.py
- Command line
-
hf download hf://spaces/bmsadmin/bookmyservice-ums/app/utils/email_utils.py
-
curl -L -o email_utils.py https://huggingface.co/spaces/bmsadmin/bookmyservice-ums/resolve/main/app/utils/email_utils.py
609 Bytes
| import smtplib | |
| from email.mime.text import MIMEText | |
| from app.core.config import settings | |
| async def send_email_otp(to_email: str, otp: str, timeout: float = 10.0): | |
| msg = MIMEText(f"Your OTP is {otp}. It is valid for 5 minutes.") | |
| msg["Subject"] = "Your One-Time Password" | |
| msg["From"] = settings.SMTP_FROM | |
| msg["To"] = to_email | |
| server = smtplib.SMTP(settings.SMTP_HOST, settings.SMTP_PORT, timeout=timeout) | |
| server.connect(settings.SMTP_HOST, settings.SMTP_PORT) | |
| server.starttls() | |
| server.login(settings.SMTP_USER, settings.SMTP_PASS) | |
| server.send_message(msg) | |
| server.quit() |