SDKs overview

mail.tm offers an API-first approach for interacting with its temporary email service, allowing developers to programmatically create email addresses, retrieve incoming emails, and manage their lifecycle. The API itself is RESTful, utilizing standard HTTP methods and JSON payloads for requests and responses. While mail.tm provides official documentation with cURL examples and code snippets for common languages, the ecosystem also includes community-contributed libraries that abstract away direct HTTP calls, offering more idiomatic interfaces for specific programming environments.

Integrating mail.tm through an SDK or library can streamline development workflows for tasks such as automated user registration testing, validating email flows in QA environments, or providing temporary email functionality within a larger application. These tools handle aspects like API authentication (if required by the specific endpoint), request formatting, and response parsing, enabling developers to focus on application logic rather than low-level API interactions. The design of mail.tm's API is intended for simplicity, which is reflected in the structure of its various client libraries.

Official SDKs by language

mail.tm's primary method for developer interaction is its RESTful API, with official documentation providing direct examples across several programming languages rather than dedicated SDK packages. These examples serve as a foundation for developers to integrate the API into their projects. The following table outlines the languages for which mail.tm provides direct code examples and guidance within its official documentation, which can be considered the 'official' approach to using the API in those environments.

Language Approach / Package Installation / Usage Maturity / Support
PHP Direct API calls (cURL/Guzzle examples) composer require guzzlehttp/guzzle (for Guzzle) Official documentation support
JavaScript Direct API calls (Fetch API/Axios examples) npm install axios (for Axios) Official documentation support
Python Direct API calls (requests library examples) pip install requests Official documentation support
cURL Command-line examples Pre-installed on most Unix-like systems Primary documentation examples

These examples illustrate how to perform common operations such as creating a new temporary email account, retrieving a list of messages for an account, and fetching the content of a specific email. Developers are encouraged to consult the mail.tm API Documentation for the most up-to-date and comprehensive examples.

Installation

As mail.tm primarily provides direct API examples rather than packaged SDKs, installation typically involves setting up a suitable HTTP client library for your chosen programming language. These libraries simplify making HTTP requests and handling responses, which are fundamental to interacting with any RESTful API, including mail.tm's. The following instructions detail common methods for installing these prerequisite libraries.

PHP

For PHP, a popular choice for making HTTP requests is Guzzle. You can install Guzzle via Composer, PHP's dependency manager:

composer require guzzlehttp/guzzle

After installation, you can include Guzzle in your PHP script and use it to interact with the mail.tm API, as demonstrated in the mail.tm PHP examples.

JavaScript (Node.js/Browser)

In JavaScript environments, the native Fetch API is available in modern browsers and Node.js (since v18). For broader compatibility or additional features, Axios is a widely used promise-based HTTP client. Install Axios using npm or yarn:

npm install axios
# or
yarn add axios

Once installed, you can import Axios and use it to send requests to the mail.tm API. The mail.tm JavaScript examples often feature Fetch or Axios for clarity.

Python

Python's requests library is a de facto standard for making HTTP requests. It's known for its user-friendly API. Install it using pip:

pip install requests

With requests installed, you can easily implement the mail.tm Python API interactions as outlined in the documentation.

Quickstart example

This example demonstrates how to create a temporary email account and fetch its messages using Python with the requests library. This quickstart illustrates the typical flow for interacting with the mail.tm API: creating a resource (an account) and then querying it for data (messages).

Python Quickstart: Create Account and Fetch Messages

import requests

BASE_URL = "https://api.mail.tm"

def create_account(address, password):
    url = f"{BASE_URL}/accounts"
    headers = {"Content-Type": "application/json"}
    data = {"address": address, "password": password}
    response = requests.post(url, headers=headers, json=data)
    response.raise_for_status() # Raise an exception for HTTP errors
    return response.json()

def get_token(address, password):
    url = f"{BASE_URL}/token"
    headers = {"Content-Type": "application/json"}
    data = {"address": address, "password": password}
    response = requests.post(url, headers=headers, json=data)
    response.raise_for_status()
    return response.json()["token"]

def get_messages(token, account_id):
    url = f"{BASE_URL}/messages"
    headers = {"Authorization": f"Bearer {token}"}
    response = requests.get(url, headers=headers)
    response.raise_for_status()
    return response.json()

# --- Usage Example ---
if __name__ == "__main__":
    email_address = "[email protected]" # mail.tm will assign a domain
    account_password = "StrongP@ssw0rd"

    try:
        # 1. Create a new account
        print("Creating account...")
        new_account = create_account(email_address, account_password)
        print(f"Account created: {new_account['address']} (ID: {new_account['id']})")
        
        # Use the assigned address from the API response
        assigned_address = new_account['address']
        account_id = new_account['id']

        # 2. Get an authentication token for the new account
        print("Getting authentication token...")
        auth_token = get_token(assigned_address, account_password)
        print(f"Authentication token obtained: {auth_token[:10]}...")

        # 3. Fetch messages for the account
        print("Fetching messages (may be empty initially)...")
        messages = get_messages(auth_token, account_id)
        
        if messages:
            print(f"Found {len(messages)} messages:")
            for msg in messages:
                print(f"  - Subject: {msg.get('subject', 'No Subject')}, From: {msg.get('from', {}).get('address', 'Unknown')}")
        else:
            print("No messages found yet.")

    except requests.exceptions.RequestException as e:
        print(f"An API error occurred: {e}")
    except Exception as e:
        print(f"An unexpected error occurred: {e}")

This snippet demonstrates the fundamental steps: defining API endpoints, constructing requests with appropriate headers and data, and processing the JSON responses. For a comprehensive understanding of all available endpoints and their parameters, refer to the mail.tm API documentation.

Community libraries

While mail.tm's official documentation focuses on direct API interaction, the developer community often builds libraries to provide more abstract and language-idiomatic interfaces. These community-driven projects can simplify integration by encapsulating common API patterns, handling authentication flows, and providing helper functions specific to a given programming language or framework. The existence of such libraries indicates active community engagement and can be a valuable resource for developers seeking pre-built solutions.

Developers looking for community libraries are encouraged to search package managers (e.g., PyPI for Python, npm for JavaScript, Packagist for PHP) or code hosting platforms (e.g., GitHub) using keywords like mail.tm, temporary email, or disposable email API. When using community-contributed libraries, it is advisable to check their maintenance status, documentation, and community support, as they are not officially maintained by mail.tm. An example of a common pattern for community libraries is creating an object-oriented wrapper around the RESTful API design principles, making it easier to interact with resources like accounts and messages.

For instance, a Python developer might find a library that offers classes for Account and Message, allowing interactions like account.create() or account.get_messages(). Similarly, a JavaScript developer might find an npm package that provides a client object with methods like mailtm.createAccount(). These libraries aim to reduce boilerplate code and improve developer velocity.

As of 2026-05-29, specific widely adopted, officially recommended community libraries for mail.tm are not prominently featured in its primary documentation. Developers should verify the suitability and security of any third-party library before incorporating it into production systems. Reviewing the source code and understanding how the library interacts with the mail.tm API is a recommended practice to ensure it aligns with project requirements and security standards, a practice commonly advised for any third-party SDK or library integration.