### Kotest Example Test Source: https://github.com/mattbobambrose/agentmail4k/blob/master/CLAUDE.md An example test case using Kotest with StringSpec style. This demonstrates the basic structure for writing tests within the project. ```kotlin class ExampleTest : StringSpec() { init { "should do something" { // test body } } } ``` -------------------------------- ### Quick Start with AgentMailClient Source: https://github.com/mattbobambrose/agentmail4k/blob/master/README.md Initialize the client, create an inbox, and send a message using the DSL. ```kotlin suspend fun quickStart() { val client = AgentMailClient() // Create an inbox val inbox = client.createInbox("support", "example.com", "Support Team") println("Created inbox: ${inbox.email}") // Send a message val response = client.sendMessage { from = inbox.inboxId to = listOf("user@example.com") subject = "Hello from AgentMail!" text = "This is a test message sent with agentmail4k." } println("Sent message: ${response.messageId}" client.close() } ``` -------------------------------- ### Get a Domain Source: https://github.com/mattbobambrose/agentmail4k/blob/master/website/agentmail/docs/domains.md Fetches details for a specific domain by its identifier. ```kotlin --8<-- "Domains.kt:get-domain" ``` -------------------------------- ### Webhook Handler Implementation Source: https://github.com/mattbobambrose/agentmail4k/blob/master/website/agentmail/docs/webhooks.md Provides examples for handling incoming webhook events and custom event routing. ```kotlin --8<-- "Webhooks.kt:webhook-handler" ``` ```kotlin --8<-- "Webhooks.kt:webhook-handler-custom" ``` -------------------------------- ### Get an Entry Source: https://github.com/mattbobambrose/agentmail4k/blob/master/website/agentmail/docs/lists.md Retrieves a specific entry from the lists. ```kotlin --8<-- "Lists.kt:get-entry" ``` -------------------------------- ### Install agentmail4k via Gradle Source: https://github.com/mattbobambrose/agentmail4k/blob/master/README.md Add the dependency to your project using Kotlin DSL or Groovy. ```kotlin dependencies { implementation("com.agentmail4k:agentmail4k:0.1.0") } ``` ```groovy dependencies { implementation 'com.agentmail4k:agentmail4k:0.1.0' } ``` -------------------------------- ### Get Zone File Source: https://github.com/mattbobambrose/agentmail4k/blob/master/website/agentmail/docs/domains.md Retrieves the DNS zone file configuration for a specific domain. ```kotlin --8<-- "Domains.kt:zone-file" ``` -------------------------------- ### Get a Webhook Source: https://github.com/mattbobambrose/agentmail4k/blob/master/website/agentmail/docs/webhooks.md Fetches details for a specific webhook by its identifier. ```kotlin --8<-- "Webhooks.kt:get-webhook" ``` -------------------------------- ### Configure Auto-Reply Rules Source: https://github.com/mattbobambrose/agentmail4k/blob/master/llms-full.txt Defines the AutoReplyBuilder DSL for setting reply rules and default actions, and the autoReply function for starting the monitor. ```kotlin /** DSL builder for configuring automatic reply rules with match conditions and reply actions. */ class AutoReplyBuilder { var pollInterval: Duration /** Adds an auto-reply rule that replies when the [match] predicate returns true. */ fun rule( match: (Message) -> Boolean, reply: ReplyBuilder.(Message) -> Unit, ) /** Sets the default reply action for messages that don't match any rule. */ fun default(reply: ReplyBuilder.(Message) -> Unit) } /** Starts an auto-reply monitor on the given inbox that automatically replies to incoming messages based on configured rules. */ fun AgentMailClient.autoReply( inboxId: String, scope: CoroutineScope = CoroutineScope(Dispatchers.Default + SupervisorJob()), block: AutoReplyBuilder.() -> Unit, ): Job ``` -------------------------------- ### Setup Auto-Reply Workflow in Kotlin Source: https://context7.com/mattbobambrose/agentmail4k/llms.txt Configure automatic email replies with custom rules and a default fallback. The auto-reply job runs for a specified duration and can be cancelled. ```kotlin import com.agentmail4k.sdk.AgentMailClient import com.agentmail4k.dsl.autoReply import kotlinx.coroutines.delay import kotlin.time.Duration.Companion.minutes import kotlin.time.Duration.Companion.seconds suspend fun setupAutoReply() { val client = AgentMailClient() val inboxId = "inbox_abc123" val autoReplyJob = client.autoReply(inboxId) { pollInterval = 5.seconds // Rule: Reply to support requests rule( match = { msg -> msg.subject?.contains("support", ignoreCase = true) == true }, reply = { msg -> text = """ Thank you for contacting support! Your request regarding "${msg.subject}" has been received. A support agent will respond within 24 hours. Reference: ${msg.messageId} """.trimIndent() } ) // Rule: Auto-acknowledge orders rule( match = { msg -> msg.from.endsWith("@orders.example.com") }, reply = { msg -> text = "Order confirmation received. Processing..." html = "

Order confirmation received. Processing...

