GitLab is used only for code review, issue tracking and project management. Canonical locations for source code are still https://gitweb.torproject.org/ https://git.torproject.org/ and git-rw.torproject.org.

Commit 3a878213 authored by Cecylia Bocovich's avatar Cecylia Bocovich

Check SMTP error code and remove request from db

This adds an extra check on SMTP errors to see if it's due to a bad
recipient address and then removes the request from the database. This
prevents one bad request from hanging up the processing of other
requests (see https://bugs.torproject.org/34027).
parent 1f208041
......@@ -18,19 +18,13 @@ import configparser
from email.mime.text import MIMEText
from twisted.internet import defer
from twisted.mail.smtp import sendmail
from twisted.mail import smtp
from ...utils.db import SQLite3 as DB
from ...utils.commons import log
from ...utils import strings
class SMTPError(Exception):
"""
Error if we can't send emails.
"""
pass
from email.mime.text import MIMEText
class Sendmail(object):
"""
......@@ -70,7 +64,7 @@ class Sendmail(object):
Errback if we don't/can't send the message.
"""
log.debug("Could not send email.")
raise SMTPError("{}".format(error))
raise error
def sendmail(self, email_addr, subject, body):
"""
......@@ -93,7 +87,7 @@ class Sendmail(object):
log.debug("Calling asynchronous sendmail.")
return sendmail(
return smtp.sendmail(
self.settings.get("sendmail_host"), self.settings.get("sendmail_addr"), email_addr, message,
requireTransportSecurity=True
).addCallback(self.sendmail_callback).addErrback(self.sendmail_errback)
......@@ -217,7 +211,14 @@ class Sendmail(object):
id=id, service="email", date=date
)
except SMTPError as e:
except smtp.SMTPClientError as e:
if e.code == 501: # Bad recipient address syntax
yield self.conn.remove_request(
id=id, service="email", date=date
)
log.info("Error sending email: {}.".format(e))
except Exception as e:
log.info("Error sending email: {}.".format(e))
elif link_requests:
......@@ -270,7 +271,14 @@ class Sendmail(object):
id=id, service="email", date=date
)
except SMTPError as e:
except smtp.SMTPClientError as e:
if e.code == 501: # Bad recipient address syntax
yield self.conn.remove_request(
id=id, service="email", date=date
)
log.info("Error sending email: {}.".format(e))
except Exception as e:
log.info("Error sending email: {}.".format(e))
else:
log.debug("No pending email requests. Keep waiting.")
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment