File size: 824 Bytes
bf1408e
eae1ad4
2904909
 
acc8c5b
eae1ad4
acc8c5b
 
 
eae1ad4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
acc8c5b
eae1ad4
acc8c5b
eae1ad4
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import os
import requests
from dotenv import load_dotenv
load_dotenv()

SENDGRID_API_KEY = os.getenv("SENDGRID_API_KEY")
SENDER_EMAIL = os.getenv("SENDER_EMAIL")

def send_otp_email(receiver_email, otp):
    url = "https://api.sendgrid.com/v3/mail/send"

    headers = {
        "Authorization": f"Bearer {SENDGRID_API_KEY}",
        "Content-Type": "application/json"
    }

    data = {
        "personalizations": [{
            "to": [{"email": receiver_email}]
        }],
        "from": {"email": SENDER_EMAIL},
        "subject": "Your FitPlan AI OTP",
        "content": [{
            "type": "text/plain",
            "value": f"Your OTP is: {otp}"
        }]
    }

    response = requests.post(url, headers=headers, json=data)

    if response.status_code != 202:
        raise Exception("Failed to send email")