Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @contextmanager
- def smtp_connection(host, user=None, passwd=None, timeout=5):
- conn = None # smell here
- try:
- conn = SMTP(host=host, timeout=timeout)
- conn.ehlo_or_helo_if_needed()
- if user and passwd:
- conn.login(user=user, password=passwd)
- logger.debug('SMTP connected')
- yield conn
- except Exception as e:
- raise e
- finally:
- if conn: # and here
- conn.quit()
- with ExitStack() as stack:
- stack.callback(cleanup_resources)
- result = perform_operation()
- if result:
- stack.pop_all()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement