Update README and example.py for clarity and consistency in message writing

This commit is contained in:
Edgar P. Burkhart 2025-05-17 20:10:14 +02:00
parent 91a6e7af3a
commit 7a57a986bf
Signed by: edpibu
GPG key ID: 9833D3C5A25BD227
3 changed files with 9 additions and 8 deletions

View file

@ -2,6 +2,6 @@
![](./logo.svg)
Tiny SMTP client for Micropython
Tiny SMTP client for Micropython. See [examples](examples) for usage.
Inspired from [shawwwn/uMail](https://github.com/shawwwn/uMail).

View file

@ -29,8 +29,8 @@ client.headers(
}
)
# Write message content
client.write_message("Hello world!")
client.write_message("Ceci est un message très intéressant.")
client.write_line("Hello world!\n")
client.write_line("Ceci est un message très intéressant.\n")
# Send message
client.send()

View file

@ -176,14 +176,15 @@ class MicromailClient:
to = [to]
self.write(f"To: {', '.join(to)}\r\n".encode())
def write_message(self, content):
self.write("\r\n".encode())
def write_line(self, content):
if isinstance(content, str):
content = content.encode()
if content.startswith(b"."):
content = b"." + content
if not content.endswith(b"\r\n"):
content += b"\r\n"
self.write(content)
self.write(content + b"\r\n")
def send(self):
code, _ = self.send_command(b"\r\n.")