Advanced Email System
Django-CFG’s Email Module provides enterprise-grade email functionality with template support, delivery tracking, multi-provider integration, and production-ready features.
Philosophy
”Template-First Design”
Rich HTML/text email templates with dynamic context:
from django_cfg.modules.django_email import send_template_email
# Send templated email
send_template_email(
template='welcome_email.html',
context={'user_name': 'John', 'activation_link': 'https://...'},
to=['[email protected]'],
subject='Welcome to our platform!'
)“Multi-Provider Support”
Seamlessly switch between email providers:
- ✅ SMTP - Traditional SMTP servers
- ✅ SendGrid - Transactional email service
- ✅ Mailgun - Email automation platform
- ✅ Amazon SES - AWS email service
- ✅ Testing Backend - Development and testing
”Production-Ready Features”
Built for enterprise applications:
- ✅ Delivery Tracking - Email status and analytics
- ✅ Bulk Operations - Efficient mass email sending
- ✅ Error Handling - Robust retry mechanisms
- ✅ Template Engine - Django template integration
- ✅ Attachment Support - File and inline attachments
- ✅ Email Validation - Address validation and sanitization
Quick Start
Basic Email Sending
from django_cfg.modules.django_email import send_email
# Simple email
send_email(
subject='Hello World',
message='This is a test email.',
from_email='[email protected]',
recipient_list=['[email protected]']
)Template-Based Emails
from django_cfg.modules.django_email import send_template_email
# HTML template email
send_template_email(
template='emails/notification.html',
context={
'user_name': 'John Doe',
'notification_text': 'Your order has been shipped!',
'action_url': 'https://example.com/track/123'
},
to=['[email protected]'],
subject='Order Shipped'
)Bulk Email Operations
from django_cfg.modules.django_email import send_bulk_email
# Send to multiple recipients
recipients = [
{'email': '[email protected]', 'name': 'User 1'},
{'email': '[email protected]', 'name': 'User 2'},
]
send_bulk_email(
template='newsletter.html',
recipients=recipients,
subject='Monthly Newsletter',
context={'month': 'December', 'year': 2024}
)Architecture
Template System
- Django Templates - Full Django template engine support
- HTML/Text Alternatives - Automatic plain text generation
- Context Variables - Dynamic content insertion
- Template Inheritance - Reusable email layouts
Provider Integration
- Unified Interface - Same API for all providers
- Auto-Configuration - Provider detection and setup
- Failover Support - Automatic provider switching
- Rate Limiting - Respect provider limits
Tracking & Analytics
- Delivery Status - Track email delivery
- Open Tracking - Monitor email opens
- Click Tracking - Track link clicks
- Bounce Handling - Manage bounced emails
Configuration
# settings.py - Standard Django email settings
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.example.com'
EMAIL_PORT = 587
EMAIL_USE_TLS = True
EMAIL_HOST_USER = '[email protected]'
EMAIL_HOST_PASSWORD = 'your-password'
# Django-CFG email enhancements
DEFAULT_FROM_EMAIL = '[email protected]'
EMAIL_TEMPLATE_DIR = 'emails'
EMAIL_TRACKING_ENABLED = TrueUse Cases
User Authentication
# Send welcome email
send_template_email(
template='emails/welcome.html',
context={'user': user, 'activation_link': activation_url},
to=[user.email],
subject='Welcome! Please activate your account'
)
# Password reset
send_template_email(
template='emails/password_reset.html',
context={'user': user, 'reset_link': reset_url},
to=[user.email],
subject='Reset your password'
)Transactional Emails
# Order confirmation
send_template_email(
template='emails/order_confirmation.html',
context={'order': order, 'items': order.items.all()},
to=[order.user.email],
subject=f'Order #{order.id} confirmed'
)
# Invoice notification
send_template_email(
template='emails/invoice.html',
context={'invoice': invoice, 'due_date': invoice.due_date},
to=[invoice.customer.email],
subject=f'Invoice #{invoice.number}'
)Marketing Campaigns
# Newsletter
newsletter_recipients = User.objects.filter(
newsletter_subscribed=True,
is_active=True
)
send_bulk_email(
template='emails/newsletter.html',
recipients=[{'email': u.email, 'name': u.get_full_name()} for u in newsletter_recipients],
subject='Monthly Newsletter - December 2024',
context={'featured_articles': articles, 'unsubscribe_url': '...'}
)Features
Template Features
- Rich HTML Templates - Full HTML support with CSS
- Plain Text Alternatives - Auto-generated or custom
- Dynamic Content - Context-based personalization
- Attachments - File and inline image support
- Localization - Multi-language template support
Delivery Features
- Batch Processing - Efficient bulk sending
- Queue Integration - Background processing support
- Retry Logic - Automatic retry on failures
- Rate Limiting - Respect provider limitations
- Bounce Handling - Manage delivery failures
Testing Features
- Email Testing Backend - Development email capture
- Template Preview - Preview emails before sending
- Validation Tools - Email address validation
- Debug Mode - Detailed logging and debugging
See Also
Email Module Documentation
Getting Started:
- Quick Start - Get started sending emails in 5 minutes
- Configuration Guide - Configure email backends
- Environment Variables - SMTP credentials and API keys
Configuration & Setup
Project Setup:
- Installation - Install Django-CFG
- First Project - Complete tutorial
- Modules Overview - All available modules
Email Configuration:
- Type-Safe Configuration - Email config with Pydantic
- Production Config - Production email setup
- Environment Detection - Dev/prod email backends
Related Features
Communication Modules:
- Telegram Module - Telegram bot integration
- Currency Module - Multi-currency support
Built-in Apps:
- Newsletter App - Email marketing campaigns
- Accounts App - Email authentication
- Support App - Support ticket emails
Background Processing:
- Django-RQ Integration - Async email sending
- Background Tasks - Task queue management
Tools & Deployment
CLI & Testing:
- CLI Commands - Test email configuration via CLI
- Troubleshooting - Common email issues
Build powerful email experiences with enterprise reliability! 📧