Creates an instance of MailpitClient.
The base URL of the Mailpit API.
Optionaloptions: MailpitClientOptionsOptional configuration including auth credentials and fetch options.
Options for a MailpitClient instance.
Optionalauth?: MailpitAuthCredentialsOptional basic auth credentials.
OptionalfetchOptions?: Omit<RequestInit, "method" | "body">Optional fetch options merged into every request.
method and body are managed internally and cannot be overridden.
Any headers provided here are merged with internally managed headers (Authorization, Content-Type), with internal headers taking precedence.
Delete individual or all messages.
OptionaldeleteRequest: MailpitDatabaseIDsRequestThe request containing the message database IDs to delete.
Plain text "ok" response
Delete all messages matching a search.
The search request containing the query.
Plain text "ok" response
Generates a cropped 180x120 JPEG thumbnail of an image attachment from a message. Only image attachments are supported.
Message database ID or "latest"
The attachment part ID
The thumbnail as a Blob. Use blob.type for the MIME type (always image/jpeg).
If the image is smaller than 180x120 then the image is padded. If the attachment is not an image then a blank image is returned.
const message = await mailpit.getMessageSummary();
if (message.Attachments.length) {
const blob = await mailpit.getAttachmentThumbnail(message.ID, message.Attachments[0].PartID);
// Browser: const url = URL.createObjectURL(blob);
// Node.js: const buffer = Buffer.from(await blob.arrayBuffer());
}
Retrieves the current Chaos triggers configuration (if enabled).
The Chaos triggers configuration
Retrieves the configuration of the Mailpit web UI.
Configuration settings
Retrieves information about the Mailpit instance.
Basic runtime information, message totals and latest release version.
Retrieves a specific attachment from a message.
Message database ID or "latest"
The attachment part ID
The attachment as a Blob. Use blob.type for the MIME type.
const message = await mailpit.getMessageSummary();
if (message.Attachments.length) {
const blob = await mailpit.getMessageAttachment(message.ID, message.Attachments[0].PartID);
console.log(blob.type); // e.g. "application/pdf"
// Browser: const url = URL.createObjectURL(blob);
// Node.js: const buffer = Buffer.from(await blob.arrayBuffer());
}
Retrieves the headers of a specific message.
The message database ID. Defaults to latest to return the latest message.
Message headers
Retrieves a summary of a specific message and marks it as read.
The message database ID. Defaults to latest to return the latest message.
Message summary
Performs an HTML check on a specific message.
The message database ID. Defaults to latest to return the latest message.
The summary of the message HTML checker
Performs a link check on a specific message.
The message database ID. Defaults to latest to return the latest message.
Whether to follow links. Defaults to false.
The summary of the message Link checker.
Retrieves a list of message summaries ordered from newest to oldest.
The pagination offset. Defaults to 0.
The number of messages to retrieve. Defaults to 50.
A list of message summaries
getMessageSummary() for more attachment and body details for a specific message.
Release a message via a pre-configured external SMTP server.
The message database ID. Use latest to return the latest message.
Array of email addresses to relay the message to
Plain text "ok" response
Renames an existing tag.
The current name of the tag.
A new name for the tag.
Plain text "ok" response
Renders the HTML part of a specific message which can be used for UI integration testing.
The message database ID. Defaults to latest to return the latest message.
Optionalembed: 1Whether this route is to be embedded in an iframe. Defaults to undefined. Set to 1 to embed.
The embed parameter will add target="_blank" and rel="noreferrer noopener" to all links.
In addition, a small script will be added to the end of the document to post (postMessage()) the height of the document back to the parent window for optional iframe height resizing.
Note that this will also transform the message into a full HTML document (if it isn't already), so this option is useful for viewing but not programmatic testing.
Rendered HTML
Retrieve messages matching a search, sorted by received date (descending).
The search request containing the query and optional parameters.
A list of message summaries matching the search criteria.
Sends a message
The request containing the message details.
Response containing database message ID
Sets and/or resets the Chaos triggers configuration (if enabled).
The request containing the chaos triggers. Omitted triggers will reset to the default 0% probabibility.
The updated Chaos triggers configuration
Set the read status of messages.
The request containing the message database IDs/search string and the read status.
Request parameters for the setReadStatus() API.
OptionalIDs?: string[]Array of message database IDs
OptionalRead?: booleanRead status
OptionalSearch?: stringOptionalparams: MailpitTimeZoneRequestOptional parameters for defining the time zone when using the before: and after: search filters.
Plain text "ok" response
You can optionally provide an array of IDs OR a Search filter. If neither is set then all messages are updated.
// Set all messages as unread
await mailpit.setReadStatus();
// Set all messages as read
await mailpit.setReadStatus({ Read: true });
// Set specific messages as read using IDs
await mailpit.setReadStatus({ IDs: ["1", "2", "3"], Read: true });
// Set specific messages as read using search
await mailpit.setReadStatus({ Search: "from:example.test", Read: true });
// Set specific messages as read using after: search with time zone
await mailpit.setReadStatus({ Search: "after:2025-04-30", Read: true }, { tz: "America/Chicago" });
Sets and removes tag(s) on message(s). This will overwrite any existing tags for selected message database IDs.
The request containing the message IDs and tags. To remove all tags from a message, pass an empty Tags array or exclude Tags entirely.
Plain text "ok" response
Performs a SpamAssassin check (if enabled) on a specific message.
The message database ID. Defaults to latest to return the latest message.
The SpamAssassin summary (if enabled)
Waits for at least one message matching a search query, then returns the latest matching message.
The search request containing the query and optional parameters.
Optionaloptions: MailpitWaitForMessageRequestOptional timeout and interval settings.
The full message summary of the latest matching message.
Polls the searchMessages() API at a configurable interval until at least one message is found, then retrieves the full message details via getMessageSummary(). The promise will reject if the timeout is reached before a matching message is found.
Waits for a specific number of messages to exist, optionally matching a search query.
Optionaloptions: MailpitWaitForMessageRequestOptional timeout and interval settings.
The message list response that satisfied the count condition.
Polls the searchMessages() (if search is provided) or listMessages() API at a configurable interval until the count condition is met. The promise will reject if the timeout is reached before the condition is satisfied.
By default, resolves when messages_count >= count. Set exact: true to require messages_count === count.
When count is 0, always uses exact match (messages_count === 0) regardless of the exact option.
const response = await mailpit.waitForMessages({ query: "to:user@example.test", count: 2 });
console.log(response.messages_count); // 2 or more
const response = await mailpit.waitForMessages({ query: "from:example.test", count: 3, exact: true });
console.log(response.messages_count); // 3
await mailpit.deleteMessages();
const response = await mailpit.waitForMessages({ count: 0 });
console.log(response.messages_count); // 0
Waits for a specific number of messages to exist, optionally matching a search query.
Optionaloptions: MailpitWaitForMessageRequestOptional timeout and interval settings.
The message list response that satisfied the count condition.
Polls the searchMessages() (if search is provided) or listMessages() API at a configurable interval until the count condition is met. The promise will reject if the timeout is reached before the condition is satisfied.
By default, resolves when messages_count >= count. Set exact: true to require messages_count === count.
When count is 0, always uses exact match (messages_count === 0) regardless of the exact option.
const response = await mailpit.waitForMessages({ query: "to:user@example.test", count: 2 });
console.log(response.messages_count); // 2 or more
const response = await mailpit.waitForMessages({ query: "from:example.test", count: 3, exact: true });
console.log(response.messages_count); // 3
await mailpit.deleteMessages();
const response = await mailpit.waitForMessages({ count: 0 });
console.log(response.messages_count); // 0
Client for interacting with the Mailpit API.
Example