Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslnode 18–226 runs
build_error
glibcnode 18–226 runs
build_error
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
MailSlurp
✓ import { MailSlurp } from 'mailslurp-client'
✗ const MailSlurp = require('mailslurp-client')
For CommonJS environments, `require('mailslurp-client').default` is typically needed to access the main `MailSlurp` class. Native ESM `import { MailSlurp }` is the standard for modern projects.
InboxController
✓ import { InboxController } from 'mailslurp-client'
✗ import InboxController from 'mailslurp-client'
Represents the controller for managing email inboxes. Other controllers like `SendController` or `WaitForController` are also available as named exports.
CreateInboxOptions
✓ import type { CreateInboxOptions } from 'mailslurp-client'
Explicit type import for configuring inbox creation. Essential for TypeScript users to get correct type inference and auto-completion.
This example demonstrates initializing the MailSlurp client with an API key, creating a temporary email inbox, sending an email from that inbox, and includes a placeholder for demonstrating email reception. It highlights common use cases for automated email testing and integration workflows.
import { MailSlurp } from 'mailslurp-client';
// Assuming a test runner like Jest is present for 'expect'
// In a standalone script, you might use console.assert or a custom check.
const expect = (value: any) => ({
toContain: (substring: string) => {
if (typeof value !== 'string' || !value.includes(substring)) {
throw new Error(`Expected "${value}" to contain "${substring}"`);
}
},
toEqual: (expected: any) => {
if (value !== expected) {
throw new Error(`Expected "${value}" to equal "${expected}"`);
}
}
});
async function runMailSlurpExample() {
// Retrieve API Key from environment variables or provide directly
const apiKey = process.env.MAILSLURP_API_KEY ?? 'YOUR_MAILSLURP_API_KEY';
if (apiKey === 'YOUR_MAILSLURP_API_KEY') {
console.warn('WARNING: Replace "YOUR_MAILSLURP_API_KEY" with your actual MailSlurp API Key from mailslurp.com dashboard.');
return;
}
// Create a new MailSlurp client instance
const mailslurp = new MailSlurp({ apiKey });
console.log('Creating a new MailSlurp inbox...');
// Create a new random inbox for testing
const inbox = await mailslurp.inboxController.createInbox({});
console.log(`Inbox created with email address: ${inbox.emailAddress}`);
// Assert that the email address is valid
expect(inbox.emailAddress).toContain('@');
// Example: Send an email from the created inbox
const recipientEmail = 'test-recipient@example.com'; // In a real scenario, this could be another MailSlurp inbox
const emailSubject = 'Hello from MailSlurp!';
await mailslurp.sendController.sendEmailAndConfirm({
inboxId: inbox.id,
sendEmailOptions: {
to: [recipientEmail],
subject: emailSubject,
body: 'This is a test email sent using the MailSlurp client.',
},
});
console.log(`Email sent from ${inbox.emailAddress} to ${recipientEmail}`);
// To demonstrate receiving, let's assume `recipientEmail` is another MailSlurp inbox you control
// Or if sending to itself for loopback test (not typical, but for demonstration):
// const receivedEmail = await mailslurp.waitForController.waitForLatestEmail({
// inboxId: inbox.id,
// timeout: 60000,
// });
// console.log(`Received email with subject: "${receivedEmail.subject}"`);
// expect(receivedEmail.subject).toEqual(emailSubject);
console.log('MailSlurp client initialized and inbox created/sent email. Check your MailSlurp dashboard.');
}
runMailSlurpExample().catch(console.error);
Errors
Common errors & fixes
MailSlurp API Key not found. Please provide an API Key to the MailSlurp client.
The `apiKey` option was not provided or was empty when instantiating `new MailSlurp({ apiKey: '...' })`.
fixObtain your API Key from the MailSlurp dashboard (app.mailslurp.com) and pass it to the client: `const mailslurp = new MailSlurp({ apiKey: process.env.MAILSLURP_API_KEY });` Error: Timeout of 60000ms exceeded
An API call, particularly a `waitForController` method, waited longer than the specified timeout for a condition (e.g., email arrival) to be met.
fixIncrease the `timeout` parameter for the specific MailSlurp operation, or globally configure the fetch client's timeout. SMTP can be slow, so 60-120 seconds might be necessary for reliability.
TypeError: (0 , mailslurp_client__WEBPACK_IMPORTED_MODULE_0__.MailSlurp) is not a constructor
Incorrect import statement for `MailSlurp` class. This typically indicates a mismatch between the module system being used (CommonJS vs. ESM) and the import syntax.
fixFor ES Modules: `import { MailSlurp } from 'mailslurp-client';`. For CommonJS: `const MailSlurp = require('mailslurp-client').default;`. Audit
Dependencies
No dependency data recorded yet.