-
Notifications
You must be signed in to change notification settings - Fork 58
Async support #210
Description
Async support
python-emails currently blocks on all network I/O — SMTP sending, HTTP resource loading, DNS lookups. This makes it awkward to use in async applications (FastAPI, Starlette, aiohttp, etc.) without wrapping calls in run_in_executor.
Proposal
Add native async support as an optional feature: pip install emails[async]
Phase 1 — async sending:
await message.send_async(...) sends email without blocking the event loop. This covers the primary use case — non-blocking email delivery, especially for bulk sending and async web frameworks.
Phase 2 — async resource loading:
Async versions of HTML/image/stylesheet loading from URLs. Enables parallel fetching of multiple resources via asyncio.gather().
Phase 3 — convenience:
Async connection pooling, batch sending helpers with concurrency control, documentation with framework integration examples.
Principles
- Sync API remains the default and is not affected
- Async is opt-in via the
asyncextra - Async code lives in separate modules and classes (
AsyncSMTPBackend,AsyncSMTPClient,send_async(),fetch_url_async(), etc.) — no mixing of sync and async logic in the same functions - Shared code (MIME building, templates, DKIM) is reused, not duplicated
- New async dependencies (
aiosmtplib,httpx) are optional