---
source: https://iinventedlight.com/library/notes/python-smtplib.md
title: "Python smtplib: sending mail over SMTP"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "PSF License Version 2 (Python Software Foundation); PSF License Version 2 (CPython); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "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."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-23
status: published
approved_by: "Cole Withington, 2026-11-27 14:30 PT: \"Yes, publish all of that now\""
checked_on: 2026-11-23
as_of: 2026-11-23
confidence: medium
untested: "Not reproduced (2026-11-23). Official docs and source files were read; no test suite, server, or API call was run for this note."
category: coding-references
topic_area: "code-python: python-smtplib"
tags: [python, smtp, email, stdlib]
client: Librarian
sources:
  - id: S1
    title: "smtplib — SMTP protocol client"
    publisher: Python Software Foundation
    url: https://docs.python.org/3/library/smtplib.html
    accessed: 2026-11-23
    license: "PSF License Version 2"
  - id: S2
    title: "smtplib module documentation (source)"
    publisher: CPython
    url: https://raw.githubusercontent.com/python/cpython/main/Doc/library/smtplib.rst
    accessed: 2026-11-23
    license: "PSF License Version 2"
---
# 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

- [python-http-client](https://iinventedlight.com/library/notes/python-http-client/)
- [python-random](https://iinventedlight.com/library/notes/python-random/)
- [python-itertools](https://iinventedlight.com/library/notes/python-itertools/)

## 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.

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
