Table of contents
This document will guide you through the installation process and initial setup of the django-nitro-mailer .
Requirements
Before you begin, make sure your environment meets the following requirements:
- Python >= 3.10, < 3.15 (Django 6.0+ requires Python 3.12+)
- Django >= 5.2, < 7.0
Installing the Package
Install the package using pip:
$ pip install django-nitro-mailer
Usage
- Add
django_nitro_mailerto yourINSTALLED_APPSin yoursettings.py:
INSTALLED_APPS = [
...
"django_nitro_mailer",
...
]
-
Run
python manage.py migrateto create the necessary tables. -
Change the
EMAIL_BACKENDsetting in yoursettings.pyto use the desired backend:
Database Backend: Store emails in the database and send them asynchronously. Requires sending a cron job or some other scheduled task to send the emails.
EMAIL_BACKEND = "django_nitro_mailer.backends.DatabaseBackend"
Sync Backend: Send emails synchronously. Does not provide the reliability that the database backend provides, but still provides the logging and throttling features.
EMAIL_BACKEND = "django_nitro_mailer.backends.SyncBackend"
Django 6.1+ MAILERS (since 0.3.1)
When migrating SMTP credentials to Django's MAILERS setting, configure Nitro as the default mailer and select a separate delivery alias with NITRO_EMAIL_MAILER:
import os
MAILERS = {
"default": {
"BACKEND": "django_nitro_mailer.backends.DatabaseBackend",
# For synchronous delivery, use django_nitro_mailer.backends.SyncBackend.
},
"smtp": {
"BACKEND": "django.core.mail.backends.smtp.EmailBackend",
"OPTIONS": {
"host": "smtp.example.com",
"port": 587,
"username": os.environ["SMTP_USERNAME"],
"password": os.environ["SMTP_PASSWORD"],
"use_tls": True,
},
},
}
NITRO_EMAIL_MAILER = "smtp"
Keep SMTP options and credentials on the delivery alias, not on the Nitro backend. The Nitro backends themselves take no OPTIONS. The delivery alias must not point to either Nitro backend: doing so would send messages back into Nitro instead of delivering them.
The same delivery alias is used by SyncBackend, the database queue, retries, and admin actions. For DatabaseBackend, schedule the queue command, for example in cron:
python manage.py nitro_send_emails
Defining MAILERS does not run the queue automatically. The command and the application must load the same Django settings.
NITRO_EMAIL_MAILER takes precedence over NITRO_EMAIL_BACKEND. Existing EMAIL_* configuration remains supported on older Django versions. An explicitly configured custom NITRO_EMAIL_BACKEND also remains supported alongside MAILERS, but it is responsible for its own configuration; it does not automatically receive another alias's OPTIONS. For SMTP credentials configured through MAILERS, use NITRO_EMAIL_MAILER as shown above.
See Settings for alias requirements and configuration errors.