Inboxes Management
Relevant source files
The following files were used as context for generating this wiki page:
Inboxes Management provides a structured system for handling incoming communications and internal workflows. It allows you to create dedicated email addresses, manage message threads, organize communications with labels, and utilize automated agents for drafting or labeling.
This module is organized into several sub-resources: Threads, Labels, Drafts, and Agents. Each sub-resource handles specific aspects of the inbox lifecycle, from receiving an email to managing responses and organization.
Sources: src/inboxes/inboxes.ts:36-41, src/inboxes/inboxes.ts:44-49
Core Architecture
The Inboxes class acts as the primary entry point. It initializes and provides access to specialized sub-managers for threads, labels, drafts, and agents.
The diagram shows the hierarchical structure of the Inboxes module and its child components.
Sources: src/inboxes/inboxes.ts:36-41, src/inboxes/threads/threads.ts:33-35
Inbox Operations
You perform basic management tasks such as creating, retrieving, and listing inboxes through the main Inboxes class.
Key Operations Table
| Operation | Method | Description |
|---|---|---|
| Create | create() | Generates a new inbox with a specific email address and name. |
| List | list() | Returns a paginated list of all inboxes. |
| Get | get() | Retrieves details for a specific inbox using an ID or email address. |
| Update | update() | Modifies the name or "from" name of an existing inbox. |
| Remove | remove() | Deletes an inbox and its associated data. |
Sources: src/inboxes/inboxes.ts:51-109, src/inboxes/inboxes.spec.ts:161-163
Thread and Email Management
The InboxThreads class manages conversations within an inbox. Threads group related emails together, providing a unified view of a communication sequence.
Thread Searching and Filtering
The search method allows you to filter threads using various parameters, including:
- Query: Search text within subject or body.
- Folders: Filter by folder names (e.g., 'inbox', 'archive').
- Labels: Filter by specific label IDs.
- Metadata: Filter by
readstatus, date ranges, or the presence of attachments.
Sources: src/inboxes/threads/threads.ts:56-102, src/inboxes/threads/threads.spec.ts:101-137
Email Interactions
The InboxThreadEmails class manages individual messages within a thread. It supports retrieving message lists, getting specific email details, replying, and forwarding.
The sequence diagram illustrates the flow for replying to an email within a specific inbox thread.
Sources: src/inboxes/threads/emails/emails.ts:54-82, src/inboxes/threads/emails/emails.spec.ts:133-149
Draft Management
InboxDrafts manages unsent messages. Drafts can be standalone or attached to an existing thread as a reply.
- Creation: You create a draft by specifying an
inboxId. If replying, you must providethreadIdandreplyToEmailId. - Attachments: The system supports attachments. During creation or update, the SDK parses these into the correct API format.
- Sending: Once ready, the
send()method converts a draft into a live email.
Sources: src/inboxes/drafts/drafts.ts:46-118, src/inboxes/drafts/interfaces/create-inbox-draft.interface.ts:11-36
Labels and Automation
Labels allow for manual and automated categorization of threads. The InboxLabels class handles CRUD operations for label entities, which include a name and a hex color code.
Inbox Agent
The InboxAgent manages automated behaviors. You configure instructions and tones for the agent to perform specific actions.
- Instructions: Text-based guidance for the agent's behavior.
- Tone: Preset styles like
concise_casualorconcise_professional. - Enabled Actions: Capabilities such as
draft_replyoradd_labels.
Sources: src/inboxes/labels/labels.ts:25-71, src/inboxes/agent/agent.spec.ts:27-33, src/inboxes/agent/agent.spec.ts:59-67
Conclusion
Inboxes Management provides a complete toolkit for building sophisticated email-based workflows. By combining thread management, organized labeling, draft handling, and automated agents, the system enables efficient communication handling and automation within the Resend ecosystem.