Menu Close

How to Send Email with Django Framework | How to Send Email in Django | Django Email Project – DevDuniya

How to Send Email with Django Framework How to Send Email in Django Django Email Project - DevDuniya
Rate this post

In this article, we are going to see How to Send Email in Django. Sending an email is quite simple in Django and so, We are going to create such kind of Django Project.
You will have to do the first complete setup for this project then follow the steps given below. To follow along with this tutorial, you need a Gmail account, prior knowledge of Django is required, and Basic HTML. If you don’t have a Gmail account then follow this link to create a new Gmail account or google account.

Before starting the project, Download python programming from their official website and install it in your system. Once python is installed then you can simply check its version by command prompt. Enter the below command in CMD.

python --version

After downloading the python programming, Now install Django with the help of Command Prompt. Enter the command given below:-

pip install django
python -m django --version


Now we will first create a project then we will create an app for that project. Do follow the below steps :

django-admin startproject mailproject
cd mailproject
python startapp mailapp
python migrate
python runserver

After these steps, Now your Django server has been started.

Now you can navigate to using your browser to see the default Django homepage.


Add your app in the file.

# Application definition


    #add app


Now in the same file, below all code add some SMTP configuration code.

EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST_USER = ""  #add here your actual mail id
EMAIL_HOST_PASSWORD = "" #password of your mail id that you have added above

Step:-4 Now add some code into your file of mailapp folder. So that it will look like this:

from django.shortcuts import render
from django.core.mail import send_mail
# Create your views here.
def mailfunction(request):
	    'Title of mail',
	return render(request, 'index.html')


Now make a folder in mailapp with ‘templates’ name, then create a file name index.html. Past the below code in index.html.

<!DOCTYPE html>
<html lang="en">
  <title>Bootstrap Example</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="">
  <script src=""></script>
  <script src=""></script>

<div class="container">
  <div class="alert alert-success">
    <strong>Success!</strong> Email Sent!!!!



Update your file of mailproject folder.

from django.contrib import admin
from django.urls import path, include

urlpatterns = [
    path('', include('emailapp.urls')),


Create a new file in mailapp folder with the file name. Remember one thing, this file is in mailapp folder not in mailproject folder. Now add some code into the file.

from django.urls import path
from . import views

urlpatterns = [
    path('', views.mailfunction, name="mailfunction"),

Now Run the Django Server:-


So we have successfully created a simple Django Project. We have covered how to send an email in the django framework.

If you have any queries related to this article, then you can ask in the comment section, we will contact you soon, and Thank you for reading this article.

Follow me to receive more useful content:

Instagram | Twitter | Linkedin | Youtube

Thank you

Suggested Blog Posts


Leave a Reply

Your email address will not be published.