All guides

Send Email from FastAPI

Send emails from FastAPI with async support

1. Install the SDK

pip install sendpigeon

2. Set your API key

Add your SendPigeon API key to your environment variables:

SENDPIGEON_API_KEY=your_api_key_here

Get your API key from the dashboard.

3. Send your first email

import os
from fastapi import FastAPI
from pydantic import BaseModel, EmailStr
from sendpigeon import SendPigeon

app = FastAPI()
client = SendPigeon(os.environ["SENDPIGEON_API_KEY"])

class ContactRequest(BaseModel):
    email: EmailStr
    name: str

@app.post("/contact")
async def contact(data: ContactRequest):
    client.send(
        to=data.email,
        from_email="hello@yourdomain.com",
        subject=f"Thanks for reaching out, {data.name}!",
        html="<h1>We got your message</h1><p>We'll get back to you soon.</p>",
    )

    return {"success": True}

Features

  • Async-native integration
  • Pydantic validation
  • OpenAPI docs included

Ready to send emails?

Get started with 1,000 free emails per month.

Start for free