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
settings.configure(EMAIL_HOST='your.smtp.server')
send_mail(_('Subject here'), 'Here is the message.', 'from@example.com', ['to@example.com'], fail_silently=False)
Produces:
$ python proof.py
Traceback (most recent call last):
File "proof.py", line 8, in <module>
fail_silently=False)
File "/usr/lib/python2.5/site-packages/django/core/mail.py", line 333, in send_mail
connection=connection).send()
File "/usr/lib/python2.5/site-packages/django/core/mail.py", line 259, in send
return self.get_connection(fail_silently).send_messages([self])
File "/usr/lib/python2.5/site-packages/django/core/mail.py", line 168, in send_messages
sent = self._send(message)
File "/usr/lib/python2.5/site-packages/django/core/mail.py", line 182, in _send
email_message.message().as_string())
File "/usr/lib/python2.5/site-packages/django/core/mail.py", line 241, in message
msg['Subject'] = self.subject
File "/usr/lib/python2.5/site-packages/django/core/mail.py", line 92, in __setitem__
name, val = forbid_multi_line_headers(name, val)
File "/usr/lib/python2.5/site-packages/django/core/mail.py", line 74, in forbid_multi_line_headers
if '\n' in val or '\r' in val:
TypeError: argument of type '__proxy__' is not iterable