Setup Django Application Form to send emails to your Gmail Inbox
Sayem Hoque
Posted on September 16, 2024
For September 2024 none of the guides I found online were up to date and comprehensive for this so just writing the steps to make it work here:
- https://myaccount.google.com/
- Under "Recent Security Activity" make sure 2FA is on
- Go to the search bar above, and search "App Passwords"
You'll be prompted as such - "To create a new app specific password, type a name for it below..."
- Name it something like "my-django-site-form"
It will generate a password you can use in your application. Store this securely somewhere. This can be used in your Django settings, but I opt for saving as an .env variable.
To test to make sure this setup is working, you can run the following code in the Django shell:
python manage.py shell
from django.core.mail import send_mail
send_mail(
'Test Email',
'This is a test email.',
'sender@email.com',
['recipient@example.com'],
fail_silently=False,
)
Replace the two emails, and you should see an email sent to recipient@example.com
💖 💪 🙅 🚩
Sayem Hoque
Posted on September 16, 2024
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.
Related
webdev Understanding HTTP, Cookies, Email Protocols, and DNS: A Guide to Key Internet Technologies
November 30, 2024