django-simple-mailer
A simple Django app for sending template-driven emails.
Features
- Send HTML + plain-text emails using Django templates
- Optional email logging — persist every send attempt to a
MailLogtable, viewable in Django admin (disabled by default, enable withSIMPLE_MAILER_LOG_EMAILS = True) - Clean
MailerErrorexception for straightforward error handling
Installation
pip install django-simple-mailer
Add to INSTALLED_APPS:
INSTALLED_APPS = [
...
"django_simple_mailer",
]
Configure Django's email settings (standard Django — nothing library-specific):
DEFAULT_FROM_EMAIL = "no-reply@example.com"
EMAIL_BACKEND = "django.core.mail.backends.smtp.EmailBackend"
EMAIL_HOST = "smtp.example.com"
EMAIL_HOST_USER = "..."
EMAIL_HOST_PASSWORD = "..."
EMAIL_PORT = 587
EMAIL_USE_TLS = True
Ensure your TEMPLATES setting has APP_DIRS enabled — this is how the mailer finds your email templates. Django's default setup already includes it:
TEMPLATES = [
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"APP_DIRS": True,
...
}
]
With APP_DIRS = True, place your email templates inside any app's templates/ directory and Email() will resolve them automatically.
If your project uses a custom loaders list instead of APP_DIRS, make sure django.template.loaders.app_directories.Loader is included.
For more info on templates see Template Convention below.
No migrate step is needed unless you enable email logging (see Email Logging below).
Usage
For each email, create three template files inside any app's templates/ directory.
Templates can sit anywhere within the templates/ directory:
your_app/
templates/
emails/
welcome_email.subject ← subject line (single line, no newlines)
welcome_email.txt ← plain-text body
welcome_email.html ← HTML body
Then send the email:
from django_simple_mailer import Email
Email(
template="emails/welcome_email", # path relative to `templates/`
context={"name": "Jane", "link": "https://app.example.com"},
recipients=["jane@example.com"],
).send()
Email() resolves templates using Django's template engine. APP_DIRS = True is the standard setup but any configured template discoverable by Django should work.
Error Handling
send() raises MailerError on delivery failure, you can get the original exception from __cause__:
from django_simple_mailer import Email, MailerError
try:
Email(template="welcome_email", context={...}, recipients=[...]).send()
except MailerError as exc:
# The underlying SMTP/backend exception is available as exc.__cause__
logger.error("Email delivery failed: %s", exc.__cause__)
Email Logging
Disabled by default. Enable with
SIMPLE_MAILER_LOG_EMAILS = True. requires having a database configured and 'django.contrib.admin' installed.
When enabled, every send() call — success or failure — writes a MailLog record to the database. Logs are viewable and searchable from Django admin.
Setup:
# settings.py
SIMPLE_MAILER_LOG_EMAILS = True # default: False
Then run migrations to create the MailLog table:
python manage.py migrate
What gets logged:
| Field | Description |
|---|---|
sent |
True on success, False on error |
error |
Exception message if delivery failed |
sender |
DEFAULT_FROM_EMAIL at send time |
recipients |
List of recipient addresses |
subject |
Rendered subject line |
txt_message |
Rendered plain-text body |
html_message |
Rendered HTML body |
Without a database:
When SIMPLE_MAILER_LOG_EMAILS = False (the default), the library has zero database interaction and works in Django projects without a configured database.
Settings Reference
| Setting | Default | Description |
|---|---|---|
SIMPLE_MAILER_LOG_EMAILS |
False |
Persist send attempts to MailLog. Requires a database and migrate. |
Template Convention
Each email requires exactly three files with the same name and path relative to any app's templates/ directory:
| File | Content |
|---|---|
<name>.subject |
Subject line — rendered as a single line, newlines stripped |
<name>.txt |
Plain-text email body |
<name>.html |
HTML email body |
When using Email(), the template argument must match the path relative to templates/.
Subdirectories are supported — template="emails/welcome/welcome_email" resolves to templates/emails/welcome/welcome_email.{subject,txt,html}.
All three files are rendered with the same context dict passed to Email().
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django_simple_mailer-1.0.0.tar.gz.
File metadata
- Download URL: django_simple_mailer-1.0.0.tar.gz
- Upload date:
- Size: 5.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
uv/0.12.9 {"installer":{"name":"uv","version":"0.12.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b59062a34c0bc5205991ad2852f38bf38a3a5d54a1ba1e17c2e47263de6ae33b
|
|
| MD5 |
fcf55e36c019234fbdd96861a5b3773c
|
|
| BLAKE2b-256 |
606876c4671f4c3153f4e8aeb0c68c3b3978ba87f094bf34cb7dab95bde50837
|
File details
Details for the file django_simple_mailer-1.0.0-py3-none-any.whl.
File metadata
- Download URL: django_simple_mailer-1.0.0-py3-none-any.whl
- Upload date:
- Size: 9.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
uv/0.12.9 {"installer":{"name":"uv","version":"0.12.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
49b801e7d2ad392d311c80d289ff473aa27d102af26bf7d9fba6fd4f624e573c
|
|
| MD5 |
314295fb4e000675e996b862290e08bc
|
|
| BLAKE2b-256 |
de0b595d84a3a2f34615bd7c9aa972d708fce8d97f6dabe13cba80ecfacbc5bc
|