[Django] #27131: send_mail error if smtp server uses CRAM-MD5 auth method

90 views
Skip to first unread message

Django

unread,
Aug 26, 2016, 6:19:38 PM8/26/16
to django-...@googlegroups.com
#27131: send_mail error if smtp server uses CRAM-MD5 auth method
-------------------------------+-----------------------
Reporter: slavugan | Owner: nobody
Type: Uncategorized | Status: new
Component: Core (Mail) | Version: 1.8
Severity: Normal | Keywords: send_mail
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+-----------------------
{{{
send_mail('title', 'message', from_email='te...@mail.com',
recipient_list=['te...@mail.com'])
Traceback (most recent call last):
File "<input>", line 1, in <module>
send_mail('hello slafffko', 'message is here',
from_email='te...@artel7.com',
recipient_list=['slav...@gmail.com'])
File "/home/slav/venv/luxjango/local/lib/python2.7/site-
packages/django/core/m
ail/__init__.py", line 62, in send_mail
return mail.send()
File "/home/slav/venv/luxjango/local/lib/python2.7/site-
packages/django/core/m
ail/message.py", line 303, in send
return self.get_connection(fail_silently).send_messages([self])
File "/home/slav/venv/luxjango/local/lib/python2.7/site-
packages/django/core/m
ail/backends/smtp.py", line 100, in send_messages
new_conn_created = self.open()
File "/home/slav/venv/luxjango/local/lib/python2.7/site-
packages/django/core/m
ail/backends/smtp.py", line 67, in open
self.connection.login(self.username, self.password)
File "/usr/lib/python2.7/smtplib.py", line 607, in login
(code, resp) = self.docmd(encode_cram_md5(resp, user, password))
File "/usr/lib/python2.7/smtplib.py", line 571, in encode_cram_md5
response = user + " " + hmac.HMAC(password, challenge).hexdigest()
File "/usr/lib/python2.7/hmac.py", line 75, in __init__
self.outer.update(key.translate(trans_5C))
TypeError: character mapping must return integer, None or unicode
}}}

email backend should pass passwrord as string, not as unicode to smtplib
to avoid this error

--
Ticket URL: <https://code.djangoproject.com/ticket/27131>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Aug 26, 2016, 6:41:59 PM8/26/16
to django-...@googlegroups.com
#27131: send_mail error if smtp server uses CRAM-MD5 auth method
-------------------------------+--------------------------------------

Reporter: slavugan | Owner: nobody
Type: Uncategorized | Status: new
Component: Core (Mail) | Version: 1.8
Severity: Normal | Resolution:

Keywords: send_mail | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------
Changes (by timgraham):

* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0


Comment:

I have no way to reproduce this -- can you submit a patch with a test?

--
Ticket URL: <https://code.djangoproject.com/ticket/27131#comment:1>

Django

unread,
Aug 27, 2016, 4:10:57 AM8/27/16
to django-...@googlegroups.com
#27131: send_mail error if smtp server uses CRAM-MD5 auth method
-------------------------------+--------------------------------------

Reporter: slavugan | Owner: nobody
Type: Uncategorized | Status: new
Component: Core (Mail) | Version: 1.8
Severity: Normal | Resolution:

Keywords: send_mail | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------

Comment (by claudep):

Would it be possible to test with Python 3?

--
Ticket URL: <https://code.djangoproject.com/ticket/27131#comment:2>

Django

unread,
Aug 27, 2016, 3:10:49 PM8/27/16
to django-...@googlegroups.com
#27131: send_mail error if smtp server uses CRAM-MD5 auth method
-------------------------------+--------------------------------------

Reporter: slavugan | Owner: nobody
Type: Uncategorized | Status: new
Component: Core (Mail) | Version: 1.8
Severity: Normal | Resolution:

Keywords: send_mail | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------

Comment (by claudep):

FYI, I'm currently working on a test for this in the Django test suite.

--
Ticket URL: <https://code.djangoproject.com/ticket/27131#comment:3>

