diff options
author | bwarsaw <> | 2003-04-20 04:02:13 +0000 |
---|---|---|
committer | bwarsaw <> | 2003-04-20 04:02:13 +0000 |
commit | 04192d3afe33bcfd72f64bacaab4e70c627268f3 (patch) | |
tree | ed48393d475c6ad099ab27d8f016fd15e788686d /Mailman/Handlers | |
parent | 866b613202dd6b94091c7fec7a58d1878ec0f682 (diff) | |
download | mailman2-04192d3afe33bcfd72f64bacaab4e70c627268f3.tar.gz mailman2-04192d3afe33bcfd72f64bacaab4e70c627268f3.tar.xz mailman2-04192d3afe33bcfd72f64bacaab4e70c627268f3.zip |
Backporting from the trunk.
Diffstat (limited to 'Mailman/Handlers')
-rw-r--r-- | Mailman/Handlers/SMTPDirect.py | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/Mailman/Handlers/SMTPDirect.py b/Mailman/Handlers/SMTPDirect.py index 4724c3a1..acaa77e2 100644 --- a/Mailman/Handlers/SMTPDirect.py +++ b/Mailman/Handlers/SMTPDirect.py @@ -50,7 +50,7 @@ DOT = '.' # Manage a connection to the SMTP server class Connection: def __init__(self): - self.__connect() + self.__conn = None def __connect(self): self.__conn = smtplib.SMTP() @@ -58,26 +58,32 @@ class Connection: self.__numsessions = mm_cfg.SMTP_MAX_SESSIONS_PER_CONNECTION def sendmail(self, envsender, recips, msgtext): + if self.__conn is None: + self.__connect() try: results = self.__conn.sendmail(envsender, recips, msgtext) except smtplib.SMTPException: - # For safety, reconnect - self.__conn.quit() - self.__connect() - # Let exceptions percolate up + # For safety, close this connection. The next send attempt will + # automatically re-open it. Pass the exception on up. + self.quit() raise - # Decrement the session counter, reconnecting if necessary + # This session has been successfully completed. self.__numsessions -= 1 # By testing exactly for equality to 0, we automatically handle the # case for SMTP_MAX_SESSIONS_PER_CONNECTION <= 0 meaning never close # the connection. We won't worry about wraparound <wink>. if self.__numsessions == 0: - self.__conn.quit() - self.__connect() + self.quit() return results def quit(self): - self.__conn.quit() + if self.__conn is None: + return + try: + self.__conn.quit() + except smtplib.SMTPException: + pass + self.__conn = None |