Send

Django Email and SMTP Setup

Configure Django transactional email with SMTP relay, TLS, queues, domain authentication, and delivery webhooks.

Updated

TL;DR

Configure Django's SMTP email backend with port 587 and TLS for existing apps. For higher-control product email, put Postscale REST sends behind a service and update final delivery state from webhooks.

What you will learn

  • Configure Django SMTP settings
  • Decide when a REST email API is better than SMTP
  • Track bounces and complaints safely

SMTP settings

Configure Django from environment variables:

EMAIL_BACKEND = "django.core.mail.backends.smtp.EmailBackend"
EMAIL_HOST = "smtp.postscale.io"
EMAIL_PORT = 587
EMAIL_USE_TLS = True
EMAIL_HOST_USER = os.environ["POSTSCALE_SMTP_USERNAME"]
EMAIL_HOST_PASSWORD = os.environ["POSTSCALE_SMTP_PASSWORD"]
DEFAULT_FROM_EMAIL = "Acme <alerts@example.com>"

Use port 587 with STARTTLS. Use port 465 only if you intentionally configure implicit TLS with the right backend behavior.

Sending example

from django.core.mail import send_mail

send_mail(
    subject="Welcome",
    message="Hello from Acme",
    from_email="Acme <alerts@example.com>",
    recipient_list=["user@example.com"],
    html_message="<p>Hello from Acme</p>",
)

For production, send from a background job and store an application message record before dispatch.

When to use the REST API

Use the REST API when you need:

  1. Structured metadata.
  2. Template IDs.
  3. Idempotency keys.
  4. A clean provider adapter.
  5. Easier integration tests.

Keep API calls in one service module instead of scattering provider calls across views and signals.

Delivery state

Django's send_mail() returning successfully does not mean a recipient mailbox accepted the message. Store message state and update it from delivery webhooks:

  1. accepted
  2. delivered
  3. deferred
  4. bounced
  5. complained

Suppress hard bounces and complaints before future sends.

References

Frequently asked questions

Can Django use SMTP relay for transactional email?
Yes. Django's SMTP email backend can send through smtp.postscale.io on port 587 with TLS and SMTP credentials.
Should email sends happen inside HTTP requests?
Avoid it for production. Enqueue mail so retries and provider latency do not slow user requests.

Related guides

Put the guide into production

Postscale brings sending, inbound processing, DMARC reporting, and masked addresses behind one API so the operational pieces stay connected.