Tiny SMTP client for Micropython
Find a file
2025-05-19 14:13:13 +02:00
.forgejo/workflows Fix pre-commit installation step in release workflow 2025-05-19 13:42:31 +02:00
.typestubs Add LICENSE file for typestubs, including Apache and MIT licenses 2025-05-19 13:47:29 +02:00
examples Remove newline characters from message content in example scripts 2025-05-17 21:43:27 +02:00
.gitignore Add examples/local.py to .gitignore 2025-05-16 23:18:51 +02:00
.mypy.ini Add type stubs for socket and ssl modules; update MicromailClient to remove type ignores 2025-05-19 13:39:16 +02:00
.pre-commit-config.yaml Initialize micromail project with basic structure and functionality 2025-05-16 23:06:10 +02:00
LICENSE Initial commit 2025-05-16 19:23:27 +02:00
logo.svg Initialize micromail project with basic structure and functionality 2025-05-16 23:06:10 +02:00
micromail.py Set default value for headers parameter in MicromailClient.headers method 2025-05-19 13:57:43 +02:00
package.json Bump package version to 0.1.5 2025-05-19 13:58:24 +02:00
README.md Fix badge links in README.md for consistency and clarity 2025-05-19 14:13:13 +02:00

micromail

Forgejo Actions Release

Tiny SMTP client for Micropython. See examples for usage.

Inspired from shawwwn/uMail.

Installation

Manual

Copy the micromail.py file to your device. You will need to install the datetime library as well.

MIP

>>> import mip
>>> mip.install("https://code.edgarpierre.fr/edpibu/micromail/releases/download/latest/")

Documentation

Class MicromailClient

  • class micromail.MicromailClient(host: str, port: int = 0, ssl: bool = False, starttls: bool = False)

    Create a new SMTP client.

  • MicromailClient.connect()

    Establish a connection to the SMTP server. The connection is kept alive until MicromailClient.quit() is called.

  • MicromailClient.login(username: str, password: str)

    Login to the SMTP server with the provided username and password. PLAIN and LOGIN authentication methods are currently supported.

  • MicromailClient.write(data: str | bytes)

    Write data of type bytearray on the server.

  • MicromailClient.send_command(*cmd: str | bytes, code: int | list[int] = []) -> tuple[int, list[str]]

    Send command to the SMTP server; returns status code and list of response lines.

  • MicromailClient.read_res(cmd: str = "", code: int | list[int] = []) -> tuple[int, list[str]]

    Read response from the SMTP server; returns status code and list of response lines.

  • MicromailClient.ehlo() -> list[str]

    Send SMTP EHLO command to the server and return response.

  • MicromailClient.starttls()

    Send SMTP STARTTLS command and enable SSL on socket.

  • MicromailClient.new_message(to: str | list[str], sender: str | None = None)

    Create a new email; sender defaults to username.

  • MicromailClient.headers(headers: dict[str, str])

    Define email headers; supported headers are date (str, defaults to current date), from (defaults to new_message sender), to (defaults to new_message to), subject (str).

  • MicromailClient.write_line(content: str)

    Write message line; \r\n is appended to content.

  • MicromailClient.send()

    Send current email.

  • MicromailClient.quit()

    Quit the SMTP server and disconnect from socket.

Functions

  • format_date(date: datetime) -> str

    Return date formatted as email date string.

Exceptions

  • Error

    Standard module error.

  • NoSocketError

    Raised when an operation on the socket is asked but the client is not connected to any socket.

  • SMTPError(cmd: str, code: int, message: str)

    Raised when an unexpected SMTP response code is received.