summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSergey Lavrinenko <s.lavrinenko@gmail.com>2016-03-11 22:11:51 (GMT)
committerSergey Lavrinenko <s.lavrinenko@gmail.com>2016-03-11 22:11:51 (GMT)
commit7a071504c0f4136972c5abd5b3f47a7c0816e630 (patch)
treeb45f6c1c5889693a33dbac677cd0ed415a127e16
parentb565bb42d274b559c36fa814db56d2b55a089eb7 (diff)
parentc113421eac26847e53d3213c9921fff24e8bb323 (diff)
downloadpython-emails-7a071504c0f4136972c5abd5b3f47a7c0816e630.zip
python-emails-7a071504c0f4136972c5abd5b3f47a7c0816e630.tar.gz
python-emails-7a071504c0f4136972c5abd5b3f47a7c0816e630.tar.bz2
Merge pull request #61 from lavr/issue-60
More specific error in SMTPBackend.send. Fixes #60
-rw-r--r--.travis.yml1
-rw-r--r--emails/backend/smtp/backend.py19
-rw-r--r--emails/backend/smtp/exceptions.py15
-rw-r--r--emails/testsuite/loader/test_loaders.py1
-rw-r--r--requirements/tests-3.3.txt2
5 files changed, 28 insertions, 10 deletions
diff --git a/.travis.yml b/.travis.yml
index 686b017..54c9c7e 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -7,7 +7,6 @@ python:
- "2.7"
- "3.3"
- "3.4"
- - "pypy"
script: py.test --cov emails
diff --git a/emails/backend/smtp/backend.py b/emails/backend/smtp/backend.py
index 86b7e82..1086c54 100644
--- a/emails/backend/smtp/backend.py
+++ b/emails/backend/smtp/backend.py
@@ -1,14 +1,15 @@
# encoding: utf-8
from __future__ import unicode_literals
-
-__all__ = ['SMTPBackend', ]
-
import smtplib
import logging
from functools import wraps
from ..response import SMTPResponse
from .client import SMTPClientWithResponse, SMTPClientWithResponse_SSL
from ...utils import DNS_NAME
+from .exceptions import SMTPConnectNetworkError
+
+
+__all__ = ['SMTPBackend']
logger = logging.getLogger(__name__)
@@ -85,16 +86,20 @@ class SMTPBackend:
def _send(self, **kwargs):
+ response = None
try:
client = self.get_client()
- except (IOError, smtplib.SMTPException) as exc:
- logger.exception("Error connecting smtp server")
+ except IOError as exc:
+ response = self.make_response(exception=SMTPConnectNetworkError.from_ioerror(exc))
+ except smtplib.SMTPException as exc:
response = self.make_response(exception=exc)
+
+ if response:
if not self.fail_silently:
response.raise_if_needed()
return response
-
- return client.sendmail(**kwargs)
+ else:
+ return client.sendmail(**kwargs)
def sendmail(self, from_addr, to_addrs, msg, mail_options=None, rcpt_options=None):
diff --git a/emails/backend/smtp/exceptions.py b/emails/backend/smtp/exceptions.py
new file mode 100644
index 0000000..fccab18
--- /dev/null
+++ b/emails/backend/smtp/exceptions.py
@@ -0,0 +1,15 @@
+# encoding: utf-8
+from __future__ import unicode_literals
+import socket
+
+
+class SMTPConnectNetworkError(IOError):
+ """Network error during connection establishment."""
+
+ @classmethod
+ def from_ioerror(cls, exc):
+ o = cls()
+ o.errno = exc.errno
+ o.filename = exc.filename
+ o.strerror = exc.strerror
+ return o
diff --git a/emails/testsuite/loader/test_loaders.py b/emails/testsuite/loader/test_loaders.py
index c7de9d6..2069df7 100644
--- a/emails/testsuite/loader/test_loaders.py
+++ b/emails/testsuite/loader/test_loaders.py
@@ -169,7 +169,6 @@ def test_external_urls():
success = 0
for url in [
- 'https://github.com/lavr/python-emails',
'http://yandex.com',
'http://www.smashingmagazine.com/'
]:
diff --git a/requirements/tests-3.3.txt b/requirements/tests-3.3.txt
index b6d69fd..11a7074 100644
--- a/requirements/tests-3.3.txt
+++ b/requirements/tests-3.3.txt
@@ -1,4 +1,4 @@
--requirement=base.txt
--requirement=tests-base.txt
-django \ No newline at end of file
+django<1.9