[Django] #37167: (Officially) allow Address objects as email addresses

12 views
Skip to first unread message

Django

unread,
Jun 12, 2026, 9:15:00 PMJun 12
to django-...@googlegroups.com
#37167: (Officially) allow Address objects as email addresses
-------------------------------------+-------------------------------------
Reporter: Mike | Owner: Mike Edmunds
Edmunds |
Type: | Status: assigned
Cleanup/optimization |
Component: Core | Version: 6.0
(Mail) |
Severity: Normal | Keywords:
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
Django should officially support Python `email.headerregistry.Address`
objects in django.core.mail functions and the `ADMINS`, `MANAGERS`,
`DEFAULT_FROM_EMAIL`, and `SERVER_EMAIL` settings.

This actually works now (for everything except `ADMINS` and `MANAGERS`),
but isn't officially documented or tested. (And it ''would'' work for
`ADMINS` and `MANAGERS` except that they specifically reject any non-`str`
values to help avoid config errors.)

Forum request: https://forum.djangoproject.com/t/ticket-34753-document-
how-to-properly-escape-to-in-email-messages/43551/10.

== Background

Python's
[https://docs.python.org/3/library/email.headerregistry.html#email.headerregistry.Address
email.headerregistry.Address] object can be used to compose an email
address from parts (a `display_name` and `addr_spec` or `username` and
`domain`). And for security, it ''should'' be used when building an email
address from user-supplied parts (see #34753 and
[https://github.com/django/django/pull/21467 PR #21467]).

Python's `EmailMessage` class accepts `Address` objects in all address
headers. You can a set a message's "From" header to an `Address`, or its
"Cc" header to a list of `Address` objects. (You can also set a "Date"
header to a `datetime` object, etc.)

Django's `EmailMessage` class accidentally supports `Address` objects, in
all headers since 6.0 and in all but "From" since at least 5.2 (maybe
earlier). It currently converts the address objects to strings, and then
Python parses them back into address objects.

== Proposal

* Update the `ADMINS` and `MANAGERS` recipient-type check in
`django.core.mail._send_server_message()` to allow `Address`.
* Change `EmailMessage.message()` and `_set_list_header_if_not_empty()` to
avoid casting an `Address` to a `str` just so Python can parse it back
again. (The cast is there primarily for lazy strings.)
* Add tests!
--
Ticket URL: <https://code.djangoproject.com/ticket/37167>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jun 19, 2026, 2:08:21 PMJun 19
to django-...@googlegroups.com
#37167: (Officially) allow Address objects as email addresses
-------------------------------------+-------------------------------------
Reporter: Mike Edmunds | Owner: Mike
Type: | Edmunds
Cleanup/optimization | Status: assigned
Component: Core (Mail) | Version: 6.0
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
-------------------------------------+-------------------------------------
Changes (by Tim Graham):

* stage: Unreviewed => Accepted

--
Ticket URL: <https://code.djangoproject.com/ticket/37167#comment:1>

Django

unread,
Jul 3, 2026, 5:15:46 PM (10 days ago) Jul 3
to django-...@googlegroups.com
#37167: (Officially) allow Address objects as email addresses
--------------------------------------+------------------------------------
Reporter: Mike Edmunds | Owner: (none)
Type: Cleanup/optimization | Status: new
Component: Core (Mail) | Version: 6.0
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
--------------------------------------+------------------------------------
Changes (by Mike Edmunds):

* owner: Mike Edmunds => (none)
* status: assigned => new

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

Django

unread,
Jul 6, 2026, 10:57:25 AM (8 days ago) Jul 6
to django-...@googlegroups.com
#37167: (Officially) allow Address objects as email addresses
-------------------------------------+-------------------------------------
Reporter: Mike Edmunds | Owner: VIZZARD-X
Type: | Status: assigned
Cleanup/optimization |
Component: Core (Mail) | Version: 6.0
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
-------------------------------------+-------------------------------------
Changes (by VIZZARD-X):

* owner: (none) => VIZZARD-X
* status: new => assigned

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

Django

unread,
Jul 10, 2026, 1:55:24 PM (4 days ago) Jul 10
to django-...@googlegroups.com
#37167: (Officially) allow Address objects as email addresses
-------------------------------------+-------------------------------------
Reporter: Mike Edmunds | Owner: VIZZARD-X
Type: | Status: assigned
Cleanup/optimization |
Component: Core (Mail) | Version: 6.0
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by VIZZARD-X):

* has_patch: 0 => 1

Comment:

[https://github.com/django/django/pull/21610 PR]
--
Ticket URL: <https://code.djangoproject.com/ticket/37167#comment:4>
Reply all
Reply to author
Forward
0 new messages