fastapi-mail
Simple lightweight mail library for FastApi
What it is and what it does
fastapi-mail is a lightweight async email library designed for FastAPI applications. It wraps aiosmtplib to send emails and attachments over SMTP, supporting both individual and bulk sends. The package integrates with FastAPI's background task system, allowing you to queue email sends without blocking request handling. It includes utilities for validating email addresses and supports Jinja2 HTML templates for message bodies, plus a NameEmail format that lets recipients be specified as "Name <email@domain.com>".
The library is built on standard async patterns (aiosmtplib, httpx, pydantic) and requires Python 3.10+. Configuration is handled via a ConnectionConfig object where you supply SMTP credentials, server details, and TLS settings. You create a FastMail instance, build a MessageSchema with subject, recipients, and body, then call send_message() to dispatch it asynchronously.
Use it for:
- Send transactional emails (password resets, confirmations) from FastAPI endpoints without blocking the response.
- Queue bulk email campaigns using FastAPI background tasks to distribute sends over time.
- Render personalized HTML emails using Jinja2 templates with dynamic data from your application.
- Validate recipient email addresses before sending using the built-in email utility classes.
- Attach files from server storage or form uploads to outgoing messages.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Sends emails and attachments asynchronously from FastAPI applications using SMTP, with support for HTML templates, bulk messaging, and background task integration.
Yes. fastapi-mail is actively maintained, has low install friction, carries no known vulnerabilities, and is the standard choice for async email in FastAPI projects. The MIT license imposes no restrictions. Install it if you need to send email from a FastAPI application.
Install
fastapi-mail on PyPI
pip
pip install fastapi-mailuv
uv add fastapi-mailpoetry
poetry add fastapi-mailInstalling fastapi-mail
Before you install
Low friction install with a pure-Python wheel. Active maintenance with a release within the last 57 days. Depends on 11 runtime packages including cryptography and email-validator, all standard ecosystem choices.
License in practice
MIT license is permissive; you can use, modify, and distribute this package freely in commercial and private projects with minimal restrictions.
Quickstart
pip install fastapi-mail
from fastapi_mail import ConnectionConfig, FastMail, MessageSchema
from fastapi import FastAPI
conf = ConnectionConfig(
MAIL_USERNAME="user",
MAIL_PASSWORD="pass",
MAIL_FROM="sender@example.com",
MAIL_PORT=465,
MAIL_SERVER="smtp.example.com",
MAIL_SSL_TLS=True
)
app = FastAPI()
fm = FastMail(conf)
await fm.send_message(MessageSchema(subject="Test", recipients=["user@example.com"], body="Hello"))
Requires Python 3.10 or later. SMTP server credentials and network access to a mail server are required at runtime.
Verify before relying
- Whether the package handles connection pooling or reuses SMTP connections efficiently under load.
- Performance characteristics when sending bulk emails (number of concurrent sends, rate limits).
- Whether Jinja2 template rendering is automatic or requires manual setup beyond what the fact sheet shows.
Package facts
| License | MIT (permissive) |
| Python support | supports the current Python release (>=3.10) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 11 — aiosmtplib, blinker, cryptography, email-validator, httpx, jinja2, pydantic, pydantic-settings, regex, starlette, typing-extensions |
| Maintenance | actively maintained — 57 days since the last release |
| First released | |
| Downloads | 1,426,701/month — #3,914 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: fastapi_mail-1.6.5-py3-none-any.whl
Tags
More Dynamic Content packages
MarkupSafe provides a text object that escapes…
permissive · top 100 on PyPI
Jinja2Jinja2 is a templating engine that renders…
permissive · top 100 on PyPI
soupsieveSoupsieve is a CSS selector library designed to…
permissive · top 100 on PyPI
WerkzeugWerkzeug is a WSGI utility library providing…
permissive · top 1,000 on PyPI
FlaskFlask is a lightweight WSGI web application…
permissive · top 1,000 on PyPI
MakoMako compiles Python-embedded templates into…
permissive · top 1,000 on PyPI
azure-communication-emailSends emails via Azure Communication Services,…
permissive · top 5,000 on PyPI
yagmailSimplifies sending emails via Gmail or any SMTP…
permissive · top 15,000 on PyPI
django-post_officeDjango Post Office queues and sends emails…
permissive · top 15,000 on PyPI
fastapi-eventsFastapi-events is an event dispatching and…
permissive · top 15,000 on PyPI
redmailRedmail simplifies sending emails with Python…
permissive · top 15,000 on PyPI
emailsBuild and send HTML and plain-text emails with…
permissive · top 15,000 on PyPI
aiosmtplibaiosmtplib is an asynchronous SMTP client that…
permissive · top 5,000 on PyPI
resendResend Python SDK provides a client library for…
permissive · top 5,000 on PyPI
aioimaplibAn asyncio-based IMAP4rev1 client library that…
copyleft · top 15,000 on PyPI
codewords-clientA Python client library for the Codewords API…
permissive · top 5,000 on PyPI