Opened 7 years ago

Closed 7 years ago

#7574 closed (fixed)

EmailMultiAlternatives and send_email do not handle ugettext_lazy translated strings correctly

Reported by: gary.hutspot@… Owned by: mk
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: UI/UX:


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 mk 7 years ago.

Download all attachments as: .zip

Change History (6)

comment:1 Changed 7 years ago by erl

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

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

Changed 7 years ago by mk

comment:2 Changed 7 years ago by mk

  • Has patch set
  • Triage Stage changed from Unreviewed to Ready for checkin

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

comment:3 Changed 7 years ago by mk

  • Owner changed from nobody to mk
  • Status changed from new to assigned

comment:4 Changed 7 years ago by mtredinnick

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 7 years ago by mtredinnick

  • Resolution set to fixed
  • Status changed from assigned to closed

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

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