diff options
author | R David Murray <rdmurray@bitdance.com> | 2013-03-21 00:36:14 (GMT) |
---|---|---|
committer | R David Murray <rdmurray@bitdance.com> | 2013-03-21 00:36:14 (GMT) |
commit | d312c740f15b2ee8ba242fb779884f7e19b28a7e (patch) | |
tree | 1f5ed34172138c7e5a916e6b964e0bda5b16821c /Lib/smtplib.py | |
parent | 958f7ae8651bb6347a0401fe9db7d0a219daf156 (diff) | |
download | cpython-d312c740f15b2ee8ba242fb779884f7e19b28a7e.zip cpython-d312c740f15b2ee8ba242fb779884f7e19b28a7e.tar.gz cpython-d312c740f15b2ee8ba242fb779884f7e19b28a7e.tar.bz2 |
#5713: Handle 421 error codes during sendmail by closing the socket.
This is a partial fix to the issue of servers disconnecting unexpectedly; in
this case the 421 says they are disconnecting, so we close the socket and
return the 421 in the appropriate error context.
Original patch by Mark Sapiro, updated by Kushal Das, with additional
tests by me.
Diffstat (limited to 'Lib/smtplib.py')
-rw-r--r-- | Lib/smtplib.py | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/Lib/smtplib.py b/Lib/smtplib.py index e06a9be..679e478 100644 --- a/Lib/smtplib.py +++ b/Lib/smtplib.py @@ -742,7 +742,10 @@ class SMTP: esmtp_opts.append(option) (code, resp) = self.mail(from_addr, esmtp_opts) if code != 250: - self.rset() + if code == 421: + self.close() + else: + self.rset() raise SMTPSenderRefused(code, resp, from_addr) senderrs = {} if isinstance(to_addrs, str): @@ -751,13 +754,19 @@ class SMTP: (code, resp) = self.rcpt(each, rcpt_options) if (code != 250) and (code != 251): senderrs[each] = (code, resp) + if code == 421: + self.close() + raise SMTPRecipientsRefused(senderrs) if len(senderrs) == len(to_addrs): # the server refused all our recipients self.rset() raise SMTPRecipientsRefused(senderrs) (code, resp) = self.data(msg) if code != 250: - self.rset() + if code == 421: + self.close() + else: + self.rset() raise SMTPDataError(code, resp) #if we got here then somebody got our mail return senderrs |