Read and organize conversations
Find mailbox conversations, read their messages, and organize shared work with folders, labels, and internal notes.
Use this guide to find a conversation, read enough to act, and leave it organized for the next
person or agent. Start with an existing mailbox and a client authenticated for that mailbox.
Agents and keys explains access: reading needs read, and
changing threads or adding notes needs update. Creating or changing mailbox labels needs
mailbox management access.
Find the conversation
List threads, optionally narrowing by folder, search, label, or your own unread state.
A thread's folder is one of inbox, assigned, pending, sent, archived, trash, or
spam. Inbound mail starts a thread in inbox, and a thread you start with a send starts in
sent. A later reply does not move it: a reply to a thread you started arrives in a thread whose
folder is still sent, so folder: "inbox" does not list it. Omit folder to list every folder
except Spam, and pass unread: true to find threads with new replies. Spam
explains who can list it.
deliveredTo is the mailbox address that received the thread's first inbound email, including
any plus tag (for example, support+billing@acme.com). It stays the same when replies arrive.
It is null for sent-only threads, chat threads, and email with no known receiving address.
Thread lists return summaries with a subject, preview, sender, and current state, without message
bodies.
import { createClient } from "samva";
const samva = createClient({ apiKey: process.env.SAMVA_API_KEY! });
const id = "mbx_...";
for await (const thread of samva.mailboxes.listThreads.items({
id,
folder: "inbox",
unread: true,
})) {
console.log(thread.id, thread.subject, thread.preview);
}The iterator fetches each page as needed. Threads are ordered by most recent activity. A conversation that gains activity during a walk can move ahead of your cursor;
refresh the list to see new activity rather than treating a completed walk as a fixed snapshot.
For polling, after and before filter by last activity. See
list threads for the filters.
The inbox hides your snoozed threads by default. Pass snoozed: true to find threads you have
snoozed, or snoozed: false to exclude them explicitly from another view.
Search conversations
Pass q to listThreads or listOrganizationThreads to find conversations by meaning and
keywords in subjects, participants, message text, and attachment filenames. Quoted history is
included; attachment contents are not searched. A filename in q is free text, not an exact
filename filter.
import { createClient } from "samva";
const samva = createClient({ apiKey: process.env.SAMVA_API_KEY! });
const page = await samva.mailboxes.listOrganizationThreads({
q: "customer asking to reschedule a delivery",
state: "active",
limit: 20,
});
for (const thread of page.items) {
console.log(thread.mailbox.address, thread.subject);
}Search returns the best-matching threads in relevance order. Other filters narrow that result
set. Follow nextCursor for another page of the original ranked set; see
list threads for its result limit. Omit q to list
by most recent activity, including when you use filters alone.
New matches do not reshuffle the remaining pages. Deleted matches and mailboxes you can no longer read drop out. Keep the same search text and mailbox scope when paging; start a new search when those change.
New mail can take a few seconds to become searchable. A message's searchable text is bounded, so text near the end of a long message may not match. Search includes only mail your credential can read. It is included on every plan, with no separate search usage charge.
Work across mailboxes
Use listOrganizationThreads to list conversations across mailboxes your credential can read.
Each summary includes mailbox, with its id, address, and kind. Filter by mailboxId to
select mailboxes, by kind for personal or shared, by state for active or done, or by
conversation for the threads one conversation has in the mailboxes you can read. The other thread
filters and cursor pagination work as on a single mailbox.
import { createClient } from "samva";
const samva = createClient({ apiKey: process.env.SAMVA_API_KEY! });
const page = await samva.mailboxes.listOrganizationThreads({ state: "active", limit: 20 });
for (const thread of page.items) {
console.log(thread.mailbox.address, thread.subject);
}For an HTTP request, repeat mailboxId for each selected mailbox and bound the page with limit:
curl 'https://api.samva.dev/v1/mailboxes/threads?mailboxId=mbx_first&mailboxId=mbx_second&state=active&limit=20' \
-H "X-API-Key: $SAMVA_API_KEY"An active view excludes what you finished. The Done view includes conversations you marked Done,
closed shared conversations, and archived conversations in your personal mailboxes, each once.
Your Done flag is private; Close puts the shared conversation in Done for every reader.
Omit state to list conversations regardless of Done or Close.
See list conversations across mailboxes.
Find mail needing your decision
Get needs-you lists held actions you may approve across
readable mailboxes. Each item gives the mailbox, action type, decision, and any tool call or send
intent. Follow nextCursor for the next page. Use the mailbox and action ID to
review the action.
Read the messages
getThread gives you participants and thread state. listThreadMessages gives message summaries.
Use getThreadContent when you need bodies, or getMessage for one message.
import { createClient } from "samva";
const samva = createClient({ apiKey: process.env.SAMVA_API_KEY! });
const id = "mbx_7q2xk9mvt4znw8rh";
const threadId = "thread_...";
const thread = await samva.mailboxes.getThread({ id, threadId });
console.log(thread.subject, thread.participants);
let contentCursor: string | undefined;
do {
const page = await samva.mailboxes.getThreadContent({ id, threadId, cursor: contentCursor });
for (const message of page.items) {
if (message.channel === "email") {
console.log(message.id, message.replyText ?? message.text, message.attachments);
}
}
contentCursor = page.nextCursor ?? undefined;
} while (contentCursor !== undefined);From a thread to its messages
A thread's id is not a message ID, and getThread returns no message list. List the messages to
get the id that getMessage, reply, replyAll, and forward take. Each item of
listThreadMessages and getThreadContent carries it as id.
| Surface | Message summaries | Bodies |
|---|---|---|
| REST | GET /v1/mailboxes/{id}/threads/{threadId}/messages | GET /v1/mailboxes/{id}/threads/{threadId}/content |
| SDK | samva.mailboxes.listThreadMessages | samva.mailboxes.getThreadContent |
| CLI | samva mailboxes list-thread-messages <mailbox-id> <thread-id> | samva mailboxes get-thread-content <mailbox-id> <thread-id> |
| MCP | mailbox_thread_get returns the thread and a page of its messages | the same call; each message carries id |
curl "https://api.samva.dev/v1/mailboxes/$MAILBOX_ID/threads/$THREAD_ID/messages" \
-H "X-API-Key: $SAMVA_API_KEY"Message summaries and content both paginate oldest first. Email content includes text, sanitized
html, and replyText when available; replyText removes quoted history. Attachments are metadata,
not file bytes. Use get an attachment to
obtain a download URL and check its expiresAt before using it. See
read thread content for the full response.
A WhatsApp thread holds chat messages: text, media metadata, the template a message was
sent as, and contextMessageId, with no subject or headers. getThread on a WhatsApp thread also
returns whatsappServiceWindow, { open, expiresAt }, which says whether free-form text can be
sent now. See Answer WhatsApp in a mailbox.
Organize shared work and your own view
Folders, priority, and labels are shared with everyone on the mailbox. Your read, star, snooze, and Done state belong to you: marking a thread read does not mark it read for another person or API key. Reading content and marking it read are separate actions. A new inbound message, or a message restored from Spam, marks the thread unread for every reader except the one who released it; a sent message leaves everyone's read state as it is.
await samva.mailboxes.updateThread({
id,
threadId,
folder: "pending",
priority: "high",
read: true,
starred: true,
});
// Wake a snoozed thread in your own view.
await samva.mailboxes.updateThread({ id, threadId, snoozedUntil: null });A partial update keeps fields you omit. To snooze, pass an ISO timestamp as snoozedUntil; the
thread wakes when that time passes. Archiving or moving to trash changes the shared folder.
See update a thread for the supported states.
Done and Close
Set done: true when you have finished your part. Set done: false to return the conversation to
your active view. The response's doneAt records your Done state.
On a shared mailbox, closed: true closes the conversation for everyone. closedAt and closedBy
record when and by whom it was closed. It appears in every reader’s Done view, even if their own
doneAt is null. Changing done does not reopen it. Set closed: false to reopen it. A personal mailbox refuses
closed with ValidationError; use folder: "archived" to archive a personal conversation. Mail's
Done button writes exactly this: done: true in a shared mailbox, folder: "archived" in a personal one.
await samva.mailboxes.updateThread({ id, threadId, done: true });
await samva.mailboxes.updateThread({ id, threadId, closed: true });A new inbound message, a message restored from Spam, or a newly sent message clears Done for every reader and reopens a closed conversation. Duplicate deliveries and older message history do not change these states. Done and Close changes emit no webhook or event-stream events; read the thread state or refresh the active view to observe them.
Create a label once, then use its ID on any thread in that mailbox:
const label = await samva.mailboxes.createLabel({
id,
slug: "needs-follow-up",
displayName: "Needs follow-up",
});
await samva.mailboxes.addThreadLabels({ id, threadId, labels: [label.id] });Adding labels preserves existing labels. Use removeThreadLabels to remove selected labels;
updateThread does not replace them. A label must belong to the same mailbox. Deleting a label
removes it from every thread that carries it. See
create a label for mailbox label limits.
Leave context for the next reader
An internal note is visible to everyone on the mailbox and is never emailed to recipients.
await samva.mailboxes.createNote({
id,
threadId,
body: "Waiting for the customer to confirm the delivery address.",
pinned: true,
});Read notes with listThreadNotes, following nextCursor as with messages. Only a note's author
can edit or delete it. To answer the customer instead, follow
Compose and send.
Read in Samva Mail without a connection
Samva Mail keeps the conversations you open on the device you read them on. Once you have opened
Mail there while online, it opens at /mail with no connection and shows what it last downloaded.
Reads, Done, Close, stars, snoozes, labels, and drafts you change offline are saved on the device
and sent when the connection returns; replies wait in the Outbox until then.
Mail opens offline only for the person who last signed in on that browser, and only for organizations they opened there. After a long time without connecting, Mail asks you to sign in again before it opens. Signing out removes the downloaded mail, any changes not yet sent, and the offline copy of Mail from the browser.
Browsers that install web apps offer Samva Mail as its own app, which opens straight into Mail. When a new version of Mail is ready, Mail offers Reload; nothing changes under a reply you are writing until you choose it.