Django

unread,
Aug 27, 2016, 5:19:28 PM8/27/16
to django-...@googlegroups.com
#27131: send_mail error if smtp server uses CRAM-MD5 auth method
-------------------------------+--------------------------------------

Reporter: slavugan | Owner: nobody
Type: Uncategorized | Status: new
Component: Core (Mail) | Version: 1.8
Severity: Normal | Resolution:

Keywords: send_mail | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------

Comment (by slavugan):

I have checked for python3 everything is ok, because of with python3
Django passes password as string to smtplib, so this error is relevant
only for python2.
For fix in __init__ in django/core/mail/backends/smtp.py we should add
something like this:
{{{
if self.password.__class__.__name__ == 'unicode':
try:
self.password = str(self.password)
except UnicodeEncodeError:
pass
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/27131#comment:4>

Django

unread,
Aug 29, 2016, 8:45:11 AM8/29/16
to django-...@googlegroups.com
#27131: send_mail error if smtp server uses CRAM-MD5 auth method
-----------------------------+------------------------------------
Reporter: slavugan | Owner: nobody
Type: Bug | Status: new
Component: Core (Mail) | Version: master
Severity: Normal | Resolution:
Keywords: send_mail | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-----------------------------+------------------------------------
Changes (by claudep):

* has_patch: 0 => 1
* version: 1.8 => master
* type: Uncategorized => Bug
* stage: Unreviewed => Accepted


Comment:

[https://github.com/django/django/pull/7178 PR]

--
Ticket URL: <https://code.djangoproject.com/ticket/27131#comment:5>

Django

unread,
Aug 30, 2016, 9:55:31 AM8/30/16
to django-...@googlegroups.com
#27131: send_mail() error on Python 2 if smtp server uses CRAM-MD5 auth method
-----------------------------+---------------------------------------------
Reporter: slavugan | Owner: nobody

Type: Bug | Status: new
Component: Core (Mail) | Version: master
Severity: Normal | Resolution:
Keywords: send_mail | Triage Stage: Ready for checkin

Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-----------------------------+---------------------------------------------
Changes (by timgraham):

* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/27131#comment:6>

Django

unread,
Aug 31, 2016, 3:02:04 AM8/31/16
to django-...@googlegroups.com
#27131: send_mail() error on Python 2 if smtp server uses CRAM-MD5 auth method
-----------------------------+---------------------------------------------
Reporter: slavugan | Owner: nobody
Type: Bug | Status: closed

Component: Core (Mail) | Version: master
Severity: Normal | Resolution: fixed

Keywords: send_mail | Triage Stage: Ready for checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-----------------------------+---------------------------------------------
Changes (by Claude Paroz <claude@…>):

* status: new => closed
* resolution: => fixed


Comment:

In [changeset:"fe252c0a5a2ceb5c97aafc16a42dbe5ad03ef1e9" fe252c0a]:
{{{
#!CommitTicketReference repository=""
revision="fe252c0a5a2ceb5c97aafc16a42dbe5ad03ef1e9"
Fixed #27131 -- Passed proper string type to SMTP connection login

Passing an Unicode string on Python 2 was crashing the connection.
Thanks slav...@gmail.com for the report, and Tim Graham for the review.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/27131#comment:7>

Django

unread,
Aug 31, 2016, 6:18:17 AM8/31/16
to django-...@googlegroups.com
#27131: send_mail() error on Python 2 if smtp server uses CRAM-MD5 auth method
-----------------------------+---------------------------------------------
Reporter: slavugan | Owner: nobody

Type: Bug | Status: closed
Component: Core (Mail) | Version: master
Severity: Normal | Resolution: fixed
Keywords: send_mail | Triage Stage: Ready for checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-----------------------------+---------------------------------------------

Comment (by claudep):

As suggested by Tim on the pull request, a workaround on older Django
could be to define email username and pasword as bytestrings.

--
Ticket URL: <https://code.djangoproject.com/ticket/27131#comment:8>

Django

unread,
Oct 14, 2021, 5:37:33 AM10/14/21
to django-...@googlegroups.com
#27131: send_mail() error on Python 2 if smtp server uses CRAM-MD5 auth method
-----------------------------+---------------------------------------------
Reporter: Slava | Owner: nobody
Type: Bug | Status: closed
Component: Core (Mail) | Version: dev

Severity: Normal | Resolution: fixed
Keywords: send_mail | Triage Stage: Ready for checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-----------------------------+---------------------------------------------

Comment (by GitHub <noreply@…>):

In [changeset:"cdad96e6330cd31185f7496aaf8eb316f2773d6d" cdad96e6]:
{{{
#!CommitTicketReference repository=""
revision="cdad96e6330cd31185f7496aaf8eb316f2773d6d"
Refs #27131 -- Removed SMTPBackendTests.test_server_login().

test_server_login() was a regression test for a crash when passing
Unicode strings to SMTP server using CRAM-MD5 method on Python 2.
Python 2 is no longer supported and test_server_login() passes even
without FakeSMTPChannel.smtp_AUTH() because
smtplib.SMTPAuthenticationError is raised when AUTH is not implemented.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/27131#comment:9>

Django

unread,
Oct 14, 2021, 5:38:25 AM10/14/21
to django-...@googlegroups.com
#27131: send_mail() error on Python 2 if smtp server uses CRAM-MD5 auth method
-----------------------------+---------------------------------------------
Reporter: Slava | Owner: nobody
Type: Bug | Status: closed
Component: Core (Mail) | Version: dev
Severity: Normal | Resolution: fixed
Keywords: send_mail | Triage Stage: Ready for checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-----------------------------+---------------------------------------------

Comment (by Mariusz Felisiak <felisiak.mariusz@…>):

In [changeset:"8ab95364b5182fd702478289f98b01d16a21016e" 8ab9536]:
{{{
#!CommitTicketReference repository=""
revision="8ab95364b5182fd702478289f98b01d16a21016e"
[4.0.x] Refs #27131 -- Removed SMTPBackendTests.test_server_login().

test_server_login() was a regression test for a crash when passing
Unicode strings to SMTP server using CRAM-MD5 method on Python 2.
Python 2 is no longer supported and test_server_login() passes even
without FakeSMTPChannel.smtp_AUTH() because
smtplib.SMTPAuthenticationError is raised when AUTH is not implemented.

Backport of cdad96e6330cd31185f7496aaf8eb316f2773d6d from main
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/27131#comment:10>

Django

unread,
Oct 14, 2021, 5:39:08 AM10/14/21
to django-...@googlegroups.com
#27131: send_mail() error on Python 2 if smtp server uses CRAM-MD5 auth method
-----------------------------+---------------------------------------------
Reporter: Slava | Owner: nobody
Type: Bug | Status: closed
Component: Core (Mail) | Version: dev
Severity: Normal | Resolution: fixed
Keywords: send_mail | Triage Stage: Ready for checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-----------------------------+---------------------------------------------

Comment (by Mariusz Felisiak <felisiak.mariusz@…>):

In [changeset:"137a9899d7965432fc24cf6fc0331e333316a1dd" 137a9899]:
{{{
#!CommitTicketReference repository=""
revision="137a9899d7965432fc24cf6fc0331e333316a1dd"
[3.2.x] Refs #27131 -- Removed SMTPBackendTests.test_server_login().

test_server_login() was a regression test for a crash when passing
Unicode strings to SMTP server using CRAM-MD5 method on Python 2.
Python 2 is no longer supported and test_server_login() passes even
without FakeSMTPChannel.smtp_AUTH() because
smtplib.SMTPAuthenticationError is raised when AUTH is not implemented.
Backport of cdad96e6330cd31185f7496aaf8eb316f2773d6d from main
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/27131#comment:11>

Reply all
Reply to author
Forward
0 new messages