diff --git a/django/core/mail/backends/smtp.py b/django/core/mail/backends/smtp.py
index 63efe43..b2370fc 100644
a
|
b
|
class EmailBackend(BaseEmailBackend):
|
95 | 95 | """A helper method that does the actual sending.""" |
96 | 96 | if not email_message.recipients(): |
97 | 97 | return False |
| 98 | from_email = _sanitize(email_message.from_email) |
| 99 | recipients = map(_sanitize, email_message.recipients()) |
98 | 100 | try: |
99 | | self.connection.sendmail(email_message.from_email, |
100 | | email_message.recipients(), |
| 101 | self.connection.sendmail(from_email, recipients, |
101 | 102 | email_message.message().as_string()) |
102 | 103 | except: |
103 | 104 | if not self.fail_silently: |
104 | 105 | raise |
105 | 106 | return False |
106 | 107 | return True |
| 108 | |
| 109 | def _sanitize(email): |
| 110 | name, domain = email.split('@', 1) |
| 111 | email = '@'.join([name, domain.encode('idna')]) |
| 112 | return email |
| 113 | |
diff --git a/tests/regressiontests/mail/tests.py b/tests/regressiontests/mail/tests.py
index a84417e..ec0e3be 100644
a
|
b
|
class MailTests(TestCase):
|
378 | 378 | self.assertEqual(message.from_email, from_email) |
379 | 379 | self.assertEqual(message.to, [to_email]) |
380 | 380 | self.assertTrue(message.message().as_string().startswith('Content-Type: text/plain; charset="utf-8"\nMIME-Version: 1.0\nContent-Transfer-Encoding: quoted-printable\nSubject: Subject\nFrom: =?utf-8?b?ZnLDtm1Aw7bDpMO8LmNvbQ==?=\nTo: =?utf-8?b?dMO2QMO2w6TDvC5jb20=?=')) |
| 381 | |
| 382 | def test_idn_smtp_send(self): |
| 383 | import smtplib |
| 384 | smtplib.SMTP = MockSMTP |
| 385 | from_email = u'fröm@öäü.com' |
| 386 | to_email = u'tö@öäü.com' |
| 387 | connection = mail.get_connection('django.core.mail.backends.smtp.EmailBackend') |
| 388 | self.assertTrue(send_mail('Subject', 'Content', from_email, [to_email], connection=connection)) |
| 389 | |
| 390 | class MockSMTP(object): |
| 391 | def __init__(self, host='', port=0, local_hostname=None, |
| 392 | timeout=1): |
| 393 | pass |
| 394 | |
| 395 | def sendmail(self, from_addr, to_addrs, msg, mail_options=[], |
| 396 | rcpt_options=[]): |
| 397 | for addr in to_addrs: |
| 398 | str(addr.split('@', 1)[-1]) |
| 399 | return {} |
| 400 | |
| 401 | def quit(self): |
| 402 | return 0 |