[Django] #37345: Add mailer shorthand for mailers[DEFAULT_MAILER_ALIAS]

18 views
Skip to first unread message

Django

unread,
Sep 13, 2026, 8:54:39 AM (6 days ago) Sep 13
to django-...@googlegroups.com
#37345: Add mailer shorthand for mailers[DEFAULT_MAILER_ALIAS]
-------------------------------------+-------------------------------------
Reporter: Johannes Maron | Type:
| Cleanup/optimization
Status: new | Component: Core
| (Mail)
Version: 6.1 | Severity: Normal
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Howdy,

The new mailers interfaces is lacking a `django.db.connection` equivalent.
A `django.mail.mailer` shorthand for `mailers[DEFAULT_MAILER_ALIAS]` would
simplify the transition away from `get_connection`.

I would have complained earlier during development, but I simply missed
it. Only that I am migrating a project now, I realize it's inconsistent
with `django.db` or `django.cache`.

Cheerio
-Joe
--
Ticket URL: <https://code.djangoproject.com/ticket/37345>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Sep 13, 2026, 11:09:40 AM (6 days ago) Sep 13
to django-...@googlegroups.com
#37345: Add mailer shorthand for mailers[DEFAULT_MAILER_ALIAS]
-------------------------------------+-------------------------------------
Reporter: Johannes Maron | Owner: (none)
Type: | Status: new
Cleanup/optimization |
Component: Core (Mail) | Version: 6.1
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Md. Saikat Islam):

Can you add more information?

I think we already support this for default(as you mentioned for default)
alias:
{{{
from django.core import mail

email_list = get_notification_emails()

# Use the default mailer. You could substitute
# mail.mailers["alias"] for a specific mailer.
backend = mail.mailers.default

backend.send_messages(email_list)

}}}

So we can use `.default` with mailers. But all other aliases (including
default) can be accessed using `mail.mailers["alias"]`.

Check this out: https://docs.djangoproject.com/en/dev/topics/email/
--
Ticket URL: <https://code.djangoproject.com/ticket/37345#comment:1>

Django

unread,
Sep 13, 2026, 1:54:46 PM (6 days ago) Sep 13
to django-...@googlegroups.com
#37345: Add mailer shorthand for mailers[DEFAULT_MAILER_ALIAS]
-------------------------------------+-------------------------------------
Reporter: Johannes Maron | Owner:
Type: | ssknight-23
Cleanup/optimization | Status: assigned
Component: Core (Mail) | Version: 6.1
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by ssknight-23):

* cc: ssknight-23 (added)
* owner: (none) => ssknight-23
* status: new => assigned

--
Ticket URL: <https://code.djangoproject.com/ticket/37345#comment:2>

Django

unread,
Sep 14, 2026, 4:46:15 AM (6 days ago) Sep 14
to django-...@googlegroups.com
#37345: Add mailer shorthand for mailers[DEFAULT_MAILER_ALIAS]
-------------------------------------+-------------------------------------
Reporter: Johannes Maron | Owner:
Type: | ssknight-23
Cleanup/optimization | Status: assigned
Component: Core (Mail) | Version: 6.1
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Sarah Boyce):

* cc: Mike Edmunds (added)

--
Ticket URL: <https://code.djangoproject.com/ticket/37345#comment:3>

Django

unread,
Sep 14, 2026, 11:32:16 AM (5 days ago) Sep 14
to django-...@googlegroups.com
#37345: Add mailer shorthand for mailers[DEFAULT_MAILER_ALIAS]
-------------------------------------+-------------------------------------
Reporter: Johannes Maron | Owner:
Type: | ssknight-23
Cleanup/optimization | Status: closed
Component: Core (Mail) | Version: 6.1
Severity: Normal | Resolution: invalid
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mike Edmunds):

* resolution: => invalid
* status: assigned => closed

Comment:

