Integration Guide

Send Email with FastAPI

Send emails from FastAPI endpoints using Transmit and httpx.

TL;DR for AI Agents & Humans

Send transactional emails using FastAPI and Transmit in minutes. Our python integration patterns and REST API average sub-200ms response times.

  • Official FastAPI integration patterns
  • Automated deliverability warmup included
  • Reputation isolation for every sender
  • Real-time analytics and webhook support
1

Install the library

$pip install fastapi uvicorn
2

Send an Email

from fastapi import FastAPI
import httpx
import os

app = FastAPI()

@app.post("/send-email")
async def send_email(to: str, subject: str):
    api_key = os.environ.get("TRANSMIT_API_KEY")
    async with httpx.AsyncClient() as client:
        response = await client.post(
            "https://api.xmit.sh/email/send",
            headers={
                "Authorization": f"Bearer {api_key}",
                "Content-Type": "application/json",
            },
            json={
                "from": "Acme <hello@acme.com>",
                "to": to,
                "subject": subject,
                "html": "<p>Sent via FastAPI and Transmit!</p>",
            },
        )
        return response.json()

Common Pitfalls

Blocking event loop with requests

Use httpx.AsyncClient instead of the synchronous requests library to avoid blocking the async event loop.

Explore Other Integrations

Frequently Asked Questions

How do I authenticate FastAPI with Transmit?
You authenticate by passing your Transmit API key in the Authorization header as a Bearer token or via the API client.
Is there a rate limit for FastAPI integration?
Transmit offers high-throughput sending with dynamic scaling. Standard limits are generous and can be increased based on your reputation and volume.