A Django email backend that dynamically selects between Django's SMTP backend and a configurable email backend based on the sender's email address. Configure specific email addresses to use SMTP while falling back to a default backend for all other addresses.
- Automatically routes emails based on the sender's address.
- Uses SMTP for specific addresses defined in your Django settings.
- Defaults to a configurable backend (eg django_mailgun) for all other addresses.
- Simple integration with existing Django projects.
Install directly from GitHub using pip
:
pip install -e git+ssh://[email protected]/openlibhums/[email protected]#egg=django-selective-email-backend
Add the backend to your settings.py:
EMAIL_BACKEND = 'selective_email_backend.backends.SelectiveEmailBackend'
Define the SMTP email addresses and other relevant settings:
# settings.py
INSTALLED_APPS = [
...
'selective_email_backend',
...
]
DEFAULT_EMAIL_BACKEND = 'django_mailgun.MailgunBackend'
SMTP_EMAIL_ADDRESSES = [
'[email protected]',
'[email protected]',
]
# Mailgun settings
MAILGUN_ACCESS_KEY = 'mailgun-access-key'
MAILGUN_SERVER_NAME = 'mailgun-server-name'
# SMTP settings
EMAIL_HOST = 'smtp.janeway.systems'
EMAIL_PORT = 587
EMAIL_USE_TLS = True
EMAIL_HOST_USER = 'smtp-user-name'
EMAIL_HOST_PASSWORD = 'smtp-password'