<meta name="clckd" content="6301244fb7ed470eb1cd6b8c31d01ac4" />

How To Send Emails In Django: A Step-By-Step Guide

Django is a popular web framework for building web applications in Python. One of the common tasks when building web applications is sending emails. In this blog post, we will learn how to send emails in Django.

First, we need to configure the email settings in the settings.py file. We can use the built-in EmailBackend or use an external service like Gmail or Amazon SES. Here's an example of how to configure the email settings using the built-in EmailBackend:

EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = 'your_email@gmail.com'
EMAIL_HOST_PASSWORD = 'your_password'

Once the email settings are configured, we can use the built-in send_mail function to send emails. Here's an example of how to use the send_mail function:

from django.core.mail import send_mail

    'Here is the message.',

The send_mail function takes five arguments:

Subject: The subject of the email.
Message: The message of the email.
From email: The email address of the sender.
List of recipient emails: A list of email addresses of the recipients.
fail_silently: A boolean value that indicates whether to raise an exception if the email fails to send.
You can also use the EmailMessage class to create more advanced emails with multiple recipients, cc, bcc, attachments and headers.

from django.core.mail import EmailMessage

email = EmailMessage(
    'Body goes here',
    ['first@example.com', 'second@example.com'],
    headers={'Message-ID': 'foo'},


That's it! With these simple steps, you can send emails in Django. You can also use other libraries like Celery to handle sending emails asynchronously.

Thank You
Shivam Rohilla | Python Developer

  • No Reviews Yet

Leave a Reply
Please Sign In For Comment.
Login or Signup
Shivam Rohilla
Hi, I'm Shivam Rohilla

Hi! My name is Shivam Rohilla. I am a Full Stack Web Developer, and I'm very passionate and dedicated to my work. With 2 years experience as a professional Full Stack Web Developer.

Follow Me:-

My social media links