Code

Ticket #9488: plain_auth.diff

File plain_auth.diff, 2.2 KB (added by jdemoor, 5 years ago)
Line 
1Index: django/core/mail.py
2===================================================================
3--- ../django/core/mail.py      (revision 8961)
4+++ ../django/core/mail.py      (working copy)
5@@ -134,7 +134,17 @@
6                 self.connection.starttls()
7                 self.connection.ehlo()
8             if self.username and self.password:
9-                self.connection.login(self.username, self.password)
10+                if settings.EMAIL_FORCE_PLAIN_AUTH:
11+                    # Force plain auth: call ehlo() or helo() first to get the
12+                    # server's supported methods; then overwrite the results
13+                    if not (200 <= self.connection.ehlo()[0] <= 299):
14+                        (code, resp) = self.connection.helo()
15+                        if not (200 <= code <= 299):
16+                            raise SMTPHeloError(code, resp)
17+                    self.connection.esmtp_features["auth"] = "LOGIN PLAIN"
18+                    self.connection.login(self.username, self.password)
19+                else:
20+                    self.connection.login(self.username, self.password)
21             return True
22         except:
23             if not self.fail_silently:
24Index: django/conf/global_settings.py
25===================================================================
26--- django/conf/global_settings.py      (revision 8961)
27+++ django/conf/global_settings.py      (working copy)
28@@ -139,6 +139,7 @@
29 EMAIL_HOST_USER = ''
30 EMAIL_HOST_PASSWORD = ''
31 EMAIL_USE_TLS = False
32+EMAIL_FORCE_PLAIN_AUTH = False
33 
34 # List of strings representing installed apps.
35 INSTALLED_APPS = ()
36Index: docs/ref/settings.txt
37===================================================================
38--- docs/ref/settings.txt       (revision 8961)
39+++ docs/ref/settings.txt       (working copy)
40@@ -373,6 +373,18 @@
41 This is only used if ``CommonMiddleware`` is installed (see
42 :ref:`topics-http-middleware`).
43 
44+.. setting:: EMAIL_FORCE_PLAIN_AUTH
45+
46+EMAIL_FORCE_PLAIN_AUTH
47+----------------------
48+
49+Default: ``False``
50+
51+Force the transmission of the SMTP password (if any) in plain text. This can be
52+useful with certain SMTP servers which falsely claim to support CRAM-MD5.
53+
54+See also ``EMAIL_HOST_USER`` and ``EMAIL_HOST_PASSWORD``.
55+
56 .. setting:: EMAIL_HOST
57 
58 EMAIL_HOST