summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJosé Padilla <jpadilla@webapplicate.com>2014-09-12 22:46:22 -0400
committerTim Graham <timograham@gmail.com>2014-09-13 09:33:21 -0400
commit5472d18e3193050f5b9a25b71852ca7b77f852a5 (patch)
treeb65e10a3ab0c5ee90fe0a5989050cbb21672c437
parent0ae79014c09f4ddd2575f53371d994773d0bd43c (diff)
Fixed #23461 -- Added EMAIL_TIMEOUT setting
-rw-r--r--django/conf/global_settings.py1
-rw-r--r--django/core/mail/backends/smtp.py2
-rw-r--r--docs/ref/settings.txt13
-rw-r--r--docs/releases/1.8.txt3
-rw-r--r--docs/topics/email.txt36
-rw-r--r--tests/mail/tests.py5
6 files changed, 34 insertions, 26 deletions
diff --git a/django/conf/global_settings.py b/django/conf/global_settings.py
index 186d77f314..5fd9029325 100644
--- a/django/conf/global_settings.py
+++ b/django/conf/global_settings.py
@@ -196,6 +196,7 @@ EMAIL_USE_TLS = False
EMAIL_USE_SSL = False
EMAIL_SSL_CERTFILE = None
EMAIL_SSL_KEYFILE = None
+EMAIL_TIMEOUT = None
# List of strings representing installed apps.
INSTALLED_APPS = ()
diff --git a/django/core/mail/backends/smtp.py b/django/core/mail/backends/smtp.py
index b3b23027f1..4c41eb8bd6 100644
--- a/django/core/mail/backends/smtp.py
+++ b/django/core/mail/backends/smtp.py
@@ -24,7 +24,7 @@ class EmailBackend(BaseEmailBackend):
self.password = settings.EMAIL_HOST_PASSWORD if password is None else password
self.use_tls = settings.EMAIL_USE_TLS if use_tls is None else use_tls
self.use_ssl = settings.EMAIL_USE_SSL if use_ssl is None else use_ssl
- self.timeout = timeout
+ self.timeout = settings.EMAIL_TIMEOUT if timeout is None else timeout
self.ssl_keyfile = settings.EMAIL_SSL_KEYFILE if ssl_keyfile is None else ssl_keyfile
self.ssl_certfile = settings.EMAIL_SSL_CERTFILE if ssl_certfile is None else ssl_certfile
if self.use_ssl and self.use_tls:
diff --git a/docs/ref/settings.txt b/docs/ref/settings.txt
index 507f3f11c9..c1d094b629 100644
--- a/docs/ref/settings.txt
+++ b/docs/ref/settings.txt
@@ -1266,6 +1266,18 @@ connection. Please refer to the documentation of Python's
:func:`python:ssl.wrap_socket` function for details on how the certificate chain
file and private key file are handled.
+.. setting:: EMAIL_TIMEOUT
+
+EMAIL_TIMEOUT
+-------------
+
+.. versionadded:: 1.8
+
+Default: ``None``
+
+Specifies a timeout in seconds for blocking operations like the connection
+attempt.
+
.. setting:: FILE_CHARSET
FILE_CHARSET
@@ -3089,6 +3101,7 @@ Email
* :setting:`EMAIL_SSL_CERTFILE`
* :setting:`EMAIL_SSL_KEYFILE`
* :setting:`EMAIL_SUBJECT_PREFIX`
+* :setting*`EMAIL_TIMEOUT`
* :setting:`EMAIL_USE_TLS`
* :setting:`MANAGERS`
* :setting:`SERVER_EMAIL`
diff --git a/docs/releases/1.8.txt b/docs/releases/1.8.txt
index 41d029a9ca..a904f0fd13 100644
--- a/docs/releases/1.8.txt
+++ b/docs/releases/1.8.txt
@@ -154,6 +154,9 @@ Email
authentication with the :setting:`EMAIL_SSL_CERTFILE` and
:setting:`EMAIL_SSL_KEYFILE` settings.
+* The SMTP :class:`~django.core.mail.backends.smtp.EmailBackend` now supports
+ setting the ``timeout`` parameter with the :setting:`EMAIL_TIMEOUT` setting.
+
File Storage
^^^^^^^^^^^^
diff --git a/docs/topics/email.txt b/docs/topics/email.txt
index a7a9329974..7303a6fe6f 100644
--- a/docs/topics/email.txt
+++ b/docs/topics/email.txt
@@ -451,41 +451,27 @@ SMTP backend
The server address and authentication credentials are set in the
:setting:`EMAIL_HOST`, :setting:`EMAIL_PORT`, :setting:`EMAIL_HOST_USER`,
:setting:`EMAIL_HOST_PASSWORD`, :setting:`EMAIL_USE_TLS`,
- :setting:`EMAIL_USE_SSL`, :setting:`EMAIL_SSL_CERTFILE` and
- :setting:`EMAIL_SSL_KEYFILE` settings in your settings file.
+ :setting:`EMAIL_USE_SSL`, :setting:`EMAIL_TIMEOUT`,
+ :setting:`EMAIL_SSL_CERTFILE` and :setting:`EMAIL_SSL_KEYFILE` settings
+ in your settings file.
The SMTP backend is the default configuration inherited by Django. If you
want to specify it explicitly, put the following in your settings::
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
- Here is an attribute which doesn't have a corresponding setting like the
- others described above:
+ .. versionadded:: 1.7
- .. attribute:: timeout
-
- .. versionadded:: 1.7
-
- This backend contains a ``timeout`` parameter, which can be set with
- the following sample code::
-
- from django.core.mail.backends import smtp
-
- class MyEmailBackend(smtp.EmailBackend):
- def __init__(self, *args, **kwargs):
- kwargs.setdefault('timeout', 42)
- super(MyEmailBackend, self).__init__(*args, **kwargs)
-
- Then point the :setting:`EMAIL_BACKEND` setting at your custom backend as
- described above.
-
- If unspecified, the default ``timeout`` will be the one provided by
- :func:`socket.getdefaulttimeout()`, which defaults to ``None`` (no timeout).
+ The ``timeout`` parameter was added. If unspecified, the default
+ ``timeout`` will be the one provided by
+ :func:`socket.getdefaulttimeout()`, which defaults to ``None`` (no
+ timeout).
.. versionchanged:: 1.8
- The ``ssl_keyfile`` and ``ssl_certfile`` parameters and
- corresponding settings were added.
+ The ``ssl_keyfile``, and ``ssl_certfile`` parameters and corresponding
+ settings were added. The ability to customize ``timeout`` using
+ a setting (:setting:`EMAIL_TIMEOUT`) was added.
.. _topic-email-console-backend:
diff --git a/tests/mail/tests.py b/tests/mail/tests.py
index cc5e3d8197..df6daee5c8 100644
--- a/tests/mail/tests.py
+++ b/tests/mail/tests.py
@@ -1033,3 +1033,8 @@ class SMTPBackendTests(BaseEmailBackendTests, SimpleTestCase):
self.assertEqual(myemailbackend.timeout, 42)
self.assertEqual(myemailbackend.connection.timeout, 42)
myemailbackend.close()
+
+ @override_settings(EMAIL_TIMEOUT=10)
+ def test_email_timeout_override_settings(self):
+ backend = smtp.EmailBackend()
+ self.assertEqual(backend.timeout, 10)