" } ) // Rule: Out of office for specific senders rule( match = { msg -> msg.labels.contains("vip") }, reply = { msg -> text = "Thank you for your message. I'm currently out of office and will respond upon my return." } ) // Default reply for unmatched messages default { msg -> text = "Thank you for your email. We'll get back to you soon." } } // Run auto-reply for 1 hour delay(1.minutes) autoReplyJob.cancel() client.close() } ``` -------------------------------- ### Get a Pod in Kotlin Source: https://github.com/mattbobambrose/agentmail4k/blob/master/website/agentmail/docs/pods.md Fetches details for a specific pod by its identifier. ```kotlin --8<-- "Pods.kt:get-pod" ``` -------------------------------- ### Get a Draft in Kotlin Source: https://github.com/mattbobambrose/agentmail4k/blob/master/website/agentmail/docs/drafts.md Fetches details for a specific draft by its identifier. ```kotlin --8<-- "Drafts.kt:get-draft" ``` -------------------------------- ### Pod Scope Example Source: https://github.com/mattbobambrose/agentmail4k/blob/master/website/agentmail/docs/scoped-access.md Obtain a scoped view of a pod's resources using `client.pods(podId)`. This is beneficial for executing multiple operations on the same pod. ```kotlin val pod = client.pods("pod-456") val runs = pod.runs().list() val tasks = pod.tasks().list() ``` -------------------------------- ### GET /metrics Source: https://github.com/mattbobambrose/agentmail4k/blob/master/website/agentmail/docs/metrics.md Retrieves email metrics for the authenticated account. ```APIDOC ## GET /metrics ### Description Retrieve email metrics for your account. ### Method GET ### Endpoint /metrics ``` -------------------------------- ### Get Raw Message in Kotlin Source: https://github.com/mattbobambrose/agentmail4k/blob/master/website/agentmail/docs/messages.md Retrieves the raw RFC 822 formatted email content. ```kotlin --8<-- "Messages.kt:raw-message" ``` -------------------------------- ### Get a Thread Source: https://github.com/mattbobambrose/agentmail4k/blob/master/website/agentmail/docs/threads.md Fetches a specific thread by its ID. Use this to access the details of a particular conversation. ```kotlin --8<-- "Threads.kt:get-thread" ``` -------------------------------- ### Configure Inbox Monitoring Source: https://github.com/mattbobambrose/agentmail4k/blob/master/llms-full.txt Defines the MonitorBuilder DSL for setting polling intervals and message handlers, and the monitor function for starting the polling coroutine. ```kotlin /** DSL builder for configuring inbox monitoring with message handlers, error handlers, and polling settings. */ class MonitorBuilder { var pollInterval: Duration var includeSpam: Boolean var includeBlocked: Boolean /** Sets the handler invoked for each new message (preview content only). */ fun onMessage(handler: suspend (Message) -> Unit) /** Sets the handler invoked for each new message (fetches full content). */ fun onFullMessage(handler: suspend (Message) -> Unit) /** Sets the handler invoked when a polling error occurs. */ fun onError(handler: suspend (Throwable) -> Unit) } /** Starts a coroutine that polls an inbox for new messages and invokes handlers. */ fun AgentMailClient.monitor( inboxId: String, scope: CoroutineScope = CoroutineScope(Dispatchers.Default + SupervisorJob()), block: MonitorBuilder.() -> Unit, ): Job ``` -------------------------------- ### Inbox Scope Example Source: https://github.com/mattbobambrose/agentmail4k/blob/master/website/agentmail/docs/scoped-access.md Obtain a scoped view of an inbox's resources using `client.inboxes(inboxId)`. This is useful when performing multiple operations on the same inbox. ```kotlin val inbox = client.inboxes("inbox-123") val messages = inbox.messages().list() val threads = inbox.threads().list() val drafts = inbox.drafts().list() ``` -------------------------------- ### Create a Domain Source: https://github.com/mattbobambrose/agentmail4k/blob/master/website/agentmail/docs/domains.md Initializes a new custom domain for email operations. ```kotlin --8<-- "Domains.kt:create-domain" ``` -------------------------------- ### Initialize AgentMail Client Source: https://github.com/mattbobambrose/agentmail4k/blob/master/website/agentmail/docs/getting-started.md Methods for instantiating the client using environment variables or explicit configuration. ```kotlin --8<-- "GettingStarted.kt:create-client-env" ``` ```kotlin --8<-- "GettingStarted.kt:create-client-explicit" ``` -------------------------------- ### GET /organization Source: https://github.com/mattbobambrose/agentmail4k/blob/master/website/agentmail/docs/metrics.md Retrieves information about the user's organization. ```APIDOC ## GET /organization ### Description Retrieve your organization information. ### Method GET ### Endpoint /organization ``` -------------------------------- ### Manage Custom Domains with Kotlin Source: https://context7.com/mattbobambrose/agentmail4k/llms.txt Covers domain registration, DNS zone file retrieval, verification, and lifecycle management. ```kotlin import com.agentmail4k.sdk.AgentMailClient suspend fun manageDomains() { val client = AgentMailClient() // Create a custom domain val domain = client.domains.create { name = "mycompany.com" } println("Created domain: ${domain.domainId}") println("Status: ${domain.status}") // List all domains val domains = client.domains.list { limit = 10 ascending = true } domains.domains.forEach { d -> println("${d.name}: ${d.status}") } // Get domain details val retrieved = client.domains.get(domain.domainId) // Get DNS zone file for configuration val zoneFile = client.domains.getZoneFile(domain.domainId) println("Zone file:\n${String(zoneFile)}") // Trigger DNS verification client.domains.verify(domain.domainId) // Update domain val updated = client.domains.update(domain.domainId) { name = "newdomain.com" } // Delete domain client.domains.delete(domain.domainId) client.close() } ``` -------------------------------- ### GET /metrics/period Source: https://github.com/mattbobambrose/agentmail4k/blob/master/website/agentmail/docs/metrics.md Query metrics at different time granularities. ```APIDOC ## GET /metrics/period ### Description Query metrics at different time granularities. ### Method GET ### Endpoint /metrics/period ### Parameters #### Query Parameters - **Period** (string) - Required - The granularity of the metrics: HOUR, DAY, WEEK, or MONTH. ``` -------------------------------- ### Run Tests and Generate Documentation Source: https://github.com/mattbobambrose/agentmail4k/blob/master/README.md Commands to execute tests and generate KDoc documentation locally. ```bash ./gradlew test ``` ```bash ./gradlew dokkaGenerate ``` -------------------------------- ### Create a Pod in Kotlin Source: https://github.com/mattbobambrose/agentmail4k/blob/master/website/agentmail/docs/pods.md Initializes a new pod resource within the workspace. ```kotlin --8<-- "Pods.kt:create-pod" ``` -------------------------------- ### Configure Client Settings Source: https://github.com/mattbobambrose/agentmail4k/blob/master/llms-full.txt Customize client behavior including defaults, timeouts, and retry logic. ```kotlin --8<-- "Configuration.kt:full-config" ``` ```kotlin --8<-- "Configuration.kt:defaults" ``` ```kotlin --8<-- "Configuration.kt:timeout-config" ``` ```kotlin --8<-- "Configuration.kt:retry-config" ``` -------------------------------- ### Get a Thread Source: https://github.com/mattbobambrose/agentmail4k/blob/master/website/agentmail/docs/threads.md Retrieves the details of a specific email thread by its identifier. ```APIDOC ## GET /threads/{threadId} ### Description Fetches the full details of a specific thread. ### Method GET ### Endpoint /threads/{threadId} ### Parameters #### Path Parameters - **threadId** (string) - Required - The unique identifier of the thread. ``` -------------------------------- ### Configure AgentMailClient Source: https://github.com/mattbobambrose/agentmail4k/blob/master/README.md Initialize the client using environment variables or explicit configuration settings. ```kotlin // From environment (reads AGENTMAIL_API_KEY) val client = AgentMailClient() // Explicit API key with custom settings val client = AgentMailClient { apiKey = "your-api-key" baseUrl = "https://api.agentmail.to" timeout { connect = 10.seconds request = 30.seconds } retry { maxRetries = 3 retryOnServerErrors = true } } ``` -------------------------------- ### Configure AgentMailClient with full settings Source: https://github.com/mattbobambrose/agentmail4k/blob/master/website/agentmail/docs/configuration.md Use the DSL builder to define all available configuration options for the client. ```kotlin --8<-- "Configuration.kt:full-config" ``` -------------------------------- ### AgentMailClient Initialization Source: https://github.com/mattbobambrose/agentmail4k/blob/master/llms-full.txt The main entry point for the SDK, used to configure and instantiate the client. ```APIDOC ## AgentMailClient Initialization ### Description Creates a new instance of the AgentMailClient using a DSL builder for configuration. ### Parameters #### Request Body - **apiKey** (String) - Optional - The API key for authentication. - **baseUrl** (String) - Optional - The base URL for the API. - **timeout** (TimeoutBuilder) - Optional - Configuration for connect, request, and socket timeouts. - **retry** (RetryBuilder) - Optional - Configuration for retry behavior including max retries and server error handling. ``` -------------------------------- ### Configure AgentMailClient in Kotlin Source: https://context7.com/mattbobambrose/agentmail4k/llms.txt Initialize the AgentMailClient with API key, base URL, timeouts, and retry settings. Reads AGENTMAIL_API_KEY from environment if not explicitly provided. Ensure the client is closed when no longer needed. ```kotlin import com.agentmail4k.sdk.AgentMailClient import kotlin.time.Duration.Companion.seconds // Simple initialization (reads AGENTMAIL_API_KEY from environment) val client = AgentMailClient() // Full configuration with DSL val client = AgentMailClient { apiKey = "your-api-key" baseUrl = "https://api.agentmail.to" timeout { connect = 10.seconds request = 30.seconds socket = 30.seconds } retry { maxRetries = 3 retryOnServerErrors = true } } // Always close the client when done client.close() ``` -------------------------------- ### InboxResource Operations Source: https://github.com/mattbobambrose/agentmail4k/blob/master/llms-full.txt Operations for managing inboxes including list, create, get, update, and delete. ```kotlin /** Provides operations for managing inboxes: list, create, get, update, and delete. */ class InboxResource { /** Lists inboxes with optional pagination. */ suspend fun list(block: ListInboxesBuilder.() -> Unit = {}): InboxList /** Creates a new inbox. */ suspend fun create(block: CreateInboxBuilder.() -> Unit = {}): Inbox /** Retrieves an inbox by ID. */ suspend fun get(inboxId: String): Inbox /** Updates an inbox by ID. */ suspend fun update(inboxId: String, block: UpdateInboxBuilder.() -> Unit): Inbox /** Deletes an inbox by ID. */ suspend fun delete(inboxId: String) } ``` -------------------------------- ### Basic Webhook Handler Source: https://github.com/mattbobambrose/agentmail4k/blob/master/llms-full.txt The SDK includes a basic webhook handler that verifies signatures and routes events. Ensure `signingSecret` is set for automatic verification. ```kotlin --8<-- "Webhooks.kt:webhook-handler" ``` -------------------------------- ### Create a Draft in Kotlin Source: https://github.com/mattbobambrose/agentmail4k/blob/master/website/agentmail/docs/drafts.md Initializes a new draft message within the system. ```kotlin --8<-- "Drafts.kt:create-draft" ``` -------------------------------- ### Monitor Inbox Source: https://github.com/mattbobambrose/agentmail4k/blob/master/llms-full.txt Configures and starts a coroutine to poll an inbox for new messages with custom handlers. ```APIDOC ## AgentMailClient.monitor ### Description Starts a coroutine that polls an inbox for new messages and invokes handlers based on the MonitorBuilder configuration. ### Parameters #### Path Parameters - **inboxId** (String) - Required - The unique identifier of the inbox to monitor. #### Request Body (MonitorBuilder) - **pollInterval** (Duration) - Optional - Frequency of polling. - **includeSpam** (Boolean) - Optional - Whether to include spam messages. - **includeBlocked** (Boolean) - Optional - Whether to include blocked messages. - **onMessage** (Function) - Optional - Handler for new message previews. - **onFullMessage** (Function) - Optional - Handler for full message content. - **onError** (Function) - Optional - Handler for polling errors. ``` -------------------------------- ### List Webhooks Source: https://github.com/mattbobambrose/agentmail4k/blob/master/website/agentmail/docs/webhooks.md Retrieves a list of all configured webhooks. ```kotlin --8<-- "Webhooks.kt:list-webhooks" ``` -------------------------------- ### Manage Webhooks with Kotlin Source: https://context7.com/mattbobambrose/agentmail4k/llms.txt Shows how to configure webhooks to receive real-time notifications for specific email events. ```kotlin import com.agentmail4k.sdk.AgentMailClient import com.agentmail4k.sdk.model.WebhookEvent suspend fun manageWebhooks() { val client = AgentMailClient() // Create a webhook with specific events val webhook = client.webhooks.create { url = "https://myapp.com/webhooks/email" events( WebhookEvent.MESSAGE_RECEIVED, WebhookEvent.MESSAGE_SENT, WebhookEvent.MESSAGE_DELIVERED, WebhookEvent.MESSAGE_BOUNCED ) } println("Created webhook: ${webhook.webhookId}") // List all webhooks val webhooks = client.webhooks.list { limit = 10 } webhooks.webhooks.forEach { w -> println("${w.webhookId}: ${w.url}") println(" Events: ${w.events}") } // Update webhook URL and events val updated = client.webhooks.update(webhook.webhookId) { url = "https://myapp.com/webhooks/v2/email" events( WebhookEvent.MESSAGE_RECEIVED, WebhookEvent.MESSAGE_BOUNCED, WebhookEvent.MESSAGE_COMPLAINED, WebhookEvent.DOMAIN_VERIFIED ) } // Delete webhook client.webhooks.delete(webhook.webhookId) client.close() } ``` -------------------------------- ### Get an Inbox Source: https://github.com/mattbobambrose/agentmail4k/blob/master/website/agentmail/docs/inboxes.md Fetch details for a specific inbox using its unique identifier. This is useful for retrieving the current state or configuration of an inbox. ```kotlin --8<-- "Inboxes.kt:get-inbox" ``` -------------------------------- ### Allow a Domain Source: https://github.com/mattbobambrose/agentmail4k/blob/master/website/agentmail/docs/lists.md Adds a specific domain to the allow list. ```kotlin --8<-- "Lists.kt:allow-domain" ``` -------------------------------- ### Set Up Automatic Email Replies Source: https://github.com/mattbobambrose/agentmail4k/blob/master/website/agentmail/docs/workflows.md Configure automatic replies using pattern-matching rules. Rules are evaluated in order, and the first matching rule handles the message. A default reply is used if no rule matches. ```kotlin autoReply(default = "Thank you for your email.") { rule("Re:", "I will get back to you soon.") rule("Out of Office", "I am currently out of the office.") } ``` -------------------------------- ### Verify a Domain Source: https://github.com/mattbobambrose/agentmail4k/blob/master/website/agentmail/docs/domains.md Confirms domain ownership after DNS records have been configured. ```kotlin --8<-- "Domains.kt:verify-domain" ``` -------------------------------- ### Manage Email Drafts with Kotlin Source: https://context7.com/mattbobambrose/agentmail4k/llms.txt Demonstrates creating, listing, updating, sending, and deleting email drafts within a specific inbox. ```kotlin import com.agentmail4k.sdk.AgentMailClient suspend fun manageDrafts() { val client = AgentMailClient() val inboxId = "inbox_abc123" val draftsResource = client.inboxes(inboxId).drafts // Create a draft val draft = draftsResource.create { to = listOf("recipient@example.com") subject = "Draft: Project Proposal" text = "Initial draft content..." } println("Created draft: ${draft.draftId}") // List all drafts val drafts = draftsResource.list { limit = 20 ascending = false } // Update draft content val updated = draftsResource.update(draft.draftId) { subject = "Updated: Project Proposal" text = "Revised draft content with more details..." html = "

