Quick setup examples

FastAPI

Send your first email from a FastAPI endpoint by calling the MailBlastr API with httpx.

Python has an official package — pip install mailblastr — and it works unchanged from a FastAPI route. The example below instead POSTs JSON to https://www.mailblastr.com/api/emails with the async `httpx` client, which pairs naturally with FastAPI. See SDKs for the package.

Prerequisites

1. Install an HTTP client

Pip
pip install httpx

2. Set your API key

.env
MAILBLASTR_API_KEY=mb_xxxxxxxxx

3. Send email from an endpoint

POST the email body to the MailBlastr API from a route handler. The easiest way to send is with the html field.

main.py
import os
import httpx
from fastapi import FastAPI

app = FastAPI()


@app.post("/")
async def send_mail():
    async with httpx.AsyncClient() as client:
        res = await client.post(
            "https://www.mailblastr.com/api/emails",
            headers={"Authorization": f"Bearer {os.environ['MAILBLASTR_API_KEY']}"},
            json={
                "from": "Acme <onboarding@yourdomain.com>",
                "to": ["delivered@mailblastr.dev"],
                "subject": "hello world",
                "html": "<strong>it works!</strong>",
            },
        )
    res.raise_for_status()
    return res.json()
A successful call returns the created email's id. See every supported field in the Send an email reference.