How to send email with Django: Complete SMTP guide

Published: (December 11, 2025 at 03:00 PM EST)
3 min read
Source: Dev.to

Source: Dev.to

Understanding Django’s email system

Django provides a robust email‑sending framework through its django.core.mail module. This module includes functions and classes for sending basic, HTML, and mass emails.

The module requires a backend to function properly, so you’ll need to configure the email backend you want to use for your project.

Django email system overview

Django supports many out‑of‑the‑box email backends. The SMTP Backend is the most popular and works well for most applications.

In addition to the default backends, you can build a custom email backend, but this guide focuses on the built‑in SMTP Email Backend.

How to send email with Django

Prerequisites

  • Django installed in your project (the guide uses Django 5.0 but works with Django 3.x and above)
  • Basic knowledge of Django and Python
  • A working Django project
    (see the official Django installation guide if you need to create one)
  • An email service provider (the examples use SendLayer, but any SMTP provider will work)

If you choose SendLayer, you can start with a free account that allows up to 200 emails.

Start your free trial at SendLayer

After creating an account, you’ll need to authorize your sending domain, which improves deliverability and verifies your account.

Configuring your email backend

Open your project’s settings.py and add the following configuration (replace the placeholder values with your own SMTP credentials):

# Django email configuration
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.sendlayer.net'      # Replace with your SMTP server
EMAIL_PORT = 587
EMAIL_USE_TLS = True
EMAIL_HOST_USER = 'your-sendlayer-username'
EMAIL_HOST_PASSWORD = 'your-sendlayer-password'

Django email settings configuration

Retrieve your SMTP credentials from your SendLayer account (or from whichever provider you use) and replace the placeholders accordingly.

Securing your credentials

Storing usernames and passwords directly in code is insecure. Use environment variables instead.

  1. Create a .env file in the project root:

    EMAIL_HOST_USER='your-sendlayer-username'
    EMAIL_HOST_PASSWORD='your-sendlayer-password'
  2. Install python-decouple:

    pip install python-decouple
  3. Update settings.py to read the variables:

    from decouple import config
    
    EMAIL_HOST_USER = config('EMAIL_HOST_USER')
    EMAIL_HOST_PASSWORD = config('EMAIL_HOST_PASSWORD')

Method 1: Send plain email using send_mail() function

send_mail() is a built‑in shortcut for sending simple text emails.

Required parameters

  • subject: Email subject line
  • message: Plain‑text body
  • from_email: Sender address
  • recipient_list: List of recipient addresses

Optional parameters

  • fail_silently: False raises exceptions; True suppresses them
  • connection: Custom email backend (defaults to the one defined in settings)
  • html_message: HTML version of the email body

Example

from django.core.mail import send_mail

send_mail(
    subject='Welcome to Our App',
    message='Thank you for signing up!',
    from_email='paulie@example.com',
    recipient_list=['user@example.com'],
    fail_silently=False,
)

Pro Tip: When using SendLayer, the from_email should belong to the domain you have authorized (e.g., @example.com).

Sending to multiple recipients

from django.core.mail import send_mail

send_mail(
    subject='Welcome to Our App',
    message='Thank you for signing up!',
    from_email='paulie@example.com',
    recipient_list=[
        'user1@example.com',
        'user2@example.com',
        'user3@example.com',
    ],
    fail_silently=False,
)

Method 2: Send email with EmailMessage class

The EmailMessage class offers more flexibility than send_mail(), allowing you to add attachments, set custom headers, and send HTML content.

EmailMessage vs send_mail function

Back to Blog

Related posts

Read more »

Django: what’s new in 6.0

2025-12-03 !https://adamj.eu/tech/assets/2025-12-03-django-mosaic.webp Django 6.0 was released todayhttps://www.djangoproject.com/weblog/2025/dec/03/django-60-r...