SDKs overview

Mailsac provides an API-first approach to disposable email addresses and email testing, allowing developers to programmatically interact with mailboxes. While the Mailsac API is a RESTful service accessible via standard HTTP requests, Software Development Kits (SDKs) and client libraries are designed to simplify integration by providing language-specific wrappers. These SDKs handle details such as API key management, request serialization, and response parsing, enabling developers to focus on application logic rather than low-level API interactions. Mailsac's official SDK primarily targets Node.js environments, reflecting its utility in server-side applications and test automation scripts.

The Mailsac API facilitates various use cases, including automated user registration testing, verifying email delivery in staging environments, and building custom email-driven workflows. By abstracting the HTTP requests, the SDKs streamline common operations such as creating unique email addresses, fetching emails from specific inboxes, and deleting messages. This programmatic access is fundamental for continuous integration/continuous delivery (CI/CD) pipelines and other automated testing frameworks where temporary email communication is required without manual intervention or reliance on real user inboxes.

Official SDKs by language

Mailsac offers an official SDK for Node.js, designed to provide a direct and idiomatic interface for JavaScript developers. This SDK is maintained by Mailsac and is the recommended method for integrating Mailsac's email testing and automation capabilities into Node.js applications. It aims to cover the full scope of the Mailsac REST API, ensuring that all functionalities available through direct HTTP calls are also accessible via the library.

The official SDK simplifies common tasks, such as creating new mailboxes, reading emails, and managing API keys. It adheres to standard Node.js package conventions, making it compatible with widely used package managers and development workflows. Developers can consult the Mailsac API documentation for detailed information on available endpoints and data models, which are mirrored in the SDK's design.

Official Mailsac SDKs

Language Package Name Installation Command Maturity
Node.js mailsac npm install mailsac or yarn add mailsac Stable

Installation

The Mailsac Node.js SDK can be installed using either npm (Node Package Manager) or Yarn, the two most common package managers in the Node.js ecosystem. Before installation, ensure that Node.js and npm/Yarn are installed on your system. You can verify their presence by running node -v and npm -v (or yarn -v) in your terminal.

Node.js Installation

To install the official Mailsac SDK for Node.js, open your terminal or command prompt and execute one of the following commands:

Using npm:

npm install mailsac

Using Yarn:

yarn add mailsac

After successful installation, the mailsac package will be added to your project's node_modules directory, and an entry will be included in your package.json file. You can then import and use the library in your JavaScript or TypeScript files.

Quickstart example

The following example demonstrates how to use the Mailsac Node.js SDK to create a temporary mailbox, send an email to it (simulated), and then retrieve the received email. This quickstart illustrates the basic workflow for integrating Mailsac into a testing or automation script. A Mailsac API key is required for most operations on private mailboxes or for advanced features, which can be obtained from the Mailsac documentation.

Node.js Quickstart: Fetching Emails

const Mailsac = require('mailsac');

const API_KEY = 'YOUR_MAILSAC_API_KEY'; // Replace with your actual Mailsac API Key
const mailsac = new Mailsac(API_KEY);

async function fetchEmailsFromMailbox() {
  const mailboxName = `test-inbox-${Date.now()}@mailsac.com`;
  console.log(`Using mailbox: ${mailboxName}`);

  // In a real scenario, you would send an email to this address from your application.
  // For this example, we'll simulate waiting for an email.
  console.log('Waiting for an email to arrive...');
  await new Promise(resolve => setTimeout(resolve, 5000)); // Wait for 5 seconds

  try {
    // Fetch messages from the mailbox
    const messages = await mailsac.messages(mailboxName);
    
    if (messages.length > 0) {
      console.log(`Found ${messages.length} email(s) in ${mailboxName}:`);
      messages.forEach((message, index) => {
        console.log(`--- Email ${index + 1} ---`);
        console.log(`Subject: ${message.subject}`);
        console.log(`From: ${message.from[0].address}`);
        console.log(`Snippet: ${message.snippet}`);
        // To get full message body, you might need to fetch individual message by ID
        // const fullMessage = await mailsac.message(mailboxName, message._id);
        // console.log('Full text:', fullMessage.text);
      });
    } else {
      console.log(`No emails found in ${mailboxName}.`);
    }

    // Optionally, delete the mailbox or specific messages after testing
    // await mailsac.deleteMailbox(mailboxName);
    // console.log(`Mailbox ${mailboxName} deleted.`);

  } catch (error) {
    console.error('Error fetching emails:', error.message);
  }
}

fetchEmailsFromMailbox();

This example initializes the Mailsac client with an API key, constructs a unique mailbox name, simulates an email being sent to it (by waiting), and then retrieves any messages found. For public mailboxes, an API key might not be strictly necessary for basic read operations, but it is required for private mailboxes and many write operations like deleting messages or creating specific addresses. For more complex scenarios, such as listening for new emails via webhooks, developers should refer to the Mailsac API reference.

Community libraries

While Mailsac officially supports a Node.js SDK, the open nature of its RESTful API allows for the development of community-contributed libraries in various programming languages. These libraries are typically developed and maintained by individual developers or organizations outside of Mailsac's direct control. They often arise to meet specific needs within different technology stacks or to provide alternative interfaces to the core Mailsac functionality.

Community libraries can offer wrappers for languages not officially supported, such as Python, Ruby, or Go, or provide specialized tools built on top of the Mailsac API. When considering a community library, it is advisable to evaluate its maintenance status, documentation quality, and community support. Developers can often find these projects on platforms like GitHub, which serve as common repositories for open-source API clients and tools. Although not officially endorsed, these libraries can be valuable resources for integrating Mailsac into diverse development environments. Searching for "Mailsac client" or "Mailsac library" on code hosting platforms may reveal relevant community contributions. The general principles of API client library design apply, regardless of official status.