summaryrefslogtreecommitdiffstats
path: root/Lib/smtplib.py
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2011-03-15 19:45:20 (GMT)
committerBenjamin Peterson <benjamin@python.org>2011-03-15 19:45:20 (GMT)
commite97a5b2bda0b1b0352137e564a93e0176b6619e5 (patch)
tree364c998e611d1347d960263d6b539a02fad526cc /Lib/smtplib.py
parentd6afe724cb8a701d6ad2adeb1d8d20e4fde6fca0 (diff)
parentffdbbcaf715323f653388966eec5c42bf6b139c5 (diff)
downloadcpython-e97a5b2bda0b1b0352137e564a93e0176b6619e5.zip
cpython-e97a5b2bda0b1b0352137e564a93e0176b6619e5.tar.gz
cpython-e97a5b2bda0b1b0352137e564a93e0176b6619e5.tar.bz2
merge heads
Diffstat (limited to 'Lib/smtplib.py')
-rwxr-xr-xLib/smtplib.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/Lib/smtplib.py b/Lib/smtplib.py
index 14e6250..213138c 100755
--- a/Lib/smtplib.py
+++ b/Lib/smtplib.py
@@ -269,6 +269,19 @@ class SMTP:
pass
self.local_hostname = '[%s]' % addr
+ def __enter__(self):
+ return self
+
+ def __exit__(self, *args):
+ try:
+ code, message = self.docmd("QUIT")
+ if code != 221:
+ raise SMTPResponseException(code, message)
+ except SMTPServerDisconnected:
+ pass
+ finally:
+ self.close()
+
def set_debuglevel(self, debuglevel):
"""Set the debug output level.