FastAPI-Mail

Tools & Infrastructure 💻 Python ⚖️ MIT 🟢 Actively maintained
1.0k stars

FastAPI-Mail is a lightweight mail system for FastAPI that simplifies sending emails, attachments, and HTML templates. It solves the problem of integrating email functionality into FastAPI applications with minimal configuration. It is intended for developers building FastAPI-based services that need to send emails.

✨ Key features

  • Simple lightweight mail system for FastAPI
  • Send emails with attachments and HTML templates
  • Easy configuration via ConnectionConfig
  • Supports SSL/TLS and STARTTLS
  • Uses Pydantic models for email schemas
  • Asynchronous email sending with FastMail

🎯 Use cases

  • Send transactional emails from a FastAPI backend
  • Send HTML email templates with dynamic content
  • Send emails with attachments in FastAPI applications
  • Implement email verification or password reset flows

📦 Installation

🧰 Requirements: Requires Python with FastAPI and Pydantic installed; no external API keys or accounts needed, but you need SMTP server credentials.

pip install fastapi-mail

🚀 Usage

from typing import List

from fastapi import FastAPI
from fastapi_mail import ConnectionConfig, FastMail, MessageSchema, MessageType, NameEmail
from pydantic import BaseModel
from starlette.responses import JSONResponse

class EmailSchema(BaseModel):
    email: List[NameEmail]

conf = ConnectionConfig(
    MAIL_USERNAME="username",
    MAIL_PASSWORD="**********",
    MAIL_FROM="test@email.com",
    MAIL_PORT=465,
    MAIL_SERVER="mail server",
    MAIL_STARTTLS=False,
    MAIL_SSL_TLS=True,
    USE_CREDENTIALS=True,
    VALIDATE_CERTS=True,
)

app = FastAPI()

@app.post("/email")
async def simple_send(email: EmailSchema) -> JSONResponse:
    message = MessageSchema(
        subject="Fastapi-Mail module",
        recipients=email.model_dump().get("email"),
        body=" Thanks for using Fastapi-mail ",
        subtype=MessageType.html,
    )
    await FastMail(conf).send_message(message)
    return JSONResponse(status_code=200, content={"message": "email has been sent"})

⚠️ Good to know

No limitations or project status are mentioned in the README.

❓ FAQ

How do I install FastAPI-Mail?

Install it via pip with the command: pip install fastapi-mail.

What configuration is required to send emails?

You need to provide SMTP server details such as MAIL_SERVER, MAIL_PORT, MAIL_USERNAME, MAIL_PASSWORD, and MAIL_FROM in a ConnectionConfig object.

Can I send HTML emails?

Yes, you can set the subtype parameter to MessageType.html in the MessageSchema to send HTML content.

Is FastAPI-Mail asynchronous?

Yes, it uses async/await, as shown in the example where the send_message method is awaited.

📊 Repository

Stars★ 1,011
Forks🍴 111
Open issues🐛 4
Last commit🕒 Aug 24, 2026
Created📅 Jan 2020
Language💻 Python
License⚖️ MIT

🤖 Overview, features, install steps and FAQ were generated from the project's README on Sep 4, 2026. Always check the original source before running commands.