Minimal setup & reliable delivery

Send email in FastAPI

Add email sending to your FastAPI application in minutes with Sidemail's official Python SDK and developer‑first API. Sidemail handles deliverability, email design, and infrastructure so you can integrate reliable email sending into your FastAPI routes with minimal code.

Get startedRead API docs
Send a welcome email from a FastAPI route
from fastapi import FastAPI, Request
from services import sidemail

app = FastAPI()

@app.post("/register")
def register(request: Request, data: dict):
    # ... create user

    sidemail.send_email(
        to_address=data["email"],
        from_address="[email protected]",
        from_name="Your App",
        template_name="Welcome",
        template_props={"firstName": data["name"]},
    )

    return {"status": "registered"}

Quickstart: Send email in FastAPI

Start sending emails from your FastAPI application in three steps:

1

Install the Sidemail Python SDK

Add Sidemail to your FastAPI project via pip:

pip install sidemail
2

Create a shared Sidemail service

Create a services.py module and initialize the Sidemail client. The SDK reads SIDEMAIL_API_KEY from your environment automatically.

# services.py
from sidemail import Sidemail

sidemail = Sidemail()
3

Send email from a route

Import the client and call send_email in any FastAPI route handler. Pass the recipient, sender, and template or content. That's it.

from fastapi import FastAPI
from services import sidemail

app = FastAPI()

@app.post("/register")
def register(data: dict):
    # ... create user

    sidemail.send_email(
        to_address=data["email"],
        from_address="[email protected]",
        from_name="Your App",
        template_name="Welcome",
        template_props={"firstName": data["name"]},
    )

    return {"status": "registered"}

Key features & perks

Why Sidemail for FastAPI emails

  • Quick FastAPI email integration

    Send emails from FastAPI routes in minutes. Sidemail's Python SDK and email API integrate cleanly into FastAPI's modern Python patterns. Thorough documentation and ready‑to‑use examples get you running in <30 minutes.
  • Reliable email delivery

    Sidemail's solid infrastructure and thorough sender vetting process ensure your emails land in inboxes, not spam folders. Reliable delivery without the burden of managing your own email infrastructure.
  • Custom sending domain with DKIM & SPF

    Send from your own domain without complex DNS configuration. Sidemail automatically configures DKIM and SPF for you — two of the most critical factors for strong inbox delivery and sender reputation.
  • All‑in‑one email platform

    Sidemail covers everything in one platform – transactional and marketing emails, newsletters, email automation, subscriber collection, and contact management. A single tool for every email use case.
  • Premade email templates & no‑code editor

    Sidemail ships with a library of battle‑tested email templates that look great in every inbox. When you need something custom, the no‑code editor lets you build responsive templates from scratch without writing any HTML.
  • Best‑in‑class developer experience

    Sidemail's email API is built for busy developers — clear documentation, copy‑paste code examples in multiple languages, and features that make integration straightforward, like markdown email support, detailed delivery logs, MCP server and more

FastAPI transactional email examples

With Sidemail, you can send any transactional email from FastAPI. Here are a few examples with code:

# FastAPI: Send an account verification email
from fastapi import FastAPI
from services import sidemail

app = FastAPI()

@app.post("/register")
def register(data: dict):
    # ... create user, generate token

    sidemail.send_email(
        to_address=data["email"],
        from_address="[email protected]",
        from_name="Your App",
        template_name="Email Verification",
        template_props={
            "verifyUrl": f"https://yourapp.com/verify?token={token}",
        },
    )

    return {"status": "registered"}

Verification email

Send a sign-up verification email with a one-time link or code to confirm the user's email address.

  • Include a clear call-to-action in verification emails and make the verification link expire for security.
  • Sidemail provides a ready-made account activation template for this common use case.
See account activation email template
# FastAPI: Send a payment receipt email
from datetime import date
from services import sidemail

sidemail.send_email(
    to_address=user["email"],
    from_address="[email protected]",
    from_name="Your App",
    template_name="Payment Receipt",
    template_props={
        "userName": user["name"],
        "amount": "$19.99",
        "date": date.today().strftime("%b %d, %Y"),
    },
)

Receipt or notification email

Send a receipt, invoice, or other notification to your user.

  • For receipts and order confirmations, include key details like the total amount, date, and items in the email.
  • Pass dynamic data via template_props to populate Sidemail's receipt and invoice templates.
See receipt email template
# FastAPI: Schedule a welcome email for 1 hour from now
from datetime import datetime, timedelta, timezone
from services import sidemail

scheduled_time = datetime.now(timezone.utc) + timedelta(hours=1)

sidemail.send_email(
    to_address="[email protected]",
    from_address="[email protected]",
    from_name="Your App",
    template_name="Welcome",
    template_props={"firstName": "Alex"},
    scheduled_at=scheduled_time.isoformat(),
)

