Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ python:
- "2.7"
- "3.3"
- "3.4"
- "pypy"

script: py.test --cov emails

Expand Down
19 changes: 12 additions & 7 deletions emails/backend/smtp/backend.py
Original file line number Diff line number Diff line change
@@ -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__)

Expand Down Expand Up @@ -85,16 +86,20 @@ def wrapper(*args, **kwargs):

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):

Expand Down
15 changes: 15 additions & 0 deletions emails/backend/smtp/exceptions.py
Original file line number Diff line number Diff line change
@@ -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
1 change: 0 additions & 1 deletion emails/testsuite/loader/test_loaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -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/'
]:
Expand Down
2 changes: 1 addition & 1 deletion requirements/tests-3.3.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
--requirement=base.txt
--requirement=tests-base.txt

django
django<1.9