Skip to content

Drafts

Drafts let you compose messages before sending them.

Create a Draft

suspend fun createDraftExample() {
    val client = AgentMailClient()
    val draft = client.createDraft("inbox-id") {
        to = listOf("recipient@example.com")
        subject = "Draft message"
        text = "This is a draft."
    }
    println("Draft ID: ${draft.draftId}")
    client.close()
}

List Drafts

suspend fun listDraftsExample() {
    val client = AgentMailClient()
    val result = client.listDrafts("inbox-id") {
        limit = 10
    }
    for (draft in result.drafts) {
        println("${draft.draftId}: ${draft.subject}")
    }
    client.close()
}

Get a Draft

suspend fun getDraftExample() {
    val client = AgentMailClient()
    val draft = client.getDraft("inbox-id", "draft-id")
    println("Subject: ${draft.subject}")
    println("To: ${draft.to}")
    client.close()
}

Update a Draft

suspend fun updateDraftExample() {
    val client = AgentMailClient()
    val updated = client.updateDraft("inbox-id", "draft-id") {
        subject = "Updated subject"
        text = "Updated body content."
    }
    println("Updated: ${updated.subject}")
    client.close()
}

Send a Draft

Create a draft, review it, then send:

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

    // Create a draft, then send it
    val draft = client.createDraft("inbox-id") {
        to = listOf("recipient@example.com")
        subject = "Ready to send"
        text = "This draft is ready."
    }

    val response = client.sendDraft("inbox-id", draft.draftId)
    println("Sent! Message ID: ${response.messageId}")
    client.close()
}

Delete a Draft

suspend fun deleteDraftExample() {
    val client = AgentMailClient()
    client.deleteDraft("inbox-id", "draft-id")
    println("Draft deleted")
    client.close()
}

Draft Attachments

suspend fun draftAttachmentExample() {
    val client = AgentMailClient()
    val data = client.getDraftAttachment("inbox-id", "draft-id", "attachment-id")
    println("Content type: ${data.contentType}")
    println("Size: ${data.data.size} bytes")
    client.close()
}

Next Steps