[Django] #17811: Connection object is no passed to the EmailMessage constructor when called from send_mass_mail

7 views
Skip to first unread message

Django

unread,
Mar 2, 2012, 4:06:38 AM3/2/12
to django-...@googlegroups.com
#17811: Connection object is no passed to the EmailMessage constructor when called
from send_mass_mail
-----------------------------+-------------------------------------
Reporter: fed239 | Owner: nobody
Type: Bug | Status: new
Component: Core (Mail) | Version: 1.3
Severity: Normal | Keywords: mail, connection, email
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------+-------------------------------------
There is a difference in the behavior of send_mail and send_mass_mail
function. send_mail passes connection as a parameter to the EmailMessage
constructor and send_mass_mail does not.
{{{
44 def send_mail(subject, message, from_email, recipient_list,
45 fail_silently=False, auth_user=None,
auth_password=None,
46 connection=None):
...
57 connection = connection or get_connection(username=auth_user,
58 password=auth_password,
59 fail_silently=fail_silently)
60 return EmailMessage(subject, message, from_email,
recipient_list,
61 connection=connection).send()
}}}

{{{
64 def send_mass_mail(datatuple, fail_silently=False, auth_user=None,
65 auth_password=None, connection=None):
...
78 connection = connection or get_connection(username=auth_user,
79 password=auth_password,
80 fail_silently=fail_silently)
81 messages = [EmailMessage(subject, message, sender, recipient)
82 for subject, message, sender, recipient in
datatuple]
83 return connection.send_messages(messages)
}}}

This causes troubles if email backend stores something inside the self
object for the later use and expects that messages would have reference to
it.

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

Django

unread,
Mar 2, 2012, 2:44:04 PM3/2/12
to django-...@googlegroups.com
#17811: Connection object is no passed to the EmailMessage constructor when called
from send_mass_mail
-------------------------------------+-------------------------------------
Reporter: fed239 | Owner: nobody
Type: Bug | Status: new
Component: Core (Mail) | Version: 1.3
Severity: Normal | Resolution:
Keywords: mail, connection, | Triage Stage: Accepted
email | Needs documentation: 0
Has patch: 0 | Patch needs improvement: 0
Needs tests: 0 | UI/UX: 0
Easy pickings: 1 |
-------------------------------------+-------------------------------------
Changes (by jezdez):

* needs_docs: => 0
* needs_better_patch: => 0
* needs_tests: => 0
* easy: 0 => 1
* stage: Unreviewed => Accepted


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

Django

unread,
Mar 12, 2012, 4:32:56 PM3/12/12
to django-...@googlegroups.com
#17811: Connection object is no passed to the EmailMessage constructor when called
from send_mass_mail
-------------------------------------+-------------------------------------
Reporter: fed239 | Owner: danielr
Type: Bug | Status: assigned
Component: Core (Mail) | Version: 1.3
Severity: Normal | Resolution:
Keywords: mail, connection, | Triage Stage: Accepted
email | Needs documentation: 0
Has patch: 0 | Patch needs improvement: 0
Needs tests: 0 | UI/UX: 0
Easy pickings: 1 |
-------------------------------------+-------------------------------------
Changes (by danielr):

* owner: nobody => danielr
* status: new => assigned


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

Django

unread,
Mar 12, 2012, 4:40:16 PM3/12/12
to django-...@googlegroups.com
#17811: Connection object is no passed to the EmailMessage constructor when called
from send_mass_mail
-------------------------------------+-------------------------------------
Reporter: fed239 | Owner: danielr
Type: Bug | Status: assigned
Component: Core (Mail) | Version: 1.3
Severity: Normal | Resolution:
Keywords: mail, connection, | Triage Stage: Ready for
email | checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by danielr):

* has_patch: 0 => 1
* stage: Accepted => Ready for checkin


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

Django

unread,
Mar 29, 2012, 5:35:49 AM3/29/12
to django-...@googlegroups.com
#17811: Connection object is no passed to the EmailMessage constructor when called
from send_mass_mail
-------------------------------------+-------------------------------------
Reporter: fed239 | Owner: danielr
Type: Bug | Status: assigned
Component: Core (Mail) | Version: 1.3
Severity: Normal | Resolution:
Keywords: mail, connection, | Triage Stage: Ready for
email | checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by jezdez):

LGTM (for the record, please don't mark ticket as RFC if you're the ticket
author :)

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

Django

unread,
Mar 29, 2012, 2:53:28 PM3/29/12
to django-...@googlegroups.com
#17811: Connection object is no passed to the EmailMessage constructor when called
from send_mass_mail
-------------------------------------+-------------------------------------
Reporter: fed239 | Owner: danielr
Type: Bug | Status: closed
Component: Core (Mail) | Version: 1.3
Severity: Normal | Resolution: fixed
Keywords: mail, connection, | Triage Stage: Ready for
email | checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by claudep):

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


Comment:

In [17827]:
{{{
#!CommitTicketReference repository="" revision="17827"
Fixed #17811 -- Added connection parameter in call to EmailMessage from
send_mass_mail. Thanks fed239 for the report and danielr for the patch.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/17811#comment:5>

Django

unread,
Apr 24, 2026, 4:12:45 PMApr 24
to django-...@googlegroups.com
#17811: Connection object is no passed to the EmailMessage constructor when called
from send_mass_mail
-------------------------------------+-------------------------------------
Reporter: Fedor Tyurin | Owner: Daniel
| Roseman
Type: Bug | Status: closed
Component: Core (Mail) | Version: 1.3
Severity: Normal | Resolution: fixed
Keywords: mail, connection, | Triage Stage: Ready for
email | checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Mike Edmunds):

Replying to [ticket:17811 Fedor Tyurin]:
> This causes troubles if email backend stores something inside the self
object for the later use and expects that messages would have reference to
it.

In general, an EmailBackend instance ''cannot'' assume that
`EmailMessage.connection` has been set to the backend instance after the
backend has been used to send the message. Django supports (and
[https://docs.djangoproject.com/en/6.0/topics/email/#topics-sending-
multiple-emails documents]) directly calling `backend.send_messages([...
list of EmailMessage ...])`, which doesn't set the `connection` property
on the sent messages. See #35864.

If a specific backend implementation needs to ensure
`EmailMessage.connection` is always set, it should set each message's
`connection` property to `self` in its `send_messages()` method.

(Also, we're about to deprecate and remove `connection` entirely as part
of #35514.)
--
Ticket URL: <https://code.djangoproject.com/ticket/17811#comment:6>
Reply all
Reply to author
Forward
0 new messages