Opened 14 years ago

Closed 14 years ago

Last modified 7 days ago

#17811 closed Bug (fixed)

Connection object is no passed to the EmailMessage constructor when called from send_mass_mail

Reported by: Fedor Tyurin Owned by: Daniel Roseman
Component: Core (Mail) Version: 1.3
Severity: Normal Keywords: mail, connection, email
Cc: pmclanahan@… Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

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.

Attachments (1)

17811.diff (721 bytes ) - added by Daniel Roseman 14 years ago.

Download all attachments as: .zip

Change History (7)

comment:1 by Jannis Leidel, 14 years ago

Easy pickings: set
Triage Stage: UnreviewedAccepted

comment:2 by Daniel Roseman, 14 years ago

Owner: changed from nobody to Daniel Roseman
Status: newassigned

by Daniel Roseman, 14 years ago

Attachment: 17811.diff added

comment:3 by Daniel Roseman, 14 years ago

Has patch: set
Triage Stage: AcceptedReady for checkin

comment:4 by Jannis Leidel, 14 years ago

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

comment:5 by Claude Paroz, 14 years ago

Resolution: fixed
Status: assignedclosed

In [17827]:

Fixed #17811 -- Added connection parameter in call to EmailMessage from send_mass_mail. Thanks fed239 for the report and danielr for the patch.

in reply to:  description comment:6 by Mike Edmunds, 7 days ago

Replying to 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 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.)

Note: See TracTickets for help on using tickets.
Back to Top