diff options
| author | Brett Cannon <brett@python.org> | 2011-03-15 20:03:32 (GMT) |
|---|---|---|
| committer | Brett Cannon <brett@python.org> | 2011-03-15 20:03:32 (GMT) |
| commit | 71f1363c349c6ccab38870d328cee4de9081c8f9 (patch) | |
| tree | f06eaefd5911d935c366b3f5179735648aebee1a /Lib/smtplib.py | |
| parent | b880c1558e8562351e75837e1ba2932ae5d17111 (diff) | |
| parent | c15799f88a8add3c40bee7692b525d8a9182e491 (diff) | |
| download | cpython-71f1363c349c6ccab38870d328cee4de9081c8f9.zip cpython-71f1363c349c6ccab38870d328cee4de9081c8f9.tar.gz cpython-71f1363c349c6ccab38870d328cee4de9081c8f9.tar.bz2 | |
merge
Diffstat (limited to 'Lib/smtplib.py')
| -rwxr-xr-x | Lib/smtplib.py | 13 |
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. |
