Skip to content

⚡Synchronous Mail Client implementation.#

This module provides a synchronous client for the Mail.TM API.

  • The client can be used to fetch data from the API, including account information, domain information, and messages.
  • The client uses the 'requests' library to make HTTP requests to the API and the 'msgspec' library to decode the JSON responses from the API into Python objects.
  • The client is easy to use and is designed to be used in a synchronous application.
  • The API is documented at Mail.tm Documentation
You don't have to worry about:
  • The client automatically handles errors and exceptions, so you don't have to.
  • The client also handles rate limits, so you don't have to.
You do have to worry about:
  • The client does not handle connection limits, so you might have to.
  • The client does not handle SSL verification, so you might have to.

SyncMail #

SyncMail(account_token: t.Optional[Token] = None)

Synchronous client for the Mail.TM API.

PARAMETER DESCRIPTION
account_token

The account token to use for authentication. If not provided, the client will not be authenticated.

TYPE: t.Optional[Token] DEFAULT: None

Example
from mailtm import SyncMail

with SyncMail() as client:
    account = client.get_me()
    print(account)

get_me #

get_me() -> t.Optional[Account]

Gets the authenticated account.

RETURNS DESCRIPTION
Optional[Account]

The account or None if the account is not authenticated.

get_domains #

get_domains() -> t.Optional[DomainPageView]

Get a page view of domains available under the account token provided to create a session.

RETURNS DESCRIPTION
Optional[DomainPageView]

A page view of domains available under the account token provided to create a session. If not authenticated, returns None.

get_domain #

get_domain(domain_id: str) -> t.Optional[Domain]

Get a specific domain with ID.

PARAMETER DESCRIPTION
domain_id

The ID of the domain to get.

TYPE: str

RETURNS DESCRIPTION
Optional[Domain]

The domain with the ID provided. If not found, returns None.

get_account #

get_account(account_id: str) -> t.Optional[Account]

Get an accnount by it's ID.

PARAMETER DESCRIPTION
account_id

The ID of the account to get.

TYPE: str

RETURNS DESCRIPTION
Optional[Account]

The account with the ID provided. If not found, returns None.

create_account #

create_account(
    address: str, password: str
) -> t.Optional[Account]

Creates an account.

PARAMETER DESCRIPTION
address

The email address of the new account.

TYPE: str

password

The password for the new account.

TYPE: str

RETURNS DESCRIPTION
Optional[Account]

The newly created account object if successful, None otherwise.

delete_account #

delete_account(account_id: t.Optional[str] = None) -> None

Deletes an account.

PARAMETER DESCRIPTION
account_id

The ID of the account to delete. If not provided, the account token will be used to delete the account.

TYPE: t.Optional[str] DEFAULT: None

get_messages #

get_messages(page: int = 1) -> t.Optional[MessagePageView]

Get a page view of messages available under the account token provided to create a session.

PARAMETER DESCRIPTION
page

The page number to get. Defaults to 1.

TYPE: int DEFAULT: 1

RETURNS DESCRIPTION
Optional[MessagePageView]

A page view of messages available under the account token provided to create a session. If not authenticated, returns None.

get_message #

get_message(message_id: str) -> t.Optional[Message]

Get a specific message with ID.

PARAMETER DESCRIPTION
message_id

The ID of the message to get.

TYPE: str

RETURNS DESCRIPTION
Optional[Message]

The message with the ID provided. If not found, returns None.

delete_message #

delete_message(message_id: str) -> None

Delete a specific message with ID.

PARAMETER DESCRIPTION
message_id

The ID of the message to delete.

TYPE: str

RETURNS DESCRIPTION
None

mark_as_seen #

mark_as_seen(message_id: str) -> None

Flag a message as seen.

PARAMETER DESCRIPTION
message_id

The ID of the message to mark as seen.

TYPE: str

RETURNS DESCRIPTION
None

get_source #

get_source(source_id: str) -> t.Optional[Source]

Get source by the source ID.

PARAMETER DESCRIPTION
source_id

The ID of the source to get.

TYPE: str

RETURNS DESCRIPTION
Optional[Source]

The source with the ID provided. If not found, returns None.