#35514: Dictionary based EMAIL_PROVIDERS settings
-----------------------------+--------------------------------------
Reporter: Jacob Rief | Owner: Jacob Rief
Type: New feature | Status: assigned
Component: Core (Mail) | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------+--------------------------------------
Comment (by Mike Edmunds):
@Jacob Rief Appreciate the responses.
You raise a really interesting idea about non-email messaging apps—I
actually hadn't considered that case. (It probably merits its own
discussion at some point.)
I know of three cases where ''existing'' third-party libraries deal with
Django email and are likely to be impacted by EMAIL_PROVIDERS. I'd hope we
can consider all of these in the design:
A. Email backends that call ESPs' HTTP APIs to send email. (This is what I
meant by "non-SMTP email backends.")
* Examples: [
https://pypi.org/project/django-ses/ django-ses],
[
https://postmarker.readthedocs.io/en/stable/django.html postmarker],
[
https://anymail.dev django-anymail] (disclosure: I maintain django-
anymail)
* These backends typically have their own settings (such as
`POSTMARK_API_KEY`) that are different from Django's existing `EMAIL_*`
settings
* I think your latest PR update to support `OPTIONS` effectively handles
their needs. (And in many cases, these libraries won't even need to be
updated. That's great!)
B. "Wrapper" email backends which add functionality (such as an
asynchronous send queue) and then connect to another email backend for the
actual sending
* Examples: [
https://pypi.org/project/django-mailer/ django-mailer],
[
https://pypi.org/project/django-celery-email/ django-celery-email],
[
https://pypi.org/project/django-post-office/ django-post-office]
* These packages typically have their own setting to specify the
"wrapped" backend and then call Django's
`get_connection(backend=setting_value)`. E.g.: with django-mailer you set
`EMAIL_BACKEND = "mailer.backend.DbBackend"` and then
`MAILER_EMAIL_BACKEND = "django.core.mail.backends.stmp.EmailBackend"`.
* These libraries should continue to work for now with deprecated
`EMAIL_*` settings, but will start to break as the deprecated settings are
removed. We should probably deprecate the `backend` param to
get_connection() now, and add a new `get_connection(provider=...)` option.
(Or deprecate get_connection() and add a new get_provider() to replace
it.)
* Wrapper email backends will need updates to properly use
EMAIL_PROVIDERS. For example, django-mailer could replace its
`MAILER_EMAIL_BACKEND` setting with a new `provider` option:
{{{#!python
EMAIL_PROVIDERS = {
"default:" {
"BACKEND": "mailer.backend.DbBackend",
"OPTIONS": {
# django-mailer needs a NEW option for its wrapped
provider:
"provider": "smtp",
},
},
"smtp": {
"BACKEND": "django.core.mail.backends.stmp.EmailBackend",
"OPTIONS": { ... },
}
}
}}}
* Or, could we think of a way django-mailer could generically wrap
''all'' defined EMAIL_PROVIDERS (except itself), without the user needing
to specify a wrapped version of each?
C. Third-party libraries that send email
* Examples: [
https://pypi.org/project/django-newsletter/ django-
newsletter]; email confirmation in [
https://pypi.org/project/django-
allauth/ django-allauth] and [
https://pypi.org/project/django-user-
accounts/ django-user-accounts]; password reset email in
django.contrib.auth
* As I mentioned earlier, a common use case is wanting a transactional
ESP for password resets, internal SMTP for admin messages, and a bulk ESP
for newsletters
* How would we expect these libraries to allow specifying EMAIL_PROVIDER
aliases for the different types of mail they send?
* (django.utils.log.AdminEmailHandler is another case of this, and
already supports an
[
https://docs.djangoproject.com/en/5.0/ref/logging/#handlers:~:text=By%20setting%20the%20email_backend%20argument%20of%20AdminEmailHandler
email_backend option]. I'd suggest it should also have an `email_provider`
option, and as you say that could be a separate ticket.)
For B & C, I'm just suggesting that we think through what we might expect
those packages to do, and then make sure the EMAIL_PROVIDERS feature will
be compatible with those expectations. (Does that make sense?)
[btw, I agree the names `EMAIL_PROVIDERS` and `provider="<alias>"` are the
best choice. My earlier comments on naming were in response to [#comment:1
comment:1] from Adam Johnson, and I came to the same conclusion as you and
Natalia and Carlton.]
--
Ticket URL: <
https://code.djangoproject.com/ticket/35514#comment:12>