File size: 510 Bytes
b407a42
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
import smtplib
from email.mime.text import MIMEText
from app.core.config import settings

async def send_email_otp(to_email: str, otp: str):
    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)
    server.starttls()
    server.login(settings.SMTP_USER, settings.SMTP_PASS)
    server.send_message(msg)
    server.quit()