Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

[Django] #28912: EmailMessage.message() should not set a blank To: field when EmailMessage.to is empty

5 views
Skip to first unread message

Django

unread,
Dec 8, 2017, 11:01:31 PM12/8/17
to django-...@googlegroups.com
#28912: EmailMessage.message() should not set a blank To: field when
EmailMessage.to is empty
------------------------------------------------+------------------------
Reporter: Jon Dufresne | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Core (Mail) | Version: master
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
------------------------------------------------+------------------------
`EmailMessage.message()` always sets a `To:` header, see:

https://github.com/django/django/blob/a9e5ac823df8ba8b786b6450c967ca378c008d0e/django/core/mail/message.py#L257

In my project, emails are sent to `Cc:` or `Bcc:` recipients without a
`To:` recipient.

Some mail backends are very strict about allowed headers and their values.
For example, Amazon Simple Email Service (SES) validates all recipient
headers to contain valid email addresses. It fails without delivery if any
header contains an invalid address. For some details, see:

https://boto3.readthedocs.io/en/latest/reference/services/ses.html#SES.Client.send_raw_email

> The message must include at least one recipient email address. The
recipient address can be a To: address, a CC: address, or a BCC: address.
If a recipient email address is invalid (that is, it is not in the format
UserName@[SubDomain.]Domain.TopLevelDomain ), the entire message will be
rejected, even if the message contains other recipients that are valid.

SES considers blank as invalid. When sending an email serialized by
`EmailMessage.message()` to `Cc:` or `Bcc:` only addresses, SES fails with
an error. `To:` avoid the error, Django can avoid setting the To header
when `EmailMessage.to` is empty.

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

Django

unread,
Dec 9, 2017, 12:15:23 AM12/9/17
to django-...@googlegroups.com
#28912: EmailMessage.message() should not set a blank To: field when
EmailMessage.to is empty
-------------------------------------+-------------------------------------

Reporter: Jon Dufresne | Owner: nobody
Type: | Status: new
Cleanup/optimization |

Component: Core (Mail) | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Jon Dufresne):

* has_patch: 0 => 1


Comment:

[https://github.com/django/django/pull/9454 PR]

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

Django

unread,
Dec 9, 2017, 5:38:26 AM12/9/17
to django-...@googlegroups.com
#28912: EmailMessage.message() should not set a blank To: field when
EmailMessage.to is empty
--------------------------------------+------------------------------------

Reporter: Jon Dufresne | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Core (Mail) | Version: master
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 Claude Paroz):

* stage: Unreviewed => Accepted


Comment:

Makes sense.

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

Django

unread,
Dec 18, 2017, 3:56:50 AM12/18/17
to django-...@googlegroups.com
#28912: EmailMessage.message() should not set a blank To: field when
EmailMessage.to is empty
-------------------------------------+-------------------------------------

Reporter: Jon Dufresne | Owner: nobody
Type: | Status: new
Cleanup/optimization |

Component: Core (Mail) | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Claude Paroz):

* stage: Accepted => Ready for checkin


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

Django

unread,
Dec 30, 2017, 9:55:27 AM12/30/17
to django-...@googlegroups.com
#28912: EmailMessage.message() should not set a blank To: field when
EmailMessage.to is empty
-------------------------------------+-------------------------------------

Reporter: Jon Dufresne | Owner: nobody
Type: | Status: closed
Cleanup/optimization |

Component: Core (Mail) | Version: master
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham <timograham@…>):

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


Comment:

In [changeset:"da82939e5a31dea21a4f4d5085dfcd449fcbed3a" da82939]:
{{{
#!CommitTicketReference repository=""
revision="da82939e5a31dea21a4f4d5085dfcd449fcbed3a"
Fixed #28912 -- Made EmailMessage.message() omit an empty To header.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/28912#comment:4>

Django

unread,
Jul 11, 2024, 2:00:58 AM7/11/24
to django-...@googlegroups.com
#28912: EmailMessage.message() should not set a blank To: field when
EmailMessage.to is empty
-------------------------------------+-------------------------------------
Reporter: Jon Dufresne | Owner: nobody
Type: | Status: closed
Cleanup/optimization |
Component: Core (Mail) | Version: dev
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Sarah Boyce <42296566+sarahboyce@…>):

In [changeset:"b9098538a966fdc1f2b5ee51c094ca3de4db6344" b909853]:
{{{#!CommitTicketReference repository=""
revision="b9098538a966fdc1f2b5ee51c094ca3de4db6344"
Fixed #35033, Refs #28912 -- Fixed repeated headers in EmailMessage.

Fixed a regression which would cause multiple To, Cc, and
Reply-To headers in the result of EmailMessage.message() if
values were supplied for both to/cc/reply_to and the
corresponding extra_headers fields.

Updated related tests to check the generated message() has
exactly one of each expected header using get_all().

Regression in b03d5002955256c4b3ed7cfae5150eb79c0eb97e.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/28912#comment:5>
Reply all
Reply to author
Forward
0 new messages