Skip to main content

agentmail/client/
inboxes.rs

1use crate::client::NoBody;
2use crate::{Client, Error, Page, types::*, util::urlish};
3
4impl Client {
5    /// POST /v0/inboxes, a new agent-owned email address. Free plans get
6    /// `{username}@agentmail.to`; custom domains must be verified first.
7    pub async fn create_inbox(&self, inbox: CreateInbox) -> Result<Inbox, Error> {
8        self.request(reqwest::Method::POST, "/v0/inboxes", &[], Some(&inbox))
9            .await
10    }
11
12    /// GET /v0/inboxes (first page; see [`Client::list_inboxes_page`]).
13    pub async fn list_inboxes(&self) -> Result<InboxList, Error> {
14        self.list_inboxes_page(Page::default()).await
15    }
16
17    /// GET /v0/inboxes with pagination. Feed [`InboxList::next_page_token`]
18    /// back in as [`Page::page_token`] until it comes back `None`.
19    pub async fn list_inboxes_page(&self, page: Page) -> Result<InboxList, Error> {
20        self.request(
21            reqwest::Method::GET,
22            "/v0/inboxes",
23            &page.query(),
24            None::<&NoBody>,
25        )
26        .await
27    }
28
29    /// GET /v0/inboxes/{inbox_id}
30    pub async fn get_inbox(&self, inbox_id: &str) -> Result<Inbox, Error> {
31        self.request(
32            reqwest::Method::GET,
33            &format!("/v0/inboxes/{}", urlish(inbox_id)),
34            &[],
35            None::<&NoBody>,
36        )
37        .await
38    }
39
40    /// PATCH /v0/inboxes/{inbox_id}, update the display name and/or metadata.
41    pub async fn update_inbox(&self, inbox_id: &str, update: UpdateInbox) -> Result<Inbox, Error> {
42        self.request(
43            reqwest::Method::PATCH,
44            &format!("/v0/inboxes/{}", urlish(inbox_id)),
45            &[],
46            Some(&update),
47        )
48        .await
49    }
50
51    /// DELETE /v0/inboxes/{inbox_id}
52    pub async fn delete_inbox(&self, inbox_id: &str) -> Result<(), Error> {
53        self.request(
54            reqwest::Method::DELETE,
55            &format!("/v0/inboxes/{}", urlish(inbox_id)),
56            &[],
57            None::<&NoBody>,
58        )
59        .await
60    }
61}