← All notes

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

Sources

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

Permanent ID: iil:note:wf83z9ws

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.},
}

Markdown

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.

All artifact files (JSON index)

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.