Skip to main content

micromailer

Ultra-fast, modular, zero-dependency async email engine for Python, FastAPI, and Django.

  • Zero runtime dependencies
  • Async SMTP with automatic STARTTLS / implicit TLS
  • HTTP API backend for Resend / SES-style providers
  • SMTP connection pool for ultra-fast bulk sending
  • HTML validation and simple templating utilities
  • Type-checked with py.typed

Install

pip install micromailer

Quick start

import asyncio
from micromailer import AsyncSMTPMailer


async def main() -> None:
    mailer = AsyncSMTPMailer(
        host="smtp.gmail.com",
        port=587,
        username="you@gmail.com",
        password="app-password",
        use_tls=True,
    )

    ok = await mailer.send(
        to="friend@example.com",
        subject="Hello",
        html_body="<h1>Hi</h1>",
        sender="you@gmail.com",
    )

    print("Sent!" if ok else "Failed")

    await mailer.aclose()


asyncio.run(main())

Backend swapping with protocols

from typing import List, Union
from micromailer import AsyncSMTPMailer, AsyncHTTPMailer
from micromailer.core.base import MailerBackend


def send_all(
    backend: MailerBackend,
    to: Union[str, List[str]],
    subject: str,
    html_body: str,
) -> None:
    import asyncio

    return asyncio.get_event_loop().run_until_complete(
        backend.send(to, subject, html_body)
    )


send_all(AsyncSMTPMailer("smtp.gmail.com"), "a@b.com", "Hi", "<p>ok</p>")
send_all(AsyncHTTPMailer("api-key", "https://api.resend.com"), "a@b.com", "Hi", "<p>ok</p>")

SMTP connection pool

Reuse TLS connections across hundreds of emails to cut TLS handshake overhead:

from micromailer import SMTPPool


async def bulk() -> None:
    async with SMTPPool(max_size=5, host="smtp.gmail.com", port=587, username="...", password="...") as pool:
        for contact in contacts:
            mailer = await pool.acquire()
            await mailer.send(contact["email"], "Newsletter", "<p>Hello</p>")
            await pool.release(mailer)


asyncio.run(bulk())

Utilities

from micromailer import validate_html, render_template, encode_base64

validate_html("<div><p>unclosed")  # []

template = render_template("Hello {name}", {"name": "Bazil"})  # "Hello Bazil"
b64 = encode_base64("raw bytes")  # "cmF3IGJ5dGVz"

Module layout

  • core.baseMailerBackend protocol, SMTPError, MailerResult, MailerBatch
  • core.smtpAsyncSMTPMailer
  • core.httpAsyncHTTPMailer
  • core.poolSMTPPool
  • utils.mimevalidate_html, render_template, encode_base64, decode_base64

Release files for micromailer 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for micromailer 0.1.0
File Size Uploaded
micromailer-0.1.0.tar.gz 5.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for micromailer 0.1.0
File Interpreter ABI Platform
micromailer-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 14.3 kB

Release files / micromailer-0.1.0.tar.gz

Download URL micromailer-0.1.0.tar.gz
Size 5.5 kB
Tags Source
SHA-256 checksum
How to use checksums
8d7dbb7fc83917f290021414bbae34a6c09718f484a1a920204d3c45d62d8b3b
BLAKE2b-256 checksum
How to use checksums
770a2e48b7a306fbb10a2c940822f101904aad5d2c5e013cab1d423474b03ab5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / micromailer-0.1.0-py3-none-any.whl

Download URL micromailer-0.1.0-py3-none-any.whl
Size 8.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
11404fd2dbb312b5b2ffc133665698529f00ae6e659dc3db7784f929e0ef2e5e
BLAKE2b-256 checksum
How to use checksums
39c1e780da05c04812a97183ebe5725b9feca8968dc44db4313ccde211003a89
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page