Python Shikhi. Learn with Fun


image

How to use the Google SMTP server to send emails for free using Python Django


Sending emails is a fundamental feature in many web applications, whether for user registration, password resets, or notifications. If you're developing a web application with Django, integrating email functionality can significantly enhance your user's experience. In this guide, we will explore how to send emails using Python and Django through the Google SMTP server for free. By leveraging Google's reliable and robust email service, you can ensure your emails are delivered promptly and securely, all without incurring additional costs. This step-by-step tutorial will walk you through the necessary configurations and code implementations to get your email functionality up and running in no time.

Configure django for Gmail SMTP server.

Step-1. To set Gmail SMTP Server, first of all below code should be pasted in settings.py.

# Email Verification Settings
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_USE_TLS = True
EMAIL_HOST_USER = 'pythonshikhi@gmail.com'
EMAIL_HOST_PASSWORD = 'azia tclk bbqg tkpm'

 

In above code, EMAIL_BACKEND, EMAIL_HOST, EMAIL_PORT, EMAIL_USE_TLS, not need to be changed. We need to change EMAIL_HOST_USER & EMAIL_HOST_PASSWORD. EMAIL_HOST_USER will be that email, from where email will be sent to user. And EMAIL_HOST_PASSWORD need to make by using HOST email. Below is the several steps to make EMAIL_HOST_PASSWORD.

 

Step:2 - First we need to login HOST email and click on Account.

 

 

 

Step:3- This page will open after clicking on Account.

 

 

 

Step:4- Click on Security to open below page.

 

 

 

 

Step:5- Click on 2-Step Verfication under How you sign in to Google section.

 

 

 

Step:6 - Click on arrow under App passwords section. To create App Password, please put a name and press on Create.

 

 

Step:7- After that you will see a password. This password is EMAIL_HOST_PASSWORD.

 

 

Now settings is ok and we can send email from django by using send_mail function.