File size: 609 Bytes
b407a42
 
 
 
9e0fc4a
b407a42
 
 
 
 
9e0fc4a
3542545
b407a42
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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()