An Interest In:
Web News this Week
- April 25, 2024
- April 24, 2024
- April 23, 2024
- April 22, 2024
- April 21, 2024
- April 20, 2024
- April 19, 2024
Send emails with Django and Gmail in production , the right way
In this post I want to talk about how can we send emails using Django and Gmail, I read a lot of articles about this but none of them is working for me, this is my way of doing this
Setup Django
first let's install django
pip install django
start a django project
django-admin startproject send_gmail
start a django app
cd send_gmailpython manage.py startapp send
add the app to settings.py installed app
# send_gmail/settings.pyINSTALLED_APPS = [...send,]
migrate and create a super user
python manage.py migratepython manage.py createsuperuser
check this post if you want to know more about how to create a virtual environment , or how to install Django and start your project
The Gmail part
now you need to create a Gmail account and then click on Manage your google account
now click on the Security tab
make sure to enable two steps verification
now click on App passwords
you have to type your password again
click on select app choose *** other (Custome Name) *** and give a name to you app
the last step click on generate and Gmail will generate a key or an app password make sure to copy this key or save it in a text file
Edit your settings.py file
#gmail_send/settings.pyEMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'EMAIL_HOST = 'smtp.gmail.com'EMAIL_HOST_USER = '[email protected]'EMAIL_HOST_PASSWORD = 'key' #past the key or password app hereEMAIL_PORT = 587EMAIL_USE_TLS = TrueDEFAULT_FROM_EMAIL = 'default from email'
now you are ready to send emails with Django and Gmail in production
For further exploration
for large apps don't use Gmail you can use SendGrid, Mailgun, Sendinblue...
Original Link: https://dev.to/abderrahmanemustapha/how-to-send-email-with-django-and-gmail-in-production-the-right-way-24ab
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To