summaryrefslogtreecommitdiffstats
path: root/Lib/smtplib.py
diff options
context:
space:
mode:
authorBrett Cannon <brett@python.org>2011-03-15 20:03:32 (GMT)
committerBrett Cannon <brett@python.org>2011-03-15 20:03:32 (GMT)
commit71f1363c349c6ccab38870d328cee4de9081c8f9 (patch)
treef06eaefd5911d935c366b3f5179735648aebee1a /Lib/smtplib.py
parentb880c1558e8562351e75837e1ba2932ae5d17111 (diff)
parentc15799f88a8add3c40bee7692b525d8a9182e491 (diff)
downloadcpython-71f1363c349c6ccab38870d328cee4de9081c8f9.zip
cpython-71f1363c349c6ccab38870d328cee4de9081c8f9.tar.gz
cpython-71f1363c349c6ccab38870d328cee4de9081c8f9.tar.bz2
merge
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.