Support for several SMTP configurations in a single site
Project description
Why?
Some projects may want to sent emails over multiple SMTP relays or smarthosts. Examples are sites running on multiple domains, e.g. info@example.com and info@example.org. It may be possible to use the same SMTP credentials for each sender address but if that isn’t possible django-email-hosts may be a good solution for the problem.
Usage
Install: pip install django-email-hosts
Configure: Add the EMAIL_HOSTS setting
Use: Always explicitly use the SMTP connection returned by email_hosts.backends.get_connection
EMAIL_HOSTS
The keys of the EMAIL_HOSTS dictionary are defined by you and there’s no deeper meaning to them. The values are DSNs inspired by dj-email-url DSNs.
An example configuration (which is possibly nonsensical) looks like this:
EMAIL_HOSTS = {
"sendgrid": "submission://USER:PASSWORD@smtp.sendgrid.com?_default_from_email=info@example.com",
"mailgun": "submission://USER:PASSWORD@smtp.mailgun.com?_default_from_email=info@example.org",
}
This configuration creates two SMTP backends, one using sendgrid and one using mailgun. The _default_from_email is completely optional. If the email message’s from_email isn’t set (resp. is equal to the DEFAULT_FROM_EMAIL setting) it automatically defaults to the per-backend value.
email_hosts.backends.get_connection
The get_connection function expects a single key for the EMAIL_HOSTS setting above. Sending a single email using an explicit connection may look as follows, using the settings from above:
from django.core.mail import EmailMessage
from email_hosts.backends import get_connection
EmailMessage(
"Hello",
"World",
to=["recipient@example.com"],
connection=use_backend("sendgrid"),
).send()
get_connection currently silently returns the default email backend if the key doesn’t exist in the EMAIL_HOSTS dictionary.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file django_email_hosts-0.2.0.tar.gz
.
File metadata
- Download URL: django_email_hosts-0.2.0.tar.gz
- Upload date:
- Size: 4.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.10.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f610a7fc983e66fccd783ebf5d32771d6aa7265ae8fa51d2761c743d668f0ec1 |
|
MD5 | 4d483a25e3bb71be3e32c6777749c6a1 |
|
BLAKE2b-256 | 4f133003acc8cd16a6329cedf6bb1c4a4c8521cd09f8ceb1e67d01f474cee435 |
File details
Details for the file django_email_hosts-0.2.0-py3-none-any.whl
.
File metadata
- Download URL: django_email_hosts-0.2.0-py3-none-any.whl
- Upload date:
- Size: 4.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.10.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cfc527fd02067c08dd3bc30d2ba96a36a6bac6c9b1927cbfa3be6a15ff25f2b2 |
|
MD5 | e28105d96f007cd26e002d1b5b407b87 |
|
BLAKE2b-256 | 6de7655cdf86ca2dfd5aa612537189b7054b57c3d80343c3240b0d8447de41f9 |