Django

Five settings send everything django.core.mail produces to a sandbox.

Before you start

  • Django 3.2 or later

1Configure the SMTP backend

The SMTP backend is Django's default, so EMAIL_BACKEND only needs setting if something else overrode it.

settings.py
# settings.py
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.mailclutch.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = 'mc_0000000000000000'
EMAIL_HOST_PASSWORD = 'pw_0000000000000000'
EMAIL_USE_TLS = True
DEFAULT_FROM_EMAIL = 'staging@example.com'

In a settings module split by environment, this belongs in the staging or development one — never in the production module.

2Send a test message

python manage.py sendtestemail anyone@example.com

Or from a shell:

from django.core.mail import send_mail

send_mail(
    'Sandbox check',
    'Hello from Django.',
    'staging@example.com',
    ['anyone@example.com'],
)

Watch it land

Open the sandbox and the message is there — rendered HTML, plain text, raw source, attachments, and the SPF, DKIM and DMARC verdicts. It updates live, so you can leave it open next to your terminal.

Nothing is ever delivered onward, whatever address you send to; claim the inbox with an account and it stays.

Awaiting your email

Send from any address; it stops here rather than going onward. The inbox keeps what it catches for 24 hours.

What usually goes wrong

  • EMAIL_USE_TLS or EMAIL_USE_SSL, never both

    EMAIL_USE_TLS is STARTTLS and goes with port 587. EMAIL_USE_SSL is implicit TLS and goes with 465. Setting both raises an error before anything is sent.

  • A console backend still wins

    EMAIL_BACKEND pointing at console or locmem prints the message instead of sending it — a common leftover in a development settings file.

  • Celery tasks

    Mail sent from a task leaves when a worker picks it up. Run the worker, or set CELERY_TASK_ALWAYS_EAGER = True in staging.

Official documentationDjango — Sending email (opens in a new tab)