Project Proposal

Revised content...

" cc = listOf("manager@example.com") } // Get a specific draft val retrieved = draftsResource.get(draft.draftId) // Send the draft as an email val sendResponse = draftsResource.send(draft.draftId) { labels = listOf("sent", "proposal") } println("Sent message: ${sendResponse.messageId}") // Delete a draft draftsResource.delete(draft.draftId) client.close() } ``` -------------------------------- ### Inbox Scope Access Source: https://github.com/mattbobambrose/agentmail4k/blob/master/llms-full.txt Use `client.inboxes(inboxId)` to get a scoped view of an inbox's resources, useful for performing multiple operations on the same inbox. ```kotlin --8<-- "ScopedAccess.kt:inbox-scope" ``` -------------------------------- ### Configure AgentMail API Key Source: https://github.com/mattbobambrose/agentmail4k/blob/master/llms-full.txt Set the API key via environment variable or pass it explicitly during client initialization. ```bash export AGENTMAIL_API_KEY="your-api-key" ``` ```kotlin --8<-- "GettingStarted.kt:create-client-env" ``` ```kotlin --8<-- "GettingStarted.kt:create-client-explicit" ``` -------------------------------- ### Pod Scope Access Source: https://github.com/mattbobambrose/agentmail4k/blob/master/llms-full.txt Use `client.pods(podId)` to get a scoped view of a pod's resources, ideal for batch operations within a specific pod. ```kotlin --8<-- "ScopedAccess.kt:pod-scope" ``` -------------------------------- ### Webhook Handler Configuration Source: https://github.com/mattbobambrose/agentmail4k/blob/master/llms-full.txt DSL builder for configuring webhook event handlers with optional signature verification. ```APIDOC ## WebhookHandler ### Description Processes incoming webhook payloads with optional HMAC-SHA256 signature verification and event-specific handlers. ### Methods #### `webhookHandler(block: WebhookHandlerBuilder.() -> Unit): WebhookHandler` - **Description**: Creates a `WebhookHandler` using the DSL builder. - **Parameters**: - **block**: A lambda function that configures the `WebhookHandlerBuilder`. - `signingSecret` (string?) - Optional - The secret key for verifying webhook signatures. - `on(event: WebhookEvent, handler: suspend (JsonObject) -> Unit)` - Registers a handler for a specific webhook event. - `onMessageReceived(handler: suspend (JsonObject) -> Unit)` - Registers a handler for the `message.received` event. - `onMessageSent(handler: suspend (JsonObject) -> Unit)` - Registers a handler for the `message.sent` event. - `onMessageDelivered(handler: suspend (JsonObject) -> Unit)` - Registers a handler for the `message.delivered` event. - `onMessageBounced(handler: suspend (JsonObject) -> Unit)` - Registers a handler for the `message.bounced` event. - `onMessageComplained(handler: suspend (JsonObject) -> Unit)` - Registers a handler for the `message.complained` event. - `onMessageRejected(handler: suspend (JsonObject) -> Unit)` - Registers a handler for the `message.rejected` event. - `onDomainVerified(handler: suspend (JsonObject) -> Unit)` - Registers a handler for the `domain.verified` event. #### `verify(headers: Map, body: String): Boolean` - **Description**: Verifies the HMAC-SHA256 signature of a webhook payload. Returns true if valid or if no signing secret is configured. - **Parameters**: - **headers** (Map) - Required - The HTTP headers of the incoming webhook request. - **body** (String) - Required - The raw body of the incoming webhook request. - **Response**: `Boolean` - True if the signature is valid or not required, false otherwise. #### `handle(headers: Map, body: String): Boolean` - **Description**: Verifies and dispatches a webhook payload to the appropriate event handler. Returns false if signature verification fails. - **Parameters**: - **headers** (Map) - Required - The HTTP headers of the incoming webhook request. - **body** (String) - Required - The raw body of the incoming webhook request. - **Response**: `Boolean` - True if the payload was handled successfully, false if signature verification failed. ``` -------------------------------- ### Handle Webhooks with WebhookHandler Source: https://github.com/mattbobambrose/agentmail4k/blob/master/llms-full.txt Uses a DSL builder to register event handlers and verify incoming webhook signatures. ```kotlin /** DSL builder for configuring webhook event handlers with optional signature verification. */ class WebhookHandlerBuilder { var signingSecret: String? /** Registers a handler for a specific webhook [event]. */ fun on(event: WebhookEvent, handler: suspend (JsonObject) -> Unit) /** Registers a handler for the message.received event. */ fun onMessageReceived(handler: suspend (JsonObject) -> Unit) /** Registers a handler for the message.sent event. */ fun onMessageSent(handler: suspend (JsonObject) -> Unit) /** Registers a handler for the message.delivered event. */ fun onMessageDelivered(handler: suspend (JsonObject) -> Unit) /** Registers a handler for the message.bounced event. */ fun onMessageBounced(handler: suspend (JsonObject) -> Unit) /** Registers a handler for the message.complained event. */ fun onMessageComplained(handler: suspend (JsonObject) -> Unit) /** Registers a handler for the message.rejected event. */ fun onMessageRejected(handler: suspend (JsonObject) -> Unit) /** Registers a handler for the domain.verified event. */ fun onDomainVerified(handler: suspend (JsonObject) -> Unit) } /** Processes incoming webhook payloads with optional HMAC-SHA256 signature verification and event-specific handlers. */ class WebhookHandler { /** Verifies the HMAC-SHA256 signature of a webhook payload. Returns true if valid or if no signing secret is configured. */ fun verify(headers: Map, body: String): Boolean /** Verifies and dispatches a webhook payload to the appropriate event handler. Returns false if signature verification fails. */ suspend fun handle(headers: Map, body: String): Boolean } /** Creates a [WebhookHandler] using the DSL builder. */ fun webhookHandler(block: WebhookHandlerBuilder.() -> Unit): WebhookHandler ``` -------------------------------- ### Manage custom domains with DomainResource Source: https://github.com/mattbobambrose/agentmail4k/blob/master/llms-full.txt Provides methods for domain lifecycle management, including verification and zone file retrieval. ```kotlin /** Provides operations for managing custom domains: list, create, get, update, delete, verify, and retrieve zone files. */ class DomainResource { /** Lists custom domains with optional pagination. */ suspend fun list(block: ListDomainsBuilder.() -> Unit = {}): DomainList /** Creates a new custom domain. */ suspend fun create(block: CreateDomainBuilder.() -> Unit): Domain /** Retrieves a domain by ID. */ suspend fun get(domainId: String): Domain /** Updates a domain by ID. */ suspend fun update(domainId: String, block: UpdateDomainBuilder.() -> Unit): Domain /** Deletes a domain by ID. */ suspend fun delete(domainId: String) /** Triggers DNS verification for a domain. */ suspend fun verify(domainId: String) /** Retrieves the DNS zone file for a domain as raw bytes. */ suspend fun getZoneFile(domainId: String): ByteArray } ``` -------------------------------- ### Create a Webhook Source: https://github.com/mattbobambrose/agentmail4k/blob/master/website/agentmail/docs/webhooks.md Registers a new webhook endpoint to receive event notifications. ```kotlin --8<-- "Webhooks.kt:create-webhook" ``` -------------------------------- ### List Pods in Kotlin Source: https://github.com/mattbobambrose/agentmail4k/blob/master/website/agentmail/docs/pods.md Retrieves a collection of all available pods. ```kotlin --8<-- "Pods.kt:list-pods" ``` -------------------------------- ### Project Structure Overview Source: https://github.com/mattbobambrose/agentmail4k/blob/master/README.md Directory layout of the agentmail4k source code. ```text src/main/kotlin/com/agentmail4k/ sdk/ AgentMailClient.kt -- Entry point, holds all API resources AgentMailConfig.kt -- DSL builders for client configuration builder/ -- DSL builders for create/update/list/send operations model/ -- Serializable data classes for API responses resource/ -- API resource classes (InboxResource, MessageResource, etc.) internal/ -- API path constants and HTTP client factory dsl/ -- High-level extension functions and workflows ``` -------------------------------- ### Query Email Metrics Source: https://github.com/mattbobambrose/agentmail4k/blob/master/website/agentmail/docs/metrics.md Retrieve email metrics for your account. Ensure the Metrics.kt file is correctly included. ```kotlin --8<-- "Metrics.kt:query-metrics" ``` -------------------------------- ### Available Resources within Pod Scope Source: https://github.com/mattbobambrose/agentmail4k/blob/master/llms-full.txt Details the resources that are accessible and manageable when using a pod-scoped client. ```kotlin --8<-- "ScopedAccess.kt:pod-scope-resources" ``` -------------------------------- ### Manage pods with PodResource Source: https://github.com/mattbobambrose/agentmail4k/blob/master/llms-full.txt Provides basic CRUD operations for managing pods. ```kotlin /** Provides operations for managing pods: list, create, get, and delete. */ class PodResource { /** Lists pods with optional pagination. */ suspend fun list(block: ListPodsBuilder.() -> Unit = {}): PodList /** Creates a new pod. */ suspend fun create(): Pod /** Retrieves a pod by ID. */ suspend fun get(podId: String): Pod /** Deletes a pod by ID. */ suspend fun delete(podId: String) } ``` -------------------------------- ### Configure Auto-Reply Source: https://github.com/mattbobambrose/agentmail4k/blob/master/llms-full.txt Set up automatic replies with pattern-matching rules evaluated in order. ```kotlin --8<-- "Workflows.kt:auto-reply" ``` -------------------------------- ### Run Gradle Tasks Source: https://github.com/mattbobambrose/agentmail4k/blob/master/CLAUDE.md Common Gradle tasks for building, testing, and running the AgentMail Kotlin DSL project. Ensure AGENTMAIL_API_KEY is set for the run task. ```bash ./gradlew test # Run all tests ./gradlew compileKotlin # Compile main sources only ./gradlew run # Run Main.kt (requires AGENTMAIL_API_KEY env var) ./gradlew dokkaGenerate # Generate KDoc API reference (output: build/dokka/html/) ``` -------------------------------- ### Retrieve Organization Information Source: https://github.com/mattbobambrose/agentmail4k/blob/master/website/agentmail/docs/metrics.md Fetch your organization's information. This snippet assumes the Metrics.kt file is available and contains the necessary function. ```kotlin --8<-- "Metrics.kt:get-organization" ``` -------------------------------- ### View AgentMailClient default configuration Source: https://github.com/mattbobambrose/agentmail4k/blob/master/website/agentmail/docs/configuration.md These settings are applied automatically when no explicit configuration is provided. ```kotlin --8<-- "Configuration.kt:defaults" ``` -------------------------------- ### Scoped Resource Access Pattern Source: https://context7.com/mattbobambrose/agentmail4k/llms.txt Demonstrates how to scope operations to specific inboxes or pods to streamline resource management. Requires an initialized AgentMailClient and appropriate identifiers. ```kotlin import com.agentmail4k.sdk.AgentMailClient suspend fun scopedAccess() { val client = AgentMailClient() val inboxId = "inbox_abc123" // Get inbox scope for repeated operations val inboxScope = client.inboxes(inboxId) // All operations scoped to this inbox val messages = inboxScope.messages.list { limit = 10 } val threads = inboxScope.threads.list { limit = 10 } val drafts = inboxScope.drafts.list() val metrics = inboxScope.metrics.query() val apiKeys = inboxScope.apiKeys.list() // Send message within scope inboxScope.messages.send { to = listOf("recipient@example.com") subject = "Scoped send" text = "Message sent via inbox scope." } // Reply within scope if (messages.messages.isNotEmpty()) { inboxScope.messages.reply(messages.messages.first().messageId) { text = "Thank you for your message." } } // Pod scope for multi-tenant access val podScope = client.pods("pod_xyz") val podInboxes = podScope.inboxes.list() val podMetrics = podScope.metrics.query() // Nested: inbox within pod val nestedInbox = podScope.inboxes("inbox_in_pod") val nestedMessages = nestedInbox.messages.list() client.close() } ``` -------------------------------- ### Manage Drafts Source: https://github.com/mattbobambrose/agentmail4k/blob/master/llms-full.txt Compose, list, update, and send email drafts. ```kotlin --8<-- "Drafts.kt:create-draft" ``` ```kotlin --8<-- "Drafts.kt:list-drafts" ``` ```kotlin --8<-- "Drafts.kt:get-draft" ``` ```kotlin --8<-- "Drafts.kt:update-draft" ``` ```kotlin --8<-- "Drafts.kt:send-draft" ``` -------------------------------- ### Manage email drafts with DraftResource Source: https://github.com/mattbobambrose/agentmail4k/blob/master/llms-full.txt Provides methods for creating, updating, sending, and managing email drafts. ```kotlin /** Provides operations for managing email drafts: list, create, get, update, delete, send, and retrieve attachments. */ class DraftResource { /** Lists drafts with optional pagination and filtering. */ suspend fun list(block: ListDraftsBuilder.() -> Unit = {}): DraftList /** Creates a new email draft. */ suspend fun create(block: CreateDraftBuilder.() -> Unit): Draft /** Retrieves a draft by ID. */ suspend fun get(draftId: String): Draft /** Updates an existing draft by ID. */ suspend fun update(draftId: String, block: UpdateDraftBuilder.() -> Unit): Draft /** Deletes a draft by ID. */ suspend fun delete(draftId: String) /** Sends a draft as an email message. */ suspend fun send(draftId: String, block: SendDraftBuilder.() -> Unit = {}): SendMessageResponse /** Retrieves a draft attachment's binary data by draft and attachment IDs. */ suspend fun getAttachment(draftId: String, attachmentId: String): AttachmentData } ``` -------------------------------- ### Pod Scope Resources Source: https://github.com/mattbobambrose/agentmail4k/blob/master/website/agentmail/docs/scoped-access.md Illustrates the resources accessible within a pod scope, such as runs and tasks. ```kotlin val runs = pod.runs().list() val tasks = pod.tasks().list() ``` -------------------------------- ### Send Message Source: https://github.com/mattbobambrose/agentmail4k/blob/master/website/agentmail/docs/getting-started.md Basic workflow for creating an inbox and sending a message. ```kotlin --8<-- "GettingStarted.kt:quick-start" ``` -------------------------------- ### Manage email messages with MessageResource Source: https://github.com/mattbobambrose/agentmail4k/blob/master/llms-full.txt Provides methods for listing, sending, replying, and retrieving email messages and their attachments. ```kotlin /** Provides operations for managing email messages: list, get, update, send, reply, reply-all, forward, retrieve attachments, and get raw content. */ class MessageResource { /** Lists messages with optional pagination and filtering. */ suspend fun list(block: ListMessagesBuilder.() -> Unit = {}): MessageList /** Retrieves a message by ID. */ suspend fun get(messageId: String): Message /** Updates a message by ID. */ suspend fun update(messageId: String, block: UpdateMessageBuilder.() -> Unit): Message /** Sends a new email message. */ suspend fun send(block: SendMessageBuilder.() -> Unit): SendMessageResponse /** Sends a reply to a specific message. */ suspend fun reply(messageId: String, block: ReplyBuilder.() -> Unit): SendMessageResponse /** Sends a reply-all to a specific message. */ suspend fun replyAll(messageId: String, block: ReplyAllBuilder.() -> Unit): SendMessageResponse /** Forwards a message to new recipients. */ suspend fun forward(messageId: String, block: ForwardMessageBuilder.() -> Unit): SendMessageResponse /** Retrieves a message attachment's binary data. */ suspend fun getAttachment(messageId: String, attachmentId: String): AttachmentData /** Retrieves the raw RFC 2822 content of a message. */ suspend fun getRaw(messageId: String): RawMessageResponse } ``` -------------------------------- ### Paginate Inboxes Source: https://github.com/mattbobambrose/agentmail4k/blob/master/website/agentmail/docs/inboxes.md Demonstrates how to paginate through lists of inboxes using the `pageToken` parameter. This pattern applies to all list operations within the SDK. ```kotlin --8<-- "Inboxes.kt:paginate-inboxes" ``` -------------------------------- ### List Domains Source: https://github.com/mattbobambrose/agentmail4k/blob/master/website/agentmail/docs/domains.md Retrieves a collection of all domains associated with the account. ```kotlin --8<-- "Domains.kt:list-domains" ``` -------------------------------- ### Fetch Full Message Content in Kotlin Source: https://github.com/mattbobambrose/agentmail4k/blob/master/website/agentmail/docs/messages.md Retrieves the complete message body for a given message summary. ```kotlin --8<-- "Messages.kt:full-message" ``` -------------------------------- ### List Entries Source: https://github.com/mattbobambrose/agentmail4k/blob/master/website/agentmail/docs/lists.md Retrieves all entries currently in the lists. ```kotlin --8<-- "Lists.kt:list-entries" ``` -------------------------------- ### AgentMailConfig Configuration Source: https://github.com/mattbobambrose/agentmail4k/blob/master/llms-full.txt Configuration builders and data classes for the AgentMail client. ```kotlin /** DSL builder for configuring an [AgentMailClient] instance. Allows setting the API key, base URL, timeout, and retry settings. */ class AgentMailConfigBuilder { var apiKey: String? var baseUrl: String /** Configures HTTP timeout settings. */ fun timeout(block: TimeoutBuilder.() -> Unit) /** Configures HTTP retry settings. */ fun retry(block: RetryBuilder.() -> Unit) } /** Immutable configuration for the AgentMail HTTP client. */ data class AgentMailConfig( val apiKey: String, val baseUrl: String, val timeout: TimeoutConfig, val retry: RetryConfig, ) /** DSL builder for configuring HTTP timeout durations. */ class TimeoutBuilder { var connect: Duration var request: Duration var socket: Duration } /** Immutable timeout configuration with connect, request, and socket durations. */ data class TimeoutConfig( val connect: Duration, val request: Duration, val socket: Duration, ) /** DSL builder for configuring HTTP retry behavior. */ class RetryBuilder { var maxRetries: Int var retryOnServerErrors: Boolean } /** Immutable retry configuration with max retries and server error retry toggle. */ data class RetryConfig( val maxRetries: Int, val retryOnServerErrors: Boolean, ) ``` -------------------------------- ### Compare DSL and Scoped Access Source: https://github.com/mattbobambrose/agentmail4k/blob/master/llms-full.txt Choose between DSL functions for single operations or scoped access for multiple operations on the same resource. ```kotlin --8<-- "ScopedAccess.kt:dsl-vs-scope" ``` -------------------------------- ### Update a Domain Source: https://github.com/mattbobambrose/agentmail4k/blob/master/website/agentmail/docs/domains.md Modifies the configuration of an existing domain. ```kotlin --8<-- "Domains.kt:update-domain" ``` -------------------------------- ### List Messages in Kotlin Source: https://github.com/mattbobambrose/agentmail4k/blob/master/website/agentmail/docs/messages.md Retrieves a list of message summaries from an inbox. ```kotlin --8<-- "Messages.kt:list-messages" ``` -------------------------------- ### List Drafts in Kotlin Source: https://github.com/mattbobambrose/agentmail4k/blob/master/website/agentmail/docs/drafts.md Retrieves a collection of existing draft messages. ```kotlin --8<-- "Drafts.kt:list-drafts" ``` -------------------------------- ### Manage Multi-Tenant Pods in Kotlin Source: https://context7.com/mattbobambrose/agentmail4k/llms.txt Create and manage isolated pods to scope resources like inboxes, threads, and domains. Deleting a pod removes all associated resources. ```kotlin import com.agentmail4k.sdk.AgentMailClient suspend fun managePods() { val client = AgentMailClient() // Create a new pod (isolated tenant) val pod = client.pods.create() println("Created pod: ${pod.podId}") // List all pods val pods = client.pods.list { limit = 20 ascending = true } // Get pod details val retrieved = client.pods.get(pod.podId) // Work within pod scope val podScope = client.pods(pod.podId) // Create inbox within pod val inbox = podScope.inboxes.create { username = "support" domain = "tenant1.example.com" displayName = "Tenant Support" } // Access pod-scoped resources val podInboxes = podScope.inboxes.list() val podThreads = podScope.threads.list() val podDrafts = podScope.drafts.list() val podDomains = podScope.domains.list() // Nested scope: inbox within pod val inboxScope = podScope.inboxes(inbox.inboxId) val messages = inboxScope.messages.list() // Pod-level metrics val metrics = podScope.metrics.query { eventTypes = "message.sent,message.received" } // Delete pod (and all its resources) client.pods.delete(pod.podId) client.close() } ``` -------------------------------- ### Set Environment Variable for API Key Source: https://github.com/mattbobambrose/agentmail4k/blob/master/website/agentmail/docs/getting-started.md Configure the API key via shell environment variable for automatic client detection. ```bash export AGENTMAIL_API_KEY="your-api-key" ``` -------------------------------- ### Create an Inbox Source: https://github.com/mattbobambrose/agentmail4k/blob/master/website/agentmail/docs/inboxes.md Use this snippet to create a new inbox managed by AgentMail. Ensure you have the necessary permissions. ```kotlin --8<-- "Inboxes.kt:create-inbox" ``` -------------------------------- ### AutoReply Configuration Source: https://github.com/mattbobambrose/agentmail4k/blob/master/llms-full.txt Sets up automatic reply rules for an inbox based on message predicates. ```APIDOC ## AgentMailClient.autoReply ### Description Starts an auto-reply monitor on the given inbox that automatically replies to incoming messages based on configured rules. ### Parameters #### Path Parameters - **inboxId** (String) - Required - The unique identifier of the inbox. #### Request Body (AutoReplyBuilder) - **pollInterval** (Duration) - Optional - Frequency of polling. - **rule** (Function) - Optional - Adds a rule that replies when the match predicate returns true. - **default** (Function) - Optional - Sets the default reply action for non-matching messages. ``` -------------------------------- ### Send a Draft in Kotlin Source: https://github.com/mattbobambrose/agentmail4k/blob/master/website/agentmail/docs/drafts.md Dispatches a previously created and reviewed draft. ```kotlin --8<-- "Drafts.kt:send-draft" ``` -------------------------------- ### Manage Client Lifecycle Source: https://github.com/mattbobambrose/agentmail4k/blob/master/website/agentmail/docs/getting-started.md Use the 'use' extension to ensure the AgentMailClient is closed properly after operations. ```kotlin --8<-- "GettingStarted.kt:use-closeable" ``` -------------------------------- ### Configure connection and request timeouts Source: https://github.com/mattbobambrose/agentmail4k/blob/master/website/agentmail/docs/configuration.md Set connection, request, and socket timeouts using the Kotlin Duration type. ```kotlin --8<-- "Configuration.kt:timeout-config" ``` -------------------------------- ### Monitor Full Message Content Source: https://github.com/mattbobambrose/agentmail4k/blob/master/llms-full.txt Receive complete message bodies by using onFullMessage. ```kotlin --8<-- "Workflows.kt:monitor-full" ``` -------------------------------- ### Query Metrics with MetricsResource Source: https://github.com/mattbobambrose/agentmail4k/blob/master/llms-full.txt Provides a single query method for retrieving email event metrics. ```kotlin /** Provides operations for querying email event metrics. */ class MetricsResource { /** Queries email event metrics with optional filters and aggregation. */ suspend fun query(block: QueryMetricsBuilder.() -> Unit = {}): QueryMetricsResponse } ``` -------------------------------- ### Delete a Domain Source: https://github.com/mattbobambrose/agentmail4k/blob/master/website/agentmail/docs/domains.md Removes a domain from the account permanently. ```kotlin --8<-- "Domains.kt:delete-domain" ``` -------------------------------- ### Execute Bulk Operations Source: https://github.com/mattbobambrose/agentmail4k/blob/master/llms-full.txt Defines the BulkBuilder DSL for batching send and thread-iteration operations, and the bulk function for execution. ```kotlin /** DSL builder for batching multiple send and thread-iteration operations into a single execution. */ class BulkBuilder { /** Queues a send operation that delivers a message to each recipient individually. */ fun send( inboxId: String, recipients: List, block: SendMessageBuilder.() -> Unit, ) /** Queues an operation that iterates over all threads in the inbox, handling pagination automatically. */ fun forEachThread( inboxId: String, filter: ListThreadsBuilder.() -> Unit = {}, action: suspend (Thread) -> Unit, ) } /** Executes a batch of send and thread-iteration operations. */ suspend fun AgentMailClient.bulk(block: BulkBuilder.() -> Unit): List ``` -------------------------------- ### Query Metrics by Period Source: https://github.com/mattbobambrose/agentmail4k/blob/master/website/agentmail/docs/metrics.md Query email metrics at different time granularities such as hourly, daily, weekly, or monthly. The available periods are HOUR, DAY, WEEK, and MONTH. ```kotlin --8<-- "Metrics.kt:metrics-period" ``` -------------------------------- ### Send a Message with CC and BCC in Kotlin Source: https://github.com/mattbobambrose/agentmail4k/blob/master/website/agentmail/docs/messages.md Sends an email message including carbon copy and blind carbon copy recipients. ```kotlin --8<-- "Messages.kt:send-with-cc-bcc" ``` -------------------------------- ### Manage List Entries with ListResource Source: https://github.com/mattbobambrose/agentmail4k/blob/master/llms-full.txt Handles allow/block list entries for various filtering criteria. Requires direction and type parameters for most operations. ```kotlin /** Provides operations for managing allow/block list entries for filtering by sender, recipient, domain, or subject. */ class ListResource { /** Lists allow/block entries for a given direction and type. */ suspend fun list( direction: ListDirection, type: ListType, block: ListEntriesBuilder.() -> Unit = {}, ): ListEntryList /** Creates a new allow/block list entry. */ suspend fun create( direction: ListDirection, type: ListType, block: CreateListEntryBuilder.() -> Unit, ): ListEntry /** Retrieves a specific list entry. */ suspend fun get(direction: ListDirection, type: ListType, entry: String): ListEntry /** Deletes a specific list entry. */ suspend fun delete(direction: ListDirection, type: ListType, entry: String) } ``` -------------------------------- ### Inbox Scope Resources Source: https://github.com/mattbobambrose/agentmail4k/blob/master/website/agentmail/docs/scoped-access.md Demonstrates the available resources that can be accessed within an inbox scope. These include messages, threads, and drafts. ```kotlin val messages = inbox.messages().list() val threads = inbox.threads().list() val drafts = inbox.drafts().list() ``` -------------------------------- ### Custom Event Handlers for Webhooks Source: https://github.com/mattbobambrose/agentmail4k/blob/master/llms-full.txt Use the generic `on()` method to handle any event type not covered by specific handlers. ```kotlin --8<-- "Webhooks.kt:webhook-handler-custom" ``` -------------------------------- ### Forward a Message in Kotlin Source: https://github.com/mattbobambrose/agentmail4k/blob/master/website/agentmail/docs/messages.md Forwards a message to new recipients. ```kotlin --8<-- "Messages.kt:forward" ``` -------------------------------- ### Process All Threads Source: https://github.com/mattbobambrose/agentmail4k/blob/master/llms-full.txt Iterate over all threads in an inbox with automatic pagination. ```kotlin --8<-- "Workflows.kt:bulk-threads" ``` -------------------------------- ### Reply and Forward Messages with AgentMail4k Source: https://context7.com/mattbobambrose/agentmail4k/llms.txt Use this to reply to messages, perform a reply-all, and forward messages to new recipients. Ensure the AgentMailClient is closed after operations. ```kotlin import com.agentmail4k.sdk.AgentMailClient import com.agentmail4k.dsl.* suspend fun replyAndForward() { val client = AgentMailClient() val inboxId = "inbox_abc123" // Get an incoming message val messages = client.listMessages(inboxId) { limit = 1 } val message = messages.messages.first() // Reply to sender val replyResponse = client.replyToMessage(message) { text = "Thank you for your message. We'll get back to you shortly." html = "

