Send email using Django and Gmail SMTP

Hello, in this tutorial we will discuss about a very important feature of Django. Yes, in this post we will show you how to Send email using Django and Gmail’s SMTP server.

How to send email using Django

To send email using Django is very easy. You can send email using a few lines of code. Here is a simple example:

You must replace sender_email@example.com with the email address of your account and  recipient_email@example.com with the recipient’s email address.

Send email using Django and Gmail SMTP

Send email using Django and Gmail SMTP

Configuring Django for Gmail’s SMTP server

To send email using Django and Gmail SMTP you must have a Gmail account. Your Gmail account’s Username and Password will be needed for sending emails.

If you have that then you can configure Django for your Gmail account by adding the following lines in your Django project’s  settings.py file:

Here, EMAIL_HOST_USER will be your Gmail account’s Username and EMAIL_HOST_PASSWORD will be your Gmail account’s Password.

Thats all. And now you can Send email with Django. Run the following function through your configured Django project:

If you have configured your Django project properly and entered valid email address for your recipient then your email will be delivered successfully.