﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
35033	"EmailMessage repeats ""To"" header if provided via the headers kwargs"	Aalekh Patel	nobody	"If you create an {{{EmailMessage}}} instance with a `""To""` key in the `headers=` kwarg, it attaches the `To` header to the email two times, violating [https://datatracker.ietf.org/doc/html/rfc5322#section-3.6 RFC 5322#3.6].

My suspicion is that it attaches it the first time from {{{extra_headers}}} in  {{{self._set_list_header_if_not_empty(msg, 'To', self.to)}}} at [https://github.com/django/django/blob/8fa7c2ae88aee7a2b54a745d25ed38152aad2591/django/core/mail/message.py#L266 django.core.mail.message:266] and the second time again from {{{extra_headers}}} at [https://github.com/django/django/blob/8fa7c2ae88aee7a2b54a745d25ed38152aad2591/django/core/mail/message.py#L282 django.core.mail.message:282]

{{{#!python
        message = EmailMessage(
            subject=""test subject"",
            body=""test body"",
            from_email=""from@example.com"",
            to=[""guy1@example.com""],
            headers={
                ""To"": "", "".join([""guy1@example.com"", ""guy2@example.com"", ""guy3@example.com""]),
            },
        )
}}}

For example, here is a Python 3.9.18 shell output for the `EmailMessage` above that shows the `To` header appears twice.

{{{#!python
>>> from django.core.mail import EmailMessage

>>> message = EmailMessage(subject=""test subject"", body=""test body"", from_email=""from@example.com"",to=[""guy1@example.com""], headers={""To"": "", "".join([""guy1@example.com"", ""guy2@example.com"", ""guy3@example.com""])})

>>> print(list(message.message().raw_items()))
[('Content-Type', 'text/plain; charset=""utf-8""'), ('MIME-Version', '1.0'), ('Content-Transfer-Encoding', '7bit'), ('Subject', 'test subject'), ('From', 'from@example.com'), ('To', 'guy1@example.com, guy2@example.com, guy3@example.com'), ('Date', 'Wed, 13 Dec 2023 15:59:31 -0000'), ('Message-ID', '<170248317136.759.5778419642073676754@036d358ca984>'), ('To', 'guy1@example.com, guy2@example.com, guy3@example.com')]
}}}


I've provided a patch for this here: [https://github.com/django/django/pull/17606 django/django#17606]"	Bug	new	Core (Mail)	3.2	Normal		email, headers		Unreviewed	1	0	1	0	1	0
