Skip to content

Commit fac5091

Browse files
Merge pull request #49 from goldlabelapps/staging
Use official Resend SDK and remove sender field
2 parents f4e87ba + bf027d1 commit fac5091

3 files changed

Lines changed: 13 additions & 20 deletions

File tree

app/api/resend/resend.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ class EmailRequest(BaseModel):
2929
to: EmailStr
3030
subject: str
3131
html: str
32-
sender: EmailStr
3332

3433
@router.post("/resend", status_code=status.HTTP_202_ACCEPTED)
3534
def send_email(request: EmailRequest):
@@ -40,8 +39,7 @@ def send_email(request: EmailRequest):
4039
result = send_email_resend(
4140
to=request.to,
4241
subject=request.subject,
43-
html=request.html,
44-
sender=request.sender
42+
html=request.html
4543
)
4644
if "error" in result:
4745
meta = make_meta("error", result["error"])

app/utils/send_email.py

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,20 @@
1-
# Utility to send email using Resend API
2-
import httpx
1+
# Utility to send email using official Resend package
32
import os
3+
import resend
44

5-
RESEND_API_KEY = os.getenv("RESEND_API_KEY")
6-
RESEND_API_URL = "https://api.resend.com/emails"
5+
resend.api_key = os.environ.get("RESEND_API_KEY")
76

8-
def send_email_resend(to: str, subject: str, html: str, sender: str) -> dict:
9-
if not RESEND_API_KEY:
7+
def send_email_resend(to: str, subject: str, html: str) -> dict:
8+
if not resend.api_key:
109
return {"error": "Missing RESEND_API_KEY"}
11-
headers = {
12-
"Authorization": f"Bearer {RESEND_API_KEY}",
13-
"Content-Type": "application/json"
14-
}
15-
payload = {
16-
"from": sender,
10+
params: resend.Emails.SendParams = {
11+
"from": "NX <nx@goldlabel.pro>",
1712
"to": [to],
1813
"subject": subject,
19-
"html": html
14+
"html": html,
2015
}
2116
try:
22-
response = httpx.post(RESEND_API_URL, headers=headers, json=payload, timeout=10)
23-
response.raise_for_status()
24-
return response.json()
17+
email: resend.Emails.SendResponse = resend.Emails.send(params)
18+
return dict(email)
2519
except Exception as e:
2620
return {"error": str(e)}

requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
pydantic[email]>=2.0.0
2+
resend>=0.7.0
13
fastapi>=0.110.0
24
uvicorn[standard]>=0.29.0
35
httpx>=0.27.0
@@ -6,4 +8,3 @@ python-dotenv>=1.0.0
68
psycopg2-binary>=2.9.0
79
python-multipart>=0.0.20
810
Faker>=25.2.0
9-
pydantic[email]>=2.0.0

0 commit comments

Comments
 (0)