email-sender
Reusable email sender for Python applications using Jinja2 HTML templates.
Works with FastAPI, Flask, Django, or any plain Python project.
Features
- Send emails with HTML templates using Jinja2.
- Async and sync sending.
- FastAPI BackgroundTasks helper.
- Support for CC, BCC, and attachments.
- Configurable via environment variables or explicit settings.
Installation
pip install email-sender
For FastAPI integration:
pip install email-sender[fastapi]
Configuration
Set the following environment variables:
MAIL_USERNAME=your_email@example.com
MAIL_PASSWORD=your_password_or_app_password
MAIL_SERVER=smtp.gmail.com
MAIL_PORT=587
MAIL_FROM_ADDRESS=your_email@example.com
MAIL_STARTTLS=True
MAIL_SSL_TLS=False
Or create an EmailSettings instance manually:
from email_sender import EmailSettings
settings = EmailSettings(
username="your_email@example.com",
password="your_password",
server="smtp.gmail.com",
port=587,
from_address="your_email@example.com",
)
Usage
FastAPI with BackgroundTasks (recommended)
from fastapi import FastAPI, BackgroundTasks
from email_sender import send_email_background
app = FastAPI()
@app.post("/register")
async def register(background_tasks: BackgroundTasks, email: str, name: str):
send_email_background(
background_tasks,
to=[email],
subject="Welcome",
template_name="welcome.html",
context={"name": name, "app_name": "MyApp"},
)
return {"message": "User registered"}
Async usage
from email_sender import send_email
await send_email(
to=["user@example.com"],
subject="Verify your email",
template_name="verify_email.html",
context={"name": "John", "verification_url": "https://example.com/verify?token=abc"},
)
Sync usage (outside event loop)
from email_sender import send_email_sync
send_email_sync(
to=["user@example.com"],
subject="Welcome",
template_name="welcome.html",
context={"name": "John", "app_name": "MyApp"},
)
Custom templates
You can point to your own templates folder:
settings = EmailSettings(
template_dir="/path/to/your/templates",
# ... other config
)
await send_email(
to=["user@example.com"],
subject="Hello",
template_name="custom.html",
context={"name": "John"},
settings=settings,
)
Your custom templates should extend base.html or be standalone HTML files.
Included templates
welcome.htmlverify_email.htmlotp.htmlpassword_changed.html
Development
git clone https://github.com/yourusername/email-sender.git
cd email-sender
python -m venv venv
source venv/bin/activate
pip install -e ".[dev]"
Running tests
pytest
License
MIT
Metadata
Release files for async-email-sender 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| async_email_sender-0.1.0.tar.gz | 8.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| async_email_sender-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 19.6 kB
Release files / async_email_sender-0.1.0.tar.gz
| Download URL | async_email_sender-0.1.0.tar.gz |
|---|---|
| Size | 8.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0ee33a3907572820c601e1617962ed884d8cb8800dd3fabe195ccb31907c076e
|
|
BLAKE2b-256 checksum How to use checksums |
1811844b8c8ae78b6a928488724ced590d5b993386fffd1132d6725cc8b54bfe
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 9, 2026.
Transparency logRelease files / async_email_sender-0.1.0-py3-none-any.whl
| Download URL | async_email_sender-0.1.0-py3-none-any.whl |
|---|---|
| Size | 10.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6459275ef7541010ef1d8fd85f35da6bfd2e69398e71e09b90ffc612d10f754e
|
|
BLAKE2b-256 checksum How to use checksums |
fb00288a9795cab927f0ba7e160e20c6ac891111f0f04116df3cc35fbf735eee
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 9, 2026.
Transparency log