Send Emails with Django
How to send out emails with Django using Gmail.
Setup a Gmail "App Password"
- Enable 2-factor authentication. This is required in order to use less secure apps.
- Navigate to myaccount.google.com/security and scroll down to the "Signing Into Google" section. Click on "App Passwords."
- You'll be asked to enter your personal Gmail account password. Next, click on "Select App" and input a name for your Django app. Generate an 'App Password'.
- Copy the generated app password for later usage
Add a few lines on Django settings.py
# Gmail Example
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = 'your_username@gmail.com'
EMAIL_HOST_PASSWORD = 'generated_app_password_from_above'
EMAIL_PORT = 587
EMAIL_USE_TLS = True
EMAIL_USE_SSL = False
It's recommended that we don't put secret information such as email password on settings.py. Please refer to How to Use Python Decouple Library for Django Application for more.
Share this post
Related Posts
UV
UV unified Python package manager: Rust-based replacement for pip, venv, pip-tools, developed by Astral (Ruff).
Precedence of Logical Operators
Logical operator precedence: NOT (highest), AND (medium), OR (lowest) with Python code examples showing order.
Offline Python Packages Installation
Offline Python package installation: download dependencies with pip, transfer and install without internet.
4 Ways of Serving Static Files in Django
Four Django static file serving methods: dev server, Whitenoise, Nginx, and Amazon S3 cloud storage comparison.