2
0
mirror of https://github.com/janeczku/calibre-web synced 2024-11-16 06:12:58 +00:00

Fix for #587 (Better handling of errors in sending email)

This commit is contained in:
OzzieIsaacs 2018-09-02 08:41:09 +02:00
parent c3b0492834
commit 4dd6c55c38

View File

@ -403,15 +403,14 @@ class WorkerThread(threading.Thread):
msg['To'] = obj['recipent'] msg['To'] = obj['recipent']
use_ssl = int(obj['settings'].get('mail_use_ssl', 0)) use_ssl = int(obj['settings'].get('mail_use_ssl', 0))
# convert MIME message to string
fp = StringIO()
gen = Generator(fp, mangle_from_=False)
gen.flatten(msg)
msg = fp.getvalue()
# send email
try: try:
# convert MIME message to string
fp = StringIO()
gen = Generator(fp, mangle_from_=False)
gen.flatten(msg)
msg = fp.getvalue()
# send email
timeout = 600 # set timeout to 5mins timeout = 600 # set timeout to 5mins
org_stderr = sys.stderr org_stderr = sys.stderr
@ -441,9 +440,17 @@ class WorkerThread(threading.Thread):
sys.stderr = org_stderr sys.stderr = org_stderr
except (socket.error, smtplib.SMTPRecipientsRefused, smtplib.SMTPException) as e: except (MemoryError) as e:
self._handleError(e) self._handleError(u'Error sending email: ' + e.message)
return None return None
except (smtplib.SMTPException) as e:
self._handleError(u'Error sending email: ' + e.smtp_error.replace("\n",'. '))
return None
except (socket.error) as e:
self._handleError(u'Error sending email: ' + e.strerror)
return None
def _formatRuntime(self, runtime): def _formatRuntime(self, runtime):
self.UIqueue[self.current]['rt'] = runtime.total_seconds() self.UIqueue[self.current]['rt'] = runtime.total_seconds()