Overview
Django-allauth sends various emails for account verification, password reset, and security notifications. This guide covers how to customize these emails, from simple template changes to advanced sending logic.Email Types
Django-allauth sends the following emails:Basic Template Customization
Django-allauth looks for email templates in your project’s template directory.Directory Structure
Create this structure in your templates directory:Template Files
Each email requires two or three files:*_subject.txt- Email subject line (single line, no HTML)*_message.txt- Plain text body*_message.html- HTML body (optional but recommended)
If you provide an HTML template, both plain text and HTML versions will be sent as a multipart email.
Email Confirmation Template
Customize the signup confirmation email:templates/account/email/email_confirmation_signup_subject.txt
templates/account/email/email_confirmation_signup_message.txt
templates/account/email/email_confirmation_signup_message.html
Password Reset Template
Customize the password reset email:templates/account/email/password_reset_key_subject.txt
templates/account/email/password_reset_key_message.txt
templates/account/email/password_reset_key_message.html
Available Template Context
Each email template receives specific context variables:Email Confirmation
Password Reset
Email Subject Configuration
Customize the subject prefix globally:settings.py
Custom Email Sending Logic
Override the adapter’ssend_mail method for complete control:
adapters.py
settings.py
Using External Email Services
SendGrid
adapters.py
Mailgun
adapters.py
Email Rendering
Customize how email messages are rendered:adapters.py
Email Notifications
Enable security notification emails:settings.py
- Password changes
- Email address changes
- Security-related account modifications
templates/account/email/password_changed_subject.txt
templates/account/email/password_changed_message.html
Testing Emails
During development, capture emails instead of sending:Console Backend
settings.py
File Backend
settings.py
MailHog / MailCatcher
settings.py
Unknown Account Emails
Control whether emails are sent for non-existent accounts:settings.py
templates/account/email/unknown_account_message.txt
Adding Attachments
adapters.py
Email Styling Best Practices
- Inline CSS: Many email clients strip
<style>tags, so use inline styles:
- Tables for Layout: Use tables instead of divs for better compatibility:
- Test Across Clients: Use services like Litmus or Email on Acid to test rendering
- Keep it Simple: Complex layouts may break in some email clients
Configuration Reference
ACCOUNT_EMAIL_SUBJECT_PREFIX
Default:"[Site] "
Prefix added to all email subjects.
ACCOUNT_EMAIL_NOTIFICATIONS
Default:False
Enable security notification emails for password changes, etc.
ACCOUNT_EMAIL_UNKNOWN_ACCOUNTS
Default:True
Send password reset emails even when account doesn’t exist (prevents enumeration).
Complete Example
settings.py