Thank you for your message. We'll get back to you shortly.

" } // Reply to all recipients client.replyAllToMessage(message) { text = "Please see my response below." } // Forward to new recipients client.forwardMessage(message) { to = listOf("manager@example.com", "team@example.com") cc = listOf("archive@example.com") subject = "FW: ${message.subject}" text = "Please review the forwarded message below." } client.close() } ``` -------------------------------- ### Manage List Entries Source: https://github.com/mattbobambrose/agentmail4k/blob/master/website/agentmail/docs/lists.md Endpoints for creating, retrieving, listing, and deleting entries within the allow/block lists. ```APIDOC ## POST /lists/block-sender ### Description Blocks a specific sender from sending emails. ### Method POST ### Endpoint /lists/block-sender ## POST /lists/allow-domain ### Description Allows a specific domain to send emails. ### Method POST ### Endpoint /lists/allow-domain ## GET /lists/entries ### Description Retrieves a list of all entries currently in the allow/block lists. ### Method GET ### Endpoint /lists/entries ## GET /lists/entry/{id} ### Description Retrieves details for a specific list entry. ### Method GET ### Endpoint /lists/entry/{id} ## DELETE /lists/entry/{id} ### Description Removes an entry from the allow/block list. ### Method DELETE ### Endpoint /lists/entry/{id} ``` -------------------------------- ### Monitor Inbox with Full Message Content Source: https://github.com/mattbobambrose/agentmail4k/blob/master/website/agentmail/docs/workflows.md Use `onFullMessage` instead of `onMessage` to receive complete message bodies when monitoring an inbox. ```kotlin monitor(intervalMillis = 1000, onFullMessage = true) { message -> println("New message body: ${message.body}") } ```