Setup gmail for sending emails in django (Easy way)
In this article I will be teaching you how to setup your gmail account and use it for sending emails in django
1. Enable 2 factor authentication
- In order to proceed, you need to enable 2fa (aka 2 factor authentication) in your gmail account. In case you are finding difficulties in doing this you can refer the following article by clicking here.
2. Creating app password
- For this step select “ Manage your google account option”.
- Now you will be shown something like this:
- Now as shown in the image above, click on the security option.
- In security tab under Signing in to Google you will find something called App passwords, click on that
- It would ask for verification, after completing that you will be shown the following:
- Now click on the select app dropdown, click on other (custom name) and then give it a name.
- And then click on the generate button and you will be shown a popup with a 16 character password.
- Make sure you write this password somewhere because it will be displayed only once.
- And that’s it here comes the final step.
3. Setting up the gmail setting in settings.py file (django)
- Now copy paste the following in settings.py django
EMAIL_BACKEND = ‘django.core.mail.backends.smtp.EmailBackend’
EMAIL_HOST = ‘smtp.gmail.com’
EMAIL_USE_TLS = True
EMAIL_PORT = 587
EMAIL_HOST_USER = ‘your_account@gmail.com’
EMAIL_HOST_PASSWORD = ‘The app password that you have taken down’
- Now try to send email using django and it would work perfectly fine, if you don’t know how to send emails using django, you can refer the following article
- https://www.geeksforgeeks.org/setup-sending-email-in-django-project/