Skip to content

Bulk Operations

Send to Multiple Recipients

suspend fun bulkSendExample() {
    val client = AgentMailClient()

    val results = client.bulk {
        send(
            inboxId = "inbox-id",
            recipients = listOf(
                "user1@example.com",
                "user2@example.com",
                "user3@example.com",
            ),
        ) {
            subject = "Monthly Newsletter"
            text = "Here's your monthly update."
            html = "<h1>Monthly Newsletter</h1><p>Here's your monthly update.</p>"
        }
    }

    println("Sent ${results.size} messages")
    for (result in results) {
        println("  Message ID: ${result.messageId}")
    }
    client.close()
}

Process All Threads

Iterate over all threads in an inbox with automatic pagination:

suspend fun bulkThreadsExample() {
    val client = AgentMailClient()

    client.bulk {
        forEachThread(
            inboxId = "inbox-id",
            filter = { limit = 50 },
        ) { thread ->
            println("Thread: ${thread.subject} (${thread.messageCount} messages)")
        }
    }

    client.close()
}

Next Steps

  • Webhooks — receive and verify webhook events
  • Pods — group inboxes into isolated pods
  • Domains — register and manage custom domains