Django AppΒΆ
For each distributed Django project that you would like to use the preferred SMTP server, you will need to install the django-email-relay
package and do some basic configuration.
Install the package from PyPI:
pip install django-email-relay
Add
email_relay
to yourINSTALLED_APPS
setting:
INSTALLED_APPS = [
# ...
"email_relay",
# ...
]
Add the
RelayDatabaseEmailBackend
to yourEMAIL_BACKEND
setting:
EMAIL_BACKEND = "email_relay.backend.RelayDatabaseEmailBackend"
Add the email relay database to your
DATABASES
setting. A default database alias is provided atemail_relay.conf.EMAIL_RELAY_DATABASE_ALIAS
which you can import and use:
from email_relay.conf import EMAIL_RELAY_DATABASE_ALIAS
DATABASES = {
# ...
EMAIL_RELAY_DATABASE_ALIAS: {
"ENGINE": "django.db.backends.postgresql",
"NAME": "email_relay_db",
"USER": "email_relay_user",
"PASSWORD": "email_relay_password",
"HOST": "localhost",
"PORT": "5432",
},
# ...
}
If you would like to use a different database alias, you will also need to set the DATABASE_ALIAS
setting within your DJANGO_EMAIL_RELAY
settings:
DATABASES = {
# ...
"some_alias": {
"ENGINE": "django.db.backends.postgresql",
"NAME": "email_relay_db",
"USER": "email_relay_user",
"PASSWORD": "email_relay_password",
"HOST": "localhost",
"PORT": "5432",
},
# ...
}
DJANGO_EMAIL_RELAY = {
# ...
"DATABASE_ALIAS": "some_alias",
# ...
}
Add the
EmailDatabaseRouter
to yourDATABASE_ROUTERS
setting:
DATABASE_ROUTERS = [
# ...
"email_relay.db.EmailDatabaseRouter",
# ...
]
See the documentation here for general information about configuring django-email-relay
.