Python smtplib: sending mail over SMTP
Answer: smtplib defines an SMTP client session object that can send mail to a machine running an SMTP or ESMTP listener daemon. If the host parameter is set to a true value, connect is called when the object is created.
What the client does
The client session object sends mail to an internet machine that runs an SMTP or ESMTP listener daemon.
For protocol details, the docs point to RFC 821 and RFC 1869.
An SMTP instance encapsulates an SMTP connection and exposes methods for a full repertoire of SMTP and ESMTP operations.
Connecting
When the host parameter is set to a true value, connect is called with host and port automatically at creation time.
Otherwise connect must be called manually.
A timeout parameter, in seconds, can bound blocking operations such as the connection attempt.
See also
Claims
- id: C1 claim: smtplib defines an SMTP client session object used to send mail. source: S1 evidence: "defines an SMTP client session object that can be used to send mail"
- id: C2 claim: It can talk to a machine with an SMTP or ESMTP listener daemon. source: S1 evidence: "SMTP or ESMTP listener daemon"
- id: C3 claim: RFC 821 and RFC 1869 describe SMTP and ESMTP operation. source: S1 evidence: "RFC 821"
- id: C4 claim: If host is set, connect is called when the object is created. source: S2 evidence: "is called with host and port automatically when the object is created"
Sources
- [S1] smtplib — SMTP protocol client. Python Software Foundation. https://docs.python.org/3/library/smtplib.html . License: PSF License Version 2. Accessed 2026-11-23.
- [S2] smtplib module documentation (source). CPython. https://raw.githubusercontent.com/python/cpython/main/Doc/library/smtplib.rst . License: PSF License Version 2. Accessed 2026-11-23.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Python Software Foundation, smtplib — SMTP protocol client; CPython, smtplib module documentation (source). PSF-2.0 (https://docs.python.org/3/license.html). Copyright Python Software Foundation. Text was condensed and changed from the originals.
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Python Software Foundation, smtplib — SMTP protocol client; CPython, smtplib module documentation (source). PSF-2.0 (https://docs.python.org/3/license.html). Copyright Python Software Foundation.
Cite this
iinventedlight. 2026. "Python smtplib: sending mail over SMTP." iinventedlight Library, iil:note:wf83z9ws, version of 2026-11-23. https://iinventedlight.com/library/notes/python-smtplib/. License: CC-BY-4.0.
@misc{iil_note_wf83z9ws,
author = {{iinventedlight}},
title = {{Python smtplib: sending mail over SMTP}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-23},
url = {https://iinventedlight.com/library/notes/python-smtplib/},
note = {Permanent ID iil:note:wf83z9ws. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).
Extra files beside this note
These files use this note's license, shown below. Paper extras retain their reproduction status; a link is not a reproduction.
- python-smtplib.schema.json (schema; CC-BY-4.0)
- python-smtplib.table.json (table; CC-BY-4.0)
For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/python-smtplib.md.