Tiny SMTP client for Micropython
| .forgejo/workflows | ||
| .typestubs | ||
| examples | ||
| .gitignore | ||
| .mypy.ini | ||
| .pre-commit-config.yaml | ||
| LICENSE | ||
| logo.svg | ||
| micromail.py | ||
| package.json | ||
| README.md | ||
micromail
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, 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.
PLAINandLOGINauthentication methods are currently supported. MicromailClient.write(data: bytearray)- Write
dataof typebytearrayon the server. MicromailClient.send_command(*cmd: bytearray) -> code: bytearray, response: list[bytearray]- Send command to the SMTP server; returns status code and response.
MicromailClient.ehlo() -> res: list[bytearray]- 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: None|str=None)- Create a new email; sender defaults to username.
MicromailClient.headers(headers:dict={})- Define email headers; supported headers are
date(str|datetime, defaults todatetime.now()),from(str, defaults tonew_messagesender),to(str|list[str], defaults tonew_messageto),subject(str). MicromailClient.write_line(content:str|bytearray)- Write message line;
\r\nis appended tocontent. MicromailClient.send()- Send current email.
MicromailClient.quit()- Quit the SMTP server and disconnect from socket.
Functions
format_date(date: datetime)- Return date formatted as email date string.