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 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.comOr 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_TLSis STARTTLS and goes with port 587.EMAIL_USE_SSLis implicit TLS and goes with 465. Setting both raises an error before anything is sent.A console backend still wins
EMAIL_BACKENDpointing atconsoleorlocmemprints 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 = Truein staging.
Other stacks
The same four values in another dialect. Every guide below is filled in with the sandbox pair at the top of this page.
Frameworks and languages
- LaravelFive .env variables, no package
- SymfonyOne MAILER_DSN
- RailsAction Mailer smtp_settings
- Node.jsA Nodemailer transport
- Next.jsRoute Handler or Server Action
- Gonet/smtp, standard library
- SpringFive Spring Boot properties
- JavaJakarta Mail, no framework
- .NETMailKit: connect, auth, send
- PHPPHPMailer, no framework
- Pythonsmtplib, standard library
- Rustlettre over a STARTTLS relay