Update README and example.py for clarity and consistency in message writing
This commit is contained in:
parent
91a6e7af3a
commit
7a57a986bf
3 changed files with 9 additions and 8 deletions
|
@ -2,6 +2,6 @@
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
Tiny SMTP client for Micropython
|
Tiny SMTP client for Micropython. See [examples](examples) for usage.
|
||||||
|
|
||||||
Inspired from [shawwwn/uMail](https://github.com/shawwwn/uMail).
|
Inspired from [shawwwn/uMail](https://github.com/shawwwn/uMail).
|
||||||
|
|
|
@ -29,8 +29,8 @@ client.headers(
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
# Write message content
|
# Write message content
|
||||||
client.write_message("Hello world!")
|
client.write_line("Hello world!\n")
|
||||||
client.write_message("Ceci est un message très intéressant.")
|
client.write_line("Ceci est un message très intéressant.\n")
|
||||||
# Send message
|
# Send message
|
||||||
client.send()
|
client.send()
|
||||||
|
|
||||||
|
|
|
@ -176,14 +176,15 @@ class MicromailClient:
|
||||||
to = [to]
|
to = [to]
|
||||||
self.write(f"To: {', '.join(to)}\r\n".encode())
|
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):
|
if isinstance(content, str):
|
||||||
content = content.encode()
|
content = content.encode()
|
||||||
|
if content.startswith(b"."):
|
||||||
|
content = b"." + content
|
||||||
|
|
||||||
if not content.endswith(b"\r\n"):
|
self.write(content + b"\r\n")
|
||||||
content += b"\r\n"
|
|
||||||
|
|
||||||
self.write(content)
|
|
||||||
|
|
||||||
def send(self):
|
def send(self):
|
||||||
code, _ = self.send_command(b"\r\n.")
|
code, _ = self.send_command(b"\r\n.")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue