summaryrefslogtreecommitdiff
path: root/Lib/smtplib.py
diff options
context:
space:
mode:
authorR David Murray <rdmurray@bitdance.com>2013-03-20 21:13:56 -0400
committerR David Murray <rdmurray@bitdance.com>2013-03-20 21:13:56 -0400
commit82c6b45c1421c9c7b687f8f8a53faa77d8ebbd55 (patch)
treedac0252ded6237ee87be620571e5c13a60b65f93 /Lib/smtplib.py
parent61683625096676722dc487aa1e9894a5b604e220 (diff)
parentf1a40b4ec5bd25411189e33de1cdabdc6780cd8c (diff)
downloadcpython-git-82c6b45c1421c9c7b687f8f8a53faa77d8ebbd55.tar.gz
Merge: #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.py13
1 files changed, 11 insertions, 2 deletions
diff --git a/Lib/smtplib.py b/Lib/smtplib.py
index 44a144cd8c..69c0186130 100644
--- a/Lib/smtplib.py
+++ b/Lib/smtplib.py
@@ -751,7 +751,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):
@@ -760,13 +763,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