﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
26216	UnicodeDecodeError during _create_attachment	thomasysliu	nobody	"UnicodeDecodeError raised when the file name of the attachment have non 'ascii' characters. 

* Simple Code
{{{
#!div style=""font-size: 80%""
Code highlighting:
  {{{#!python

# -*- coding: utf-8 -*-
from django.core.mail import send_mail
from django.core.mail import EmailMessage
import os
from django.core.management.base import BaseCommand, CommandError

def test():
	filename = u'\u96fb\u5b50\u5b782.ics'
	email = EmailMessage(""subject"", ""body"", to=[""xxx@this.is.an.email.addr""])
	email.attach(filename.encode('utf-8'), ""TEST"")
	email.send()


class Command(BaseCommand):
	args = ''
	help = 'Send mail'
	def handle(self, *args, **options):
		test()


  }}}
}}}
* Traceback
{{{
/tmp/test_email$ python2.7 manage.py test_sendemail
Traceback (most recent call last):
  File ""manage.py"", line 10, in <module>
    execute_from_command_line(sys.argv)
  File ""/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/__init__.py"", line 353, in execute_from_command_line
    utility.execute()
  File ""/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/__init__.py"", line 345, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File ""/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/base.py"", line 348, in run_from_argv
    self.execute(*args, **cmd_options)
  File ""/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/base.py"", line 399, in execute
    output = self.handle(*args, **options)
  File ""/private/tmp/test_email/test_email/management/commands/test_sendemail.py"", line 18, in handle
    test()
  File ""/private/tmp/test_email/test_email/management/commands/test_sendemail.py"", line 11, in test
    email.send()
  File ""/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/mail/message.py"", line 292, in send
    return self.get_connection(fail_silently).send_messages([self])
  File ""/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/mail/backends/smtp.py"", line 107, in send_messages
    sent = self._send(message)
  File ""/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/mail/backends/smtp.py"", line 121, in _send
    message = email_message.message()
  File ""/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/mail/message.py"", line 256, in message
    msg = self._create_message(msg)
  File ""/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/mail/message.py"", line 344, in _create_message
    return self._create_attachments(msg)
  File ""/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/mail/message.py"", line 357, in _create_attachments
    msg.attach(self._create_attachment(*attachment))
  File ""/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/mail/message.py"", line 402, in _create_attachment
    filename.encode('ascii')
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe9 in position 0: ordinal not in range(128)
}}}"	Bug	closed	Core (Mail)	1.9	Normal	invalid			Unreviewed	0	0	0	0	0	0
