pub struct Client { /* private fields */ }Expand description
An authenticated handle on the AgentMail API. Cheap to clone-ish (it owns
a pooled reqwest::Client); construct once and share by reference.
Implementations§
Source§impl Client
impl Client
Sourcepub fn new(api_key: impl Into<String>, base_url: impl Into<String>) -> Self
pub fn new(api_key: impl Into<String>, base_url: impl Into<String>) -> Self
A client against base_url (see DEFAULT_BASE_URL), with a
DEFAULT_TIMEOUT on every request.
Sourcepub fn from_env() -> Result<Self, Error>
pub fn from_env() -> Result<Self, Error>
From AGENTMAIL_API_KEY (+ optional AGENTMAIL_BASE_URL).
Sourcepub async fn create_inbox(&self, inbox: CreateInbox) -> Result<Inbox, Error>
pub async fn create_inbox(&self, inbox: CreateInbox) -> Result<Inbox, Error>
POST /v0/inboxes, a new agent-owned email address. Free plans get
{username}@agentmail.to; custom domains must be verified first.
Sourcepub async fn list_inboxes(&self) -> Result<InboxList, Error>
pub async fn list_inboxes(&self) -> Result<InboxList, Error>
GET /v0/inboxes (first page; see Client::list_inboxes_page).
Sourcepub async fn list_inboxes_page(&self, page: Page) -> Result<InboxList, Error>
pub async fn list_inboxes_page(&self, page: Page) -> Result<InboxList, Error>
GET /v0/inboxes with pagination. Feed InboxList::next_page_token
back in as Page::page_token until it comes back None.
Sourcepub async fn get_inbox(&self, inbox_id: &str) -> Result<Inbox, Error>
pub async fn get_inbox(&self, inbox_id: &str) -> Result<Inbox, Error>
GET /v0/inboxes/{inbox_id}
Sourcepub async fn delete_inbox(&self, inbox_id: &str) -> Result<(), Error>
pub async fn delete_inbox(&self, inbox_id: &str) -> Result<(), Error>
DELETE /v0/inboxes/{inbox_id}
Sourcepub async fn send_message(
&self,
inbox_id: &str,
message: SendMessage,
) -> Result<SentMessage, Error>
pub async fn send_message( &self, inbox_id: &str, message: SendMessage, ) -> Result<SentMessage, Error>
POST /v0/inboxes/{inbox_id}/messages/send
Sourcepub async fn list_messages(&self, inbox_id: &str) -> Result<MessageList, Error>
pub async fn list_messages(&self, inbox_id: &str) -> Result<MessageList, Error>
GET /v0/inboxes/{inbox_id}/messages (first page; see
Client::list_messages_page).
Sourcepub async fn list_messages_page(
&self,
inbox_id: &str,
page: Page,
) -> Result<MessageList, Error>
pub async fn list_messages_page( &self, inbox_id: &str, page: Page, ) -> Result<MessageList, Error>
GET /v0/inboxes/{inbox_id}/messages with pagination. Feed
MessageList::next_page_token back in as Page::page_token
until it comes back None.
Sourcepub async fn get_message(
&self,
inbox_id: &str,
message_id: &str,
) -> Result<Message, Error>
pub async fn get_message( &self, inbox_id: &str, message_id: &str, ) -> Result<Message, Error>
GET /v0/inboxes/{inbox_id}/messages/{message_id}
Sourcepub async fn create_webhook(
&self,
webhook: CreateWebhook,
) -> Result<Webhook, Error>
pub async fn create_webhook( &self, webhook: CreateWebhook, ) -> Result<Webhook, Error>
POST /v0/webhooks, subscribe an HTTPS endpoint to events
(e.g. message.received). The response carries the signing secret
exactly once; store it.
Sourcepub async fn list_webhooks(&self) -> Result<WebhookList, Error>
pub async fn list_webhooks(&self) -> Result<WebhookList, Error>
GET /v0/webhooks (first page; see Client::list_webhooks_page).
Sourcepub async fn list_webhooks_page(&self, page: Page) -> Result<WebhookList, Error>
pub async fn list_webhooks_page(&self, page: Page) -> Result<WebhookList, Error>
GET /v0/webhooks with pagination. Feed WebhookList::next_page_token
back in as Page::page_token until it comes back None.