Django 3 Send Emails To Gmail Account Using Send_Email Library Full Project For Beginners

You are currently viewing Django 3 Send Emails To Gmail Account Using Send_Email Library Full Project For Beginners

Welcome folks today in this post we will be talking about how to send test emails inside your django 3 application. We will be using gmail as our example server. You can take any server for your choice. All the steps are explained in depth and also a youtube video is given below to better understand the blog.



Installing Django



Creating Project


Go to the directory where you need to create the project and then initialize this command to create a new project



Creating Sample App



Registering Your App inside Project



Now go to the of the project and write these lines of code there



Here you need to replace sendapp with your app name. Basically in this line of code we are telling the django project that whenever django opens the home path then it should be redirected to a file which we will create inside our app folder.

Now inside your Django App folder create a new file and write this code inside it.


Here in this block of code we are configuring our urls. So the home path url will handle by a file which is there inside our django app folder.

Now open your folder and copy paste the below code.


So Inside this code we are telling django when the request comes to the home path then return this template file which will be located inside send folder and there will be file index.html

So now inside your django app directory create a new templates directory and inside it create send directory and inside it create a index.html file and write the following code to it.



So inside this file we are just writing a basic html document and inside it we have a simple heading telling the user that the email was successfully sent.

Now we need to open the file of our project and write the basic settings which will be required by django to send the email to gmail such as the email address and password of the sender and also the port number etc. So open that file and copy paste the following code.



Enable Less Secure Apps in Gmail



Now after configuring all these details inside the of your project.

Now again open your file and in that file update the code and paste the following code.


Here in this block of code just before we are returning the index.html we are sending the email with the help of django send_mail function we are importing it at the very top from the core library of django and then we are using the send_mail function which takes the subject,body of message, and also email address of sender, and the recipient email address in an array. So you can define multiple email addresses to send multiple emails to multiple people at one time. And the last boolean parameter fail_silently is set to false.

Now the application is complete. Now head over to the cmd and execute the following command to start the django server


After executing this command this will start your django server at port 8000 like below




Leave a Reply