As pointed out in comment:1, `django.core.mail.mailers.default` returns
the default mailer instance
([https://docs.djangoproject.com/en/6.1/topics/email/#django.core.mail.mailers.default
docs]). It is
[https://github.com/django/deps/blob/main/accepted/0018-mailers.md
#mailers-factory:~:text=mailers.default%20is,the%20next%20section.) meant
to parallel] `django.db.connection`, `django.core.cache.cache`,
`django.tasks.default_task_backend`, and similar accessors.

We can't create a module-level accessor like
`django.core.mail.default_mailer`, because Django's `ConnectionProxy` and
`LazyObject` helpers (used for module-level accessors) require cacheable
instances. In general, `EmailBackend` instances
[https://github.com/django/deps/blob/main/accepted/0018-mailers.md
#mailers-instances-are-not-cached are not cacheable].
--
Ticket URL: <https://code.djangoproject.com/ticket/37345#comment:4>

Django

unread,
Sep 14, 2026, 12:18:33 PM (5 days ago) Sep 14
to django-...@googlegroups.com
#37345: Add mailer shorthand for mailers[DEFAULT_MAILER_ALIAS]
-------------------------------------+-------------------------------------
Reporter: Johannes Maron | Owner:
Type: | ssknight-23
Cleanup/optimization | Status: new
Component: Core (Mail) | Version: 6.1
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Johannes Maron):

* resolution: invalid =>
* status: closed => new

Comment:

Is it worth making the same path available on other connection proxies?
For example: `django.db.connections.default`,
`django.cache.caches.default`, ...

The purpose of this DEP was consistency, right? My confusion may be an
indicator that there's still some work to be done. And I pride myself on
knowing Django somewhat well. Newcomers might have an even harder time
understanding this.
--
Ticket URL: <https://code.djangoproject.com/ticket/37345#comment:5>

Django

unread,
Sep 14, 2026, 12:40:28 PM (5 days ago) Sep 14
to django-...@googlegroups.com
#37345: Add mailer shorthand for mailers[DEFAULT_MAILER_ALIAS]
-------------------------------------+-------------------------------------
Reporter: Johannes Maron | Owner:
Type: | ssknight-23
Cleanup/optimization | Status: new
Component: Core (Mail) | Version: 6.1
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Mike Edmunds):

Replying to [comment:5 Johannes Maron]:
> Is it worth making the same path available on other connection proxies?
> For example: `django.db.connections.default`,
`django.cache.caches.default`, ...

I like that idea. (And then maybe eventually deprecating the module-level
lazy proxies.)

It might be better to open a separate ticket specifically for that
request, to avoid confusion.
--
Ticket URL: <https://code.djangoproject.com/ticket/37345#comment:6>

Django

unread,
Sep 14, 2026, 12:57:43 PM (5 days ago) Sep 14
to django-...@googlegroups.com
#37345: Add mailer shorthand for mailers[DEFAULT_MAILER_ALIAS]
-------------------------------------+-------------------------------------
Reporter: Johannes Maron | Owner:
| ssknight-23
Type: New feature | Status: closed
Component: Core (Mail) | Version: 6.1
Severity: Normal | Resolution:
| needsnewfeatureprocess
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Johannes Maron):

* resolution: => needsnewfeatureprocess
* status: new => closed
* type: Cleanup/optimization => New feature

Comment:

I'll pass it down the proper channels then :)
--
Ticket URL: <https://code.djangoproject.com/ticket/37345#comment:7>

Django

unread,
Sep 14, 2026, 1:07:32 PM (5 days ago) Sep 14
to django-...@googlegroups.com
#37345: Add mailer shorthand for mailers[DEFAULT_MAILER_ALIAS]
-------------------------------------+-------------------------------------
Reporter: Johannes Maron | Owner:
| ssknight-23
Type: New feature | Status: closed
Component: Core (Mail) | Version: 6.1
Severity: Normal | Resolution:
| needsnewfeatureprocess
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Johannes Maron):

https://github.com/django/new-features/issues/209
--
Ticket URL: <https://code.djangoproject.com/ticket/37345#comment:8>
Reply all
Reply to author
Forward
0 new messages