Re: [Django] #36132: Add **kwargs to send_mail() and send_mass_mail() functions

12 views
Skip to first unread message

Django

unread,
Jan 23, 2025, 6:39:06 PM1/23/25
to django-...@googlegroups.com
#36132: Add **kwargs to send_mail() and send_mass_mail() functions
-------------------------------------+-------------------------------------
Reporter: Nikolay Fedorov | Owner: (none)
Type: | Status: closed
Cleanup/optimization |
Component: Core (Mail) | Version: 5.1
Severity: Normal | Resolution: wontfix
Keywords: send_email, | Triage Stage:
send_mass_mail, mail | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Nikolay Fedorov):

But in {{{user.email_user}}} you are pass {{{**kwargs}}} to
{{{send_mail}}} which doesn't support this... this is a component
inconsistency.
--
Ticket URL: <https://code.djangoproject.com/ticket/36132#comment:2>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jan 23, 2025, 6:50:28 PM1/23/25
to django-...@googlegroups.com
#36132: Add **kwargs to send_mail() and send_mass_mail() functions
-------------------------------------+-------------------------------------
Reporter: Nikolay Fedorov | Owner: (none)
Type: | Status: closed
Cleanup/optimization |
Component: Core (Mail) | Version: 5.1
Severity: Normal | Resolution: wontfix
Keywords: send_email, | Triage Stage:
send_mass_mail, mail | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Simon Charette):

The fact that `user.send_mail` delegates `**kwargs` to `mail.send_mail`
which has a documented signature only makes it so both share the same
interface.

I don't see what is incoherent about `send_mail` not passing arbitrary
kwargs to `EmailMessage`. In other words, I don't see why a function that
opts in `**kwargs` delegation should force all functions down its stack to
also do so.
--
Ticket URL: <https://code.djangoproject.com/ticket/36132#comment:3>

Django

unread,
Jan 24, 2025, 4:20:48 AM1/24/25
to django-...@googlegroups.com
#36132: Add **kwargs to send_mail() and send_mass_mail() functions
-------------------------------------+-------------------------------------
Reporter: Nikolay Fedorov | Owner: (none)
Type: | Status: closed
Cleanup/optimization |
Component: Core (Mail) | Version: 5.1
Severity: Normal | Resolution: wontfix
Keywords: send_email, | Triage Stage:
send_mass_mail, mail | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Nikolay Fedorov):

Replying to [comment:3 Simon Charette]:
> The fact that `user.send_mail` delegates `**kwargs` to `mail.send_mail`
which has a documented signature only makes it so both share the same
interface.
>
> I don't see what is incoherent about `send_mail` not passing arbitrary
kwargs to `EmailMessage`. In other words, I don't see why a function that
opts in `**kwargs` delegation should force all functions down its stack to
also do so.

I didn't mean arbitrary arguments, but I wanted to be able to use all the
available documented ones for `EmailMessage`, such as `headers`. Now, for
this, I have to use my own rewritten version of `send_mail` to simply
transfer headers. This is a discrepancy between the system components and
not a convenience.
--
Ticket URL: <https://code.djangoproject.com/ticket/36132#comment:4>

Django

unread,
Jan 28, 2025, 3:58:58 PM1/28/25
to django-...@googlegroups.com
#36132: Add **kwargs to send_mail() and send_mass_mail() functions
-------------------------------------+-------------------------------------
Reporter: Nikolay Fedorov | Owner: (none)
Type: | Status: closed
Cleanup/optimization |
Component: Core (Mail) | Version: 5.1
Severity: Normal | Resolution: wontfix
Keywords: send_email, | Triage Stage:
send_mass_mail, mail | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Mike Edmunds):

If the primary request here is for the
[https://docs.djangoproject.com/en/5.1/ref/contrib/auth/#django.contrib.auth.models.User.email_user
User.email_user()] method to accept additional arguments like `headers` or
`reply_to`, that ''might'' be a reasonable feature request. There are ways
to achieve that without changing the "frozen" mail.send_mail() API, by
updating User.email_user() from legacy send_mail() to using the newer
EmailMessage classes. (My opinion only; I don't speak for Django.)

If that's your goal, the next step would be to raise the idea in the
[https://forum.djangoproject.com/ forum] to seek feedback. It would help
to include a concrete example of what you're trying to do (e.g., what
headers you need to add in `User.email_user()`).

Or, if the primary request here is a single statement that sends mail with
headers, you can achieve that now with the EmailMessage (or
EmailMultiAlternatives) class:

{{{#!python
EmailMessage(subject, message, from_email, to, headers={"In-Reply-To":
"..."}).send()
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/36132#comment:5>
Reply all
Reply to author
Forward
0 new messages