Opened 11 years ago

Closed 11 years ago

#7574 closed (fixed)

EmailMultiAlternatives and send_email do not handle ugettext_lazy translated strings correctly

Reported by: gary.hutspot@… Owned by: Matthias Kestenholz
Component: Core (Mail) Version: master
Severity: Keywords:
Cc: gary.hutspot@… Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


When trying to send email with a subject that is lazily translated, the following TypeError is thrown:

argument of type 'proxy' is not iterable

Cut and paste compatible example:

from django.utils.translation import ugettext_lazy as _
from django.core.mail import send_mail
from django.conf import settings

# If you do not have smtp running on your local system, specify your smtp server here

send_mail(_('Subject here'), 'Here is the message.', '', [''], fail_silently=False)


$ python 
Traceback (most recent call last):
  File "", line 8, in <module>
  File "/usr/lib/python2.5/site-packages/django/core/", line 333, in send_mail
  File "/usr/lib/python2.5/site-packages/django/core/", line 259, in send
    return self.get_connection(fail_silently).send_messages([self])
  File "/usr/lib/python2.5/site-packages/django/core/", line 168, in send_messages
    sent = self._send(message)
  File "/usr/lib/python2.5/site-packages/django/core/", line 182, in _send
  File "/usr/lib/python2.5/site-packages/django/core/", line 241, in message
    msg['Subject'] = self.subject
  File "/usr/lib/python2.5/site-packages/django/core/", line 92, in __setitem__
    name, val = forbid_multi_line_headers(name, val)
  File "/usr/lib/python2.5/site-packages/django/core/", line 74, in forbid_multi_line_headers
    if '\n' in val or '\r' in val:
TypeError: argument of type '__proxy__' is not iterable

Attachments (1)

7574.patch (919 bytes) - added by Matthias Kestenholz 11 years ago.

Download all attachments as: .zip

Change History (6)

comment:1 Changed 11 years ago by Muriel Bowie

I am having the same problem. Currently I use ugettext instead of ugettext_lazy as a workaround.

Changed 11 years ago by Matthias Kestenholz

Attachment: 7574.patch added

comment:2 Changed 11 years ago by Matthias Kestenholz

Has patch: set
Triage Stage: UnreviewedReady for checkin

Just changing the order of the force_unicode block and the \n/\r detection block is enough.

comment:3 Changed 11 years ago by Matthias Kestenholz

Owner: changed from nobody to Matthias Kestenholz
Status: newassigned

comment:4 Changed 11 years ago by Malcolm Tredinnick

Since Header instances don't act as containers or sequences (they don't support in tests), this patch cannot work. Writing as test for the failing case might have helped detect that.

(Thanks for taking the time to write a patch, but please let somebody else triage it to "ready for checkin" so that we get another set of eyes on that patch for review.)

comment:5 Changed 11 years ago by Malcolm Tredinnick

Resolution: fixed
Status: assignedclosed

(In [8083]) Fixed #7574 -- Fixed the handling of lazy translation in email headers.

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