-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathresend.py
More file actions
48 lines (40 loc) · 1.48 KB
/
Copy pathresend.py
File metadata and controls
48 lines (40 loc) · 1.48 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
from app import __version__
import os
from app.utils.make_meta import make_meta
from fastapi import APIRouter, Query, Path, Body, HTTPException
from app.utils.db import get_db_connection
from app.utils.send_email import send_email_resend
router = APIRouter()
base_url = os.getenv("BASE_URL", "http://localhost:8000")
RESEND_API_KEY = os.getenv("RESEND_API_KEY")
@router.get("/resend")
def root() -> dict:
"""GET /resend endpoint."""
if not RESEND_API_KEY:
meta = make_meta("error", "RESEND_API_KEY is missing from environment. Please set it in your .env file.")
return {"meta": meta}
meta = make_meta("success", "Resend endpoint")
return {"meta": meta}
# POST endpoint to send email
from fastapi import status
from pydantic import BaseModel, EmailStr
class EmailRequest(BaseModel):
to: EmailStr
subject: str
html: str
@router.post("/resend", status_code=status.HTTP_202_ACCEPTED)
def send_email(request: EmailRequest):
"""POST /resend endpoint to send email via Resend API."""
if not RESEND_API_KEY:
meta = make_meta("error", "RESEND_API_KEY missing. Please set it in your .env file.")
return {"meta": meta}
result = send_email_resend(
to=request.to,
subject=request.subject,
html=request.html
)
if "error" in result:
meta = make_meta("error", result["error"])
return {"meta": meta}
meta = make_meta("success", "Email sent successfully.")
return {"meta": meta, "data": result}