Update README.md to enhance MicromailClient documentation and add exceptions section; modify error handling in write method to raise NoSocketError
This commit is contained in:
parent
3795f8d8c0
commit
02e6f3fbcc
2 changed files with 59 additions and 27 deletions
84
README.md
84
README.md
|
@ -21,43 +21,75 @@ Copy the `micromail.py` file to your device. You will need to install the `datet
|
||||||
|
|
||||||
### Class MicromailClient
|
### Class MicromailClient
|
||||||
|
|
||||||
`class micromail.MicromailClient(host: str, port: int, ssl: bool=False, starttls: bool=False)`
|
- `class micromail.MicromailClient(host: str, port: int = 0, ssl: bool = False, starttls: bool = False)`
|
||||||
: Create a new SMTP client.
|
|
||||||
|
|
||||||
`MicromailClient.connect()`
|
Create a new SMTP client.
|
||||||
: Establish a connection to the SMTP server. The connection is kept alive until `MicromailClient.quit()` is called.
|
|
||||||
|
|
||||||
`MicromailClient.login(username: str, password: str)`
|
- `MicromailClient.connect()`
|
||||||
: Login to the SMTP server with the provided username and password. `PLAIN` and `LOGIN` authentication methods are currently supported.
|
|
||||||
|
|
||||||
`MicromailClient.write(data: bytearray)`
|
|
||||||
: Write `data` of type `bytearray` on the server.
|
|
||||||
|
|
||||||
`MicromailClient.send_command(*cmd: bytearray) -> code: bytearray, response: list[bytearray]`
|
Establish a connection to the SMTP server. The connection is kept alive until `MicromailClient.quit()` is called.
|
||||||
: Send command to the SMTP server; returns status code and response.
|
|
||||||
|
|
||||||
`MicromailClient.ehlo() -> res: list[bytearray]`
|
- `MicromailClient.login(username: str, password: str)`
|
||||||
: Send SMTP EHLO command to the server and return response.
|
|
||||||
|
|
||||||
`MicromailClient.starttls()`
|
Login to the SMTP server with the provided username and password. `PLAIN` and `LOGIN` authentication methods are currently supported.
|
||||||
: Send SMTP STARTTLS command and enable SSL on socket.
|
|
||||||
|
|
||||||
`MicromailClient.new_message(to: str|list[str], sender: None|str=None)`
|
- `MicromailClient.write(data: str | bytes)`
|
||||||
: Create a new email; sender defaults to username.
|
|
||||||
|
|
||||||
`MicromailClient.headers(headers:dict={})`
|
Write `data` of type `bytearray` on the server.
|
||||||
: Define email headers; supported headers are `date` (`str|datetime`, defaults to `datetime.now()`), `from` (`str`, defaults to `new_message` `sender`), `to` (`str|list[str]`, defaults to `new_message` `to`), `subject` (`str`).
|
|
||||||
|
|
||||||
`MicromailClient.write_line(content:str|bytearray)`
|
- `MicromailClient.send_command(*cmd: str | bytes, code: int | list[int] = []) -> tuple[int, list[str]]`
|
||||||
: Write message line; `\r\n` is appended to `content`.
|
|
||||||
|
|
||||||
`MicromailClient.send()`
|
Send command to the SMTP server; returns status code and list of response lines.
|
||||||
: Send current email.
|
|
||||||
|
|
||||||
`MicromailClient.quit()`
|
- `MicromailClient.read_res(cmd: str = "", code: int | list[int] = []) -> tuple[int, list[str]]`
|
||||||
: Quit the SMTP server and disconnect from socket.
|
|
||||||
|
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
|
### Functions
|
||||||
|
|
||||||
`format_date(date: datetime)`
|
- `format_date(date: datetime) -> str`
|
||||||
: Return date formatted as email date string.
|
|
||||||
|
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.
|
||||||
|
|
|
@ -110,7 +110,7 @@ class MicromailClient:
|
||||||
|
|
||||||
def write(self, data: str | bytes) -> None:
|
def write(self, data: str | bytes) -> None:
|
||||||
if self.socket is None:
|
if self.socket is None:
|
||||||
raise Error("No socket to write to.")
|
raise NoSocketError
|
||||||
|
|
||||||
if isinstance(data, str):
|
if isinstance(data, str):
|
||||||
data = data.encode()
|
data = data.encode()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue