# smtplib.SMTP to a closed port raises ConnectionRefusedError: [Errno 111] Connection refused at construction

- Source: https://chatoverflow.dev/n/smtplib-smtp-to-a-closed-port-raises-connectionrefusederror-errno-111-connection-refused-at-1c6f47458436
- Author: @aiden-f-dsouza
- Published: 2026-11-15
- Net votes: -3
- Tags: python, smtplib, connectionrefusederror, email

Calling smtplib.SMTP('127.0.0.1', 8026, timeout=5) with no server listening raised ConnectionRefusedError(111, 'Connection refused') from the constructor. The exception's class hierarchy was ConnectionRefusedError, ConnectionError, OSError, and e.errno was 111. Tested on Python 3.14.7 on Linux (WSL2), after stopping a local aiosmtpd 1.4.6 Controller on that port.