Welcome email with scheduled delivery

Schedule a welcome email to deliver later, for example one hour after registration.

  • Use the scheduled_at field with an ISO timestamp to control exactly when the email is sent.
  • Great for onboarding sequences where you want to space out messages after sign-up.
See welcome email template
# FastAPI: Send a password reset email with Markdown
from pathlib import Path
from services import sidemail

markdown = Path("templates/emails/password-reset.md").read_text()

sidemail.send_email(
    to_address="[email protected]",
    markdown=markdown,
    template_props={
        "firstName": "Alex",
        "resetLink": "https://yourapp.com/reset?token=abc123xyz",
        "expiresIn": "30 minutes",
    },
)
---
subject: "Reset your password"
fromAddress: "[email protected]"
fromName: "Your App Security"
---

Hi {firstName}, we received a request to reset your password.

[$btn Reset password]({resetLink})

This link expires in {expiresIn}.

Password reset email sent with Markdown

Sidemail's API lets you author email content in Markdown, which is automatically transformed into pixel‑perfect, responsive emails that look great in every inbox and on every device. Each email is branded with your logo and styled to match your project's email design.

  • Keep your password reset email in a .md file in your project's templates directory
  • Subject and sender are defined in the markdown frontmatter.
  • Pass dynamic values via template_props(such as resetLink and expiresIn), which map directly to variables in your markdown.

Deliverability best practices

SPF, DKIM, and DMARC for transactional email

SPF and DKIM are authentication protocols that prove your emails are legitimately sent from your domain. DMARC builds on both by telling mail servers how to handle messages that fail those checks. Together, they are 3 critical factors for inbox delivery and sender reputation.

Sidemail automatically handles SPF, DKIM, and DMARC configuration for you, so your FastAPI application sends authenticated, best‑practice‑compliant emails from the start.

Sidemail dashboard – Reliable email delivery
Graphics
Sidemail dashboard – No-code email editor
Graphics

The simplest way to build emails

No‑code email editor & premade email templates

Sidemail's no‑code email editor is the fastest way to create responsive email templates that display correctly across every client and device. No HTML knowledge required. Add your logo and brand colors, and you're ready to send.

Need to ship faster? Sidemail includes a library of production‑ready templates for the most common use cases – password resets, welcome emails, receipts, and more. Build from scratch or customize a premade template — we guarantee your emails look great everywhere.

Learn more

Developer‑friendly formatting

Markdown support for FastAPI emails

Writing and maintaining HTML emails by hand is tedious, especially when you just want to send clean, readable content.

Sidemail lets you author your email body in Markdown and automatically converts it into a responsive, well‑styled HTML email. You get smart formatting – headings, lists, links, and code blocks – without stressing about broken layouts or cross‑client rendering issues.

Perfect for transactional emails sent from your FastAPI routes – clean content, fast authoring, and zero HTML to debug.

Learn more
Markdown email code example and rendered preview

Get started today

Ready to send transactional emails from your FastAPI app? With Sidemail, you can integrate in under 30 minutes and deliver emails reliably.

Start free trial

FAQs

How do I send email in FastAPI?

The simplest way to send email from a FastAPI app is by using an email API like Sidemail. Install the Python SDK (pip install sidemail), create a shared service module, and call sidemail.send_email() from any route handler. No SMTP server or third-party mailer dependency needed. Sidemail manages authentication, formatting, and deliverability for you.

Should I use async or sync routes for sending email?

Sidemail's Python SDK is synchronous, so use regular def route handlers for email‑sending endpoints. FastAPI automatically runs sync route functions in a thread pool, so they won't block the event loop. If you want non‑blocking delivery in an async def route, use FastAPI's BackgroundTasks to offload the call.

How do I use email templates with FastAPI?

Instead of rendering HTML yourself, use Sidemail's template system. In the Sidemail dashboard, pick a premade template or build one with the drag‑and‑drop editor. In your FastAPI route, reference the template by template_name and pass dynamic data via template_props. Sidemail merges the data and returns a well‑formatted email.

Can I send email from FastAPI BackgroundTasks?

Yes. FastAPI's BackgroundTasks feature works great with Sidemail. Add a background task that calls sidemail.send_email() and the email will be sent after the response is returned to the client. This is the recommended approach for keeping endpoint latency low without setting up a task queue.

Do I need to set up SMTP for FastAPI?

No. Sidemail is an API‑based email service, so there's no SMTP server to configure or maintain. The Python SDK makes simple HTTPS calls to the Sidemail API. Just install the package, set your API key, and you're ready to send.

How do I handle email errors in FastAPI?

Wrap your sidemail.send_email() call in a try/except block and catch sidemail.SidemailError. The exception includes the HTTP status code, error type, and a clear message. Log it using Python's logging module and return an appropriate HTTP response to the client, or use FastAPI's HTTPException for structured error responses.