Opened 9 years ago

Closed 8 years ago

#25437 closed Bug (duplicate)

Translation of DEFAULT_FROM_EMAIL not working

Reported by: Maciej Pawlisz Owned by:
Component: Core (Mail) Version: 1.7
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I tried to translate DEFAULT_FROM_EMAIL using ugettext_lazy. Unfortunately it didn't work resulting in a traceback:

  File "C:\Python27\lib\site-packages\django\core\mail\message.py", line 276, in send
    return self.get_connection(fail_silently).send_messages([self])
  File "C:\Python27\lib\site-packages\django\core\mail\backends\smtp.py", line 94, in send_messages
    sent = self._send(message)
  File "C:\Python27\lib\site-packages\django\core\mail\backends\smtp.py", line 105, in _send
    from_email = sanitize_address(email_message.from_email, email_message.encoding)
  File "C:\Python27\lib\site-packages\django\core\mail\message.py", line 104, in sanitize_address
    nm, addr = addr
ValueError: too many values to unpack

I think that there is a bug in sanitize_address:

def sanitize_address(addr, encoding):
    if isinstance(addr, six.string_types):
        addr = parseaddr(force_text(addr))
    nm, addr = addr

parseaddr is never called because addr is not a six.string_types, but a django.utils.functional.__proxy__. force_text should be called before that check or if condition should be different, ie:

  if not isinstance(addr,(tuple,list)):
    addr = parseaddr(force_text(addr))

Change History (6)

comment:1 by Claude Paroz, 9 years ago

Triage Stage: UnreviewedAccepted

I'ts a bit of a corner case to translate en email address, but this shouldn't be so hard to support, so any proposed fix is welcome.

comment:2 by Anderson Resende, 8 years ago

Owner: changed from nobody to Anderson Resende
Status: newassigned

comment:3 by Anderson Resende, 8 years ago

Owner: Anderson Resende removed
Status: assignednew

comment:4 by Adam, 8 years ago

why would the DEFAULT_FROM_EMAIL be translated (it's an email address)? Is there some other case which is causing this error as well or am I missing something?

comment:5 by Claude Paroz, 8 years ago

My guess of the use case was that the from email depends on the current language, so when the user answers to the email, it is automatically sent to the right language-dependent contact point.

comment:6 by Huynh Thanh Tam, 8 years ago

Resolution: duplicate
Status: newclosed

Duplicate with #24416

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