Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions app/api/resend/resend.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ class EmailRequest(BaseModel):
to: EmailStr
subject: str
html: str
sender: EmailStr

@router.post("/resend", status_code=status.HTTP_202_ACCEPTED)
def send_email(request: EmailRequest):
Expand All @@ -40,8 +39,7 @@ def send_email(request: EmailRequest):
result = send_email_resend(
to=request.to,
subject=request.subject,
html=request.html,
sender=request.sender
html=request.html
)
if "error" in result:
meta = make_meta("error", result["error"])
Expand Down
26 changes: 10 additions & 16 deletions app/utils/send_email.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,20 @@
# Utility to send email using Resend API
import httpx
# Utility to send email using official Resend package
import os
import resend

RESEND_API_KEY = os.getenv("RESEND_API_KEY")
RESEND_API_URL = "https://api.resend.com/emails"
resend.api_key = os.environ.get("RESEND_API_KEY")

def send_email_resend(to: str, subject: str, html: str, sender: str) -> dict:
if not RESEND_API_KEY:
def send_email_resend(to: str, subject: str, html: str) -> dict:
if not resend.api_key:
return {"error": "Missing RESEND_API_KEY"}
headers = {
"Authorization": f"Bearer {RESEND_API_KEY}",
"Content-Type": "application/json"
}
payload = {
"from": sender,
params: resend.Emails.SendParams = {
"from": "NX <nx@goldlabel.pro>",
"to": [to],
"subject": subject,
"html": html
"html": html,
}
try:
response = httpx.post(RESEND_API_URL, headers=headers, json=payload, timeout=10)
response.raise_for_status()
return response.json()
email: resend.Emails.SendResponse = resend.Emails.send(params)
return dict(email)
except Exception as e:
return {"error": str(e)}
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
pydantic[email]>=2.0.0
resend>=0.7.0
fastapi>=0.110.0
uvicorn[standard]>=0.29.0
httpx>=0.27.0
Expand All @@ -6,4 +8,3 @@ python-dotenv>=1.0.0
psycopg2-binary>=2.9.0
python-multipart>=0.0.20
Faker>=25.2.0
pydantic[email]>=2.0.0
Loading