diff --git a/README.md b/README.md index 10dea9f..5c7cff7 100644 --- a/README.md +++ b/README.md @@ -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). diff --git a/examples/example.py b/examples/example.py index 4745514..fc15eb1 100644 --- a/examples/example.py +++ b/examples/example.py @@ -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() diff --git a/micromail/__init__.py b/micromail/__init__.py index 7d452f8..fa8a8be 100644 --- a/micromail/__init__.py +++ b/micromail/__init__.py @@ -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.")