Inbox & Threads Management
Relevant source files
The following files were used as context for generating this wiki page:
The Inbox and Threads Management system provides a comprehensive API for handling incoming and outgoing communications within a domain. It allows developers to create dedicated inboxes, manage conversation threads, organize emails with labels, and handle drafts for streamlined communication workflows.
This system centralizes email interactions into "Inboxes," which contain "Threads" consisting of multiple "Emails." Users can also configure automated agents and apply custom labels to categorize content.
Sources: inboxes.go:132-137, examples/inboxes.go:20-50
Core Components and Architecture
The system follows a hierarchical structure where an Inbox acts as the primary container. Each Inbox can contain multiple Threads, and each Thread contains one or more Emails.
Component Relationship
The following diagram illustrates the relationship between inboxes, threads, emails, and drafts.
The diagram shows that an Inbox is the parent entity for threads, drafts, and labels. Threads are further composed of individual emails.
Sources: inboxes.go:132-140, inbox_drafts.go:37-56
Data Structures
The primary data structures used for management include:
| Structure | Description | Key Fields |
|---|---|---|
Inbox | Represents a communication endpoint. | Id, EmailAddress, Unread, Drafts |
InboxThread | Represents a grouped conversation. | Id, Subject, Folder, EmailCount |
InboxDraft | Represents an unsent email message. | Id, Type, ThreadId, Subject |
InboxLabel | Represents a tag for categorization. | Id, Name, Color |
Sources: inboxes.go:34-51, inbox_drafts.go:37-56, inbox_threads_test.go:15-28
Inbox Operations
Inboxes are created on specific domains to receive and send emails. Resend can provision a receiving address automatically if forwarding is enabled.
Creating an Inbox
When you create an inbox, you must provide an EmailAddress. Optional fields include Name, FromName, and Forwarding.
created, err := client.Inboxes.Create(&resend.CreateInboxRequest{
EmailAddress: "support@acme.com",
Name: "Customer Support",
FromName: "Ada from Support",
Forwarding: true,
})
Sources: inboxes.go:68-79, examples/inboxes.go:20-25
Inbox Management Functions
- List: Retrieves all inboxes for a team, sorted newest first. Sources: inboxes.go:167-175
- Get: Retrieves details for a specific inbox using either its ID or email address. Sources: inboxes.go:189-204
- Update: Modifies the internal name or the name recipients see. Sources: inboxes.go:214-232
- Remove: Deletes an inbox. Deletion returns a 404 if the inbox does not exist. Sources: inboxes.go:242-259
Thread and Email Management
Threads organize related emails. The system allows moving threads between folders and searching through conversation history.
Folder Structure
Threads are categorized into specific folders:
inbox: Active incoming messages.archive: Completed conversations.spam: Unwanted messages.trash: Messages scheduled for deletion in 30 days.sent: Automatically assigned to outgoing messages.
Sources: inboxes.go:10-27, examples/inboxes.go:146-150
Thread Lifecycle
The following sequence diagram shows the process of receiving an email, replying with a draft, and archiving the thread.
The diagram represents the standard workflow of handling a thread from arrival to archival.
Sources: examples/inboxes.go:81-125, inbox_drafts.go:351-382
Email Interactions
Users can interact with specific emails within a thread via three primary actions:
- Get: Retrieve the full content of an email, including HTML, text, and attachments. Sources: inbox_thread_emails_test.go:66-78
- Reply: Send a response to the original sender or all recipients. Sources: inbox_thread_emails_test.go:86-107
- Forward: Send the email content to new recipients. Sources: inbox_thread_emails_test.go:126-146
Draft Management
Drafts allow users to prepare content before sending. Drafts are classified as either standalone (starting a new thread) or reply (responding within an existing thread).
Draft Properties
- Idempotency: Drafts can be created and sent with an
IdempotencyKeyto prevent duplicate operations. Sources: inbox_drafts.go:123-131, inbox_drafts.go:243-255 - Content: At least one content field (
To,Subject,Text,Html, orAttachments) must be non-empty. Sources: inbox_drafts.go:310-312 - Attachments: Draft attachments must include
Content,Filename, andContentType. They cannot exceed a total of 25 MB. Sources: inbox_drafts.go:94-106
Update and Send Logic
Updating a draft with Text or Html replaces the entire body; omitted parts become null. When sending a draft, it must have a recipient, a subject, and a body, otherwise the API returns a 422 error.
Sources: inbox_drafts.go:204-209, inbox_drafts.go:351-356
Labeling and Categorization
Labels are named, colored tags used to organize threads within an inbox.
- Creation: Labels are defined per inbox with a name and hex color code. Sources: inbox_labels_test.go:50-62
- Assignment: Multiple labels can be added to or set on a thread. Sources: inbox_thread_labels_test.go:22-34
- Removal: Labels can be removed from a specific thread or deleted from the inbox entirely. Sources: inbox_thread_labels_test.go:95-108, inbox_labels_test.go:103-116
Summary
The Inbox & Threads Management system provides the necessary infrastructure to build complex email clients or automated support systems. By leveraging the hierarchical relationship between inboxes, threads, and emails, along with robust draft and label support, developers can maintain organized and reliable communication channels.
Sources: examples/inboxes.go:14-160, inboxes.go:132-140