sendsend.email

Send email with FastAPI

A server-side call to the SendSend API from your FastAPI app.

  1. Create a test API key in the dashboard first: it never delivers real email. Switch to a live key once your domain is verified.
  2. Set SENDSEND_API_KEY in the environment that runs the app.
  3. Add this to main.py:
import os, uuid, httpx
from fastapi import FastAPI, Response

app = FastAPI()

@app.post("/send")
async def send(to: str):
    async with httpx.AsyncClient(timeout=15) as client:
        r = await client.post(
            "https://api.sendsend.email/v1/emails",
            headers={"Authorization": f"Bearer {os.environ['SENDSEND_API_KEY']}", "Idempotency-Key": str(uuid.uuid4())},
            json={"from": "Acme <hello@mail.acme.com>", "to": [to], "subject": "Hello from FastAPI", "html": "<p>It works!</p>"},
        )
    return Response(content=r.content, status_code=r.status_code, media_type="application/json")

Good to know