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.base—MailerBackendprotocol,SMTPError,MailerResult,MailerBatchcore.smtp—AsyncSMTPMailercore.http—AsyncHTTPMailercore.pool—SMTPPoolutils.mime—validate_html,render_template,encode_base64,decode_base64
Release files for micromailer 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| micromailer-0.1.1.tar.gz | 5.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| micromailer-0.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 14.3 kB
Release files / micromailer-0.1.1.tar.gz
| Download URL | micromailer-0.1.1.tar.gz |
|---|---|
| Size | 5.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b66fcda24697f4ce069d28996f715f0f988cfc58028d15ecf769cb4c083c43ca
|
|
BLAKE2b-256 checksum How to use checksums |
2b227c91b0b66a577081209fe573faaef43d3c7c37f1d1e2fced975d39f51642
|
| 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.1-py3-none-any.whl
| Download URL | micromailer-0.1.1-py3-none-any.whl |
|---|---|
| Size | 8.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1f658058ee03fc5e1ddfcc1019f4ac92304c979536585fe936872a72482afb48
|
|
BLAKE2b-256 checksum How to use checksums |
19443def2e9e169031c8c110eb97255a0e4e2232f3fb08b086e1e7b5796153bb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|