Getting started overview
This guide outlines the essential steps to begin using Mailsac for email testing and automation. It covers account creation, API key generation, and executing a foundational API request to retrieve email content. Mailsac provides disposable email addresses and an API to programmatically interact with these mailboxes, which is useful for development, quality assurance (QA), and automated testing environments Mailsac documentation. The service supports a RESTful API architecture, allowing integration with various programming languages and systems Mailsac API reference.
Before making your first API call, you will need to:
- Create a Mailsac account.
- Generate an API key from your account dashboard.
- Understand how to use the API key for authentication.
Mailsac offers a free tier that includes access to public mailboxes and a limited number of private mailboxes. Paid plans, such as the Mail Tester plan starting at $40/month, provide enhanced features like increased private mailbox limits, broader API access, and higher usage quotas Mailsac pricing page. The API is designed for ease of use, with clear documentation and examples in languages like JavaScript and cURL.
Here's a quick reference for the getting started process:
| Step | What to do | Where |
|---|---|---|
| 1. Sign Up | Create a new Mailsac account. | Mailsac Signup Page |
| 2. Get API Key | Generate your unique API key. | Mailsac API Keys Dashboard |
| 3. Authenticate | Include your API key in API requests. | HTTP Header: Mailsac-Key |
| 4. First Request | Fetch emails from a mailbox. | Get Messages API Endpoint |
Create an account and get keys
To begin interacting with the Mailsac API, you must first create an account. This process typically involves providing an email address and setting a password. Once your account is established, you can access the Mailsac dashboard, which serves as your central hub for managing mailboxes and API keys.
-
Navigate to the Mailsac Website: Open your web browser and go to the Mailsac homepage.
-
Sign Up: Locate the "Sign Up" or "Get Started Free" button, typically in the top right corner of the page, and click it. You will be redirected to the Mailsac signup page.
-
Complete Registration: Fill in the required details, such as your email address and a secure password. Follow any on-screen prompts to verify your email address, which may involve clicking a link sent to your inbox.
-
Access Dashboard: After successful registration and verification, log in to your Mailsac account. You will be directed to your user dashboard.
-
Generate an API Key: From the dashboard, navigate to the "API Keys" section. This is usually found in the account settings or a dedicated API management area Mailsac API keys management. Click on a button like "Create New API Key" or "Generate Key."
-
Name Your Key (Optional): Some platforms allow you to assign a descriptive name to your API key. This helps in identifying the purpose of each key if you create multiple keys for different applications or environments. For example, you might name it "My First App Key."
-
Copy the API Key: Once generated, your API key will be displayed. It is critical to copy this key immediately and store it securely. For security reasons, Mailsac often displays the full key only once, and you may not be able to retrieve it again if lost. Treat your API key like a password; do not expose it in public repositories or client-side code.
Your Mailsac API key is a unique identifier that authenticates your requests to the Mailsac API. It grants you access to your mailboxes and allows you to perform operations such as fetching messages, creating private mailboxes, and managing email content. All subsequent API calls will require this key for authorization.
Your first request
Once you have your Mailsac API key, you can make your first programmatic request. A common initial step is to retrieve messages from a public mailbox. Mailsac's API is RESTful, meaning you interact with it using standard HTTP methods (GET, POST, PUT, DELETE) to specific endpoints Mailsac API documentation. Authentication is typically handled by including your API key in a custom HTTP header.
For this example, we will use a public mailbox named test-example. You can use any string for a public mailbox, as they are created on demand when an email is sent to them or when you attempt to access them via the API. The API endpoint to fetch messages from a mailbox is /api/addresses/{email}/messages.
Using cURL (Command Line)
cURL is a command-line tool and library for transferring data with URLs. It's widely available on most Unix-like systems and can be installed on Windows cURL installation guide. This example demonstrates how to fetch messages using cURL.
curl -X GET \
"https://mailsac.com/api/addresses/test-example/messages" \
-H "Mailsac-Key: YOUR_API_KEY"
Replace YOUR_API_KEY with the actual API key you generated from your Mailsac dashboard.
Using Node.js (JavaScript)
Mailsac provides a Node.js SDK to simplify interactions with its API. First, you need to install the SDK:
npm install mailsac-client
Then, you can use the following JavaScript code to retrieve messages:
const Mailsac = require('mailsac-client');
const mailsac = new Mailsac('YOUR_API_KEY');
async function getMessages() {
try {
const messages = await mailsac.addresses.getMessages('test-example');
console.log('Messages in test-example mailbox:', messages);
} catch (error) {
console.error('Error fetching messages:', error);
}
}
getMessages();
Again, replace YOUR_API_KEY with your actual Mailsac API key. This code initializes the Mailsac client with your API key and then calls the getMessages method to retrieve emails from the specified mailbox.
After executing either of these requests, if there are messages in the [email protected] mailbox, the response will be a JSON array containing message objects. If the mailbox is empty, you might receive an empty array or a response indicating no messages.
Common next steps
After successfully making your first request to Mailsac, consider these common next steps to further integrate and utilize the API:
-
Sending a Test Email: To see Mailsac in action, send an email to the public mailbox you just queried (e.g.,
[email protected]) from any email client. Then, re-run your API request to observe the newly received message. This confirms your setup can both receive and retrieve emails. -
Creating and Using Private Mailboxes: For more secure or isolated testing, create private mailboxes. Private mailboxes require authentication to access, ensuring that only you (or those with your API key) can view their contents. The Mailsac API allows you to programmatically create and manage these Create Address API endpoint.
-
Filtering and Searching Messages: As your testing scales, you'll need to locate specific emails. Mailsac's API supports filtering messages by sender, subject, or content, and searching within message bodies. Explore the API documentation for parameters that allow you to refine your message retrieval Get Messages filtering options.
-
Automating Email Workflows: Integrate Mailsac into your continuous integration/continuous deployment (CI/CD) pipelines or testing frameworks. For example, you can use Mailsac to automate user registration and verification flows by programmatically checking for confirmation emails and extracting verification links. This is a common pattern in automated testing Mailsac email testing guide.
-
Webhooks for Real-time Notifications: Instead of polling the API, configure webhooks to receive real-time notifications when new emails arrive in a mailbox. This can significantly improve the efficiency of your automated tests by triggering actions immediately upon email receipt. Webhooks are a standard mechanism for event-driven communication Mailsac Webhooks documentation, also described in general terms by resources like the Cloudflare Workers webhook request documentation.
-
Exploring Advanced Features: Depending on your plan, investigate features like custom domains, email forwarding, and attachment handling. These can extend Mailsac's utility for more complex testing scenarios.
-
Reviewing Rate Limits and Usage: Be mindful of the API rate limits associated with your Mailsac plan to avoid service interruptions. Monitor your usage through the Mailsac dashboard or by checking API response headers for limit information. Understanding these limits is crucial for scalable applications.
Troubleshooting the first call
Encountering issues during your first API call is common. Here are some troubleshooting steps for Mailsac:
-
Invalid API Key (401 Unauthorized):
- Check for Typos: Ensure your API key is copied and pasted exactly, without extra spaces or missing characters.
- Correct Header Name: Verify that the HTTP header for your API key is precisely
Mailsac-Key. Case sensitivity matters. - Key Generation: Confirm you generated the key from your Mailsac API keys dashboard and it hasn't expired or been revoked.
- Plan Limitations: Some Mailsac plans may restrict API access to certain features or require a paid subscription for specific endpoints. Check your Mailsac plan details.
-
Mailbox Not Found / No Messages (Empty Array or 404 Not Found):
- Public vs. Private: If you're trying to access a private mailbox without having explicitly created it or authenticated correctly, you might not see messages. Ensure you are using a public mailbox for initial tests, or correctly authenticating for a private one.
- Email Sent?: Have you actually sent an email to the
[email protected]address (or your chosen mailbox)? Mailsac mailboxes are often created upon receipt of the first email. - Correct Mailbox Name: Double-check the mailbox name in your API request matches the one you expect. For public mailboxes, the part before
@mailsac.comis the identifier.
-
Network Issues / Connection Refused:
- Internet Connection: Verify your internet connection is stable.
- Firewall/Proxy: Corporate firewalls or proxies can sometimes block outbound requests to unknown domains. Consult your network administrator if you suspect this is the case.
- Mailsac Status: Check the Mailsac status page (if available) for any ongoing service disruptions.
-
Incorrect Endpoint or Method (400 Bad Request, 405 Method Not Allowed):
- API Reference: Refer to the Mailsac API reference to ensure you are using the correct URL path and HTTP method (e.g., GET for retrieving, POST for creating).
- URL Encoding: If your mailbox name or other parameters contain special characters, ensure they are properly URL-encoded.
-
SDK-Specific Errors (e.g., Node.js):
- SDK Installation: Confirm the
mailsac-clientSDK is correctly installed vianpm install mailsac-client. - Initialization: Ensure you are initializing the SDK client with your API key as shown in the examples.
- Error Handling: Implement
try-catchblocks (as shown in the Node.js example) to gracefully handle and log any errors returned by the SDK or underlying API calls.
- SDK Installation: Confirm the
When troubleshooting, always examine the full HTTP response, including status codes and response bodies, as they often contain specific error messages that can guide your debugging efforts.