Skip to main content

Client

Struct Client 

Source
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

Source

pub async fn agent_sign_up( &self, signup: AgentSignup, ) -> Result<AgentSignupResult, Error>

POST /v0/agent/sign-up, start onboarding a new agent. Emails a one-time code to human_email; confirm it with Client::agent_verify. Runs before any credential exists, so the client’s bearer token (if any) is irrelevant.

Source

pub async fn agent_verify( &self, otp_code: &str, ) -> Result<AgentVerifyResult, Error>

POST /v0/agent/verify, confirm the one-time code from Client::agent_sign_up.

Source§

impl Client

Source

pub async fn create_api_key( &self, key: CreateApiKey, ) -> Result<CreatedApiKey, Error>

POST /v0/api-keys, mint a new API key. The full secret is in CreatedApiKey::api_key and is shown only here; store it now.

Source

pub async fn list_api_keys(&self) -> Result<ApiKeyList, Error>

GET /v0/api-keys (first page; see Client::list_api_keys_page).

Source

pub async fn list_api_keys_page(&self, page: Page) -> Result<ApiKeyList, Error>

GET /v0/api-keys with pagination. Feed ApiKeyList::next_page_token back in as Page::page_token until it comes back None.

Source

pub async fn delete_api_key(&self, api_key_id: &str) -> Result<(), Error>

DELETE /v0/api-keys/{api_key_id}

Source§

impl Client

Source

pub async fn get_message_attachment( &self, inbox_id: &str, message_id: &str, attachment_id: &str, ) -> Result<Attachment, Error>

GET /v0/inboxes/{inbox_id}/messages/{message_id}/attachments/{attachment_id}. The returned Attachment carries a short-lived download_url; pass it to Client::download_attachment to fetch the bytes.

Source

pub async fn get_thread_attachment( &self, inbox_id: &str, thread_id: &str, attachment_id: &str, ) -> Result<Attachment, Error>

GET /v0/inboxes/{inbox_id}/threads/{thread_id}/attachments/{attachment_id}.

Source

pub async fn get_draft_attachment( &self, inbox_id: &str, draft_id: &str, attachment_id: &str, ) -> Result<Attachment, Error>

GET /v0/inboxes/{inbox_id}/drafts/{draft_id}/attachments/{attachment_id}.

Source

pub async fn download_attachment( &self, attachment: &Attachment, ) -> Result<Vec<u8>, Error>

Download an attachment’s bytes from its presigned download_url. The URL is a short-lived S3 link fetched without the API bearer token, so obtain the Attachment from one of the get_*_attachment calls first (a plain response attachment carries no download_url and yields Error::NoDownloadUrl).

Source§

impl Client

Source

pub async fn auth_me(&self) -> Result<Identity, Error>

GET /v0/auth/me, the Identity the current API key authenticates as.

Source§

impl Client

Source

pub async fn create_domain(&self, domain: CreateDomain) -> Result<Domain, Error>

POST /v0/domains, add a sending domain. The response carries the DNS VerificationRecords to publish.

Source

pub async fn list_domains(&self) -> Result<DomainList, Error>

GET /v0/domains (first page; see Client::list_domains_page).

Source

pub async fn list_domains_page(&self, page: Page) -> Result<DomainList, Error>

GET /v0/domains with pagination. Feed DomainList::next_page_token back in as Page::page_token until it comes back None.

Source

pub async fn get_domain(&self, domain_id: &str) -> Result<Domain, Error>

GET /v0/domains/{domain_id}

Source

pub async fn update_domain( &self, domain_id: &str, update: UpdateDomain, ) -> Result<Domain, Error>

PATCH /v0/domains/{domain_id}, toggle feedback and subdomain settings.

Source

pub async fn delete_domain(&self, domain_id: &str) -> Result<(), Error>

DELETE /v0/domains/{domain_id}

Source

pub async fn verify_domain(&self, domain_id: &str) -> Result<(), Error>

POST /v0/domains/{domain_id}/verify, ask the API to re-check the DNS records. Returns once the check is queued; poll Client::get_domain for the resulting status.

Source

pub async fn get_domain_zone_file( &self, domain_id: &str, ) -> Result<String, Error>

GET /v0/domains/{domain_id}/zone-file, the DNS records as a ready-to-import zone file (plain text, not JSON).

Source§

impl Client

Source

pub async fn create_draft( &self, inbox_id: &str, draft: CreateDraft, ) -> Result<Draft, Error>

POST /v0/inboxes/{inbox_id}/drafts – create a draft. Supply in_reply_to to create a reply draft (with reply_all to address the whole thread) or forward_of to create a forward draft.

Source

pub async fn list_drafts(&self, inbox_id: &str) -> Result<DraftList, Error>

GET /v0/inboxes/{inbox_id}/drafts (first page; see Client::list_drafts_page).

Source

pub async fn list_drafts_page( &self, inbox_id: &str, page: Page, ) -> Result<DraftList, Error>

GET /v0/inboxes/{inbox_id}/drafts with pagination. Feed DraftList::next_page_token back in as Page::page_token until it comes back None.

Source

pub async fn get_draft( &self, inbox_id: &str, draft_id: &str, ) -> Result<Draft, Error>

GET /v0/inboxes/{inbox_id}/drafts/{draft_id}

Source

pub async fn update_draft( &self, inbox_id: &str, draft_id: &str, update: UpdateDraft, ) -> Result<Draft, Error>

PATCH /v0/inboxes/{inbox_id}/drafts/{draft_id} – edit fields on an existing draft. Passing None for an Option field leaves it unchanged; the API expects the field to be omitted, not set to null, when unchanged.

Source

pub async fn delete_draft( &self, inbox_id: &str, draft_id: &str, ) -> Result<(), Error>

DELETE /v0/inboxes/{inbox_id}/drafts/{draft_id}

Source

pub async fn send_draft( &self, inbox_id: &str, draft_id: &str, ) -> Result<SentMessage, Error>

POST /v0/inboxes/{inbox_id}/drafts/{draft_id}/send – send a draft. The draft is deleted after a successful send.

Source§

impl Client

Source

pub async fn list_inbox_events( &self, inbox_id: &str, ) -> Result<InboxEventList, Error>

GET /v0/inboxes/{inbox_id}/events (first page; see Client::list_inbox_events_page).

Source

pub async fn list_inbox_events_page( &self, inbox_id: &str, page: Page, ) -> Result<InboxEventList, Error>

GET /v0/inboxes/{inbox_id}/events with pagination, the inbox’s audit log.

Source§

impl Client

Source

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.

Source

pub async fn list_inboxes(&self) -> Result<InboxList, Error>

GET /v0/inboxes (first page; see Client::list_inboxes_page).

Source

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.

Source

pub async fn get_inbox(&self, inbox_id: &str) -> Result<Inbox, Error>

GET /v0/inboxes/{inbox_id}

Source

pub async fn update_inbox( &self, inbox_id: &str, update: UpdateInbox, ) -> Result<Inbox, Error>

PATCH /v0/inboxes/{inbox_id}, update the display name and/or metadata.

Source

pub async fn delete_inbox(&self, inbox_id: &str) -> Result<(), Error>

DELETE /v0/inboxes/{inbox_id}

Source§

impl Client

Source

pub async fn list_list_entries( &self, direction: ListDirection, kind: ListKind, ) -> Result<ListEntries, Error>

GET /v0/lists/{direction}/{kind} (first page; see Client::list_list_entries_page).

Source

pub async fn list_list_entries_page( &self, direction: ListDirection, kind: ListKind, page: Page, ) -> Result<ListEntries, Error>

GET /v0/lists/{direction}/{kind} with pagination. Feed ListEntries::next_page_token back in as Page::page_token until it comes back None.

Source

pub async fn create_list_entry( &self, direction: ListDirection, kind: ListKind, entry: CreateListEntry, ) -> Result<ListEntry, Error>

POST /v0/lists/{direction}/{kind}, add an address or domain to the list.

Source

pub async fn get_list_entry( &self, direction: ListDirection, kind: ListKind, entry: &str, ) -> Result<ListEntry, Error>

GET /v0/lists/{direction}/{kind}/{entry}

Source

pub async fn delete_list_entry( &self, direction: ListDirection, kind: ListKind, entry: &str, ) -> Result<(), Error>

DELETE /v0/lists/{direction}/{kind}/{entry}

Source§

impl Client

Source

pub async fn send_message( &self, inbox_id: &str, message: SendMessage, ) -> Result<SentMessage, Error>

POST /v0/inboxes/{inbox_id}/messages/send

Source

pub async fn send_text( &self, inbox_id: &str, to: &str, subject: &str, text: &str, ) -> Result<SentMessage, Error>

Send a plain-text message to a single recipient: the common case, in one line. For anything richer (HTML, cc/bcc, attachments, labels), build a SendMessage and call Client::send_message.

Source

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).

Source

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.

Source

pub async fn get_message( &self, inbox_id: &str, message_id: &str, ) -> Result<Message, Error>

GET /v0/inboxes/{inbox_id}/messages/{message_id}

Source

pub async fn reply_to_message( &self, inbox_id: &str, message_id: &str, reply: ReplyToMessage, ) -> Result<SentMessage, Error>

POST /v0/inboxes/{inbox_id}/messages/{message_id}/reply – reply to a message. The to field is derived from the parent message; only text/html/cc/bcc are caller-supplied.

Source

pub async fn reply_all_to_message( &self, inbox_id: &str, message_id: &str, reply: ReplyToMessage, ) -> Result<SentMessage, Error>

POST /v0/inboxes/{inbox_id}/messages/{message_id}/reply-all – reply to all recipients of a message.

Source

pub async fn update_message( &self, inbox_id: &str, message_id: &str, update: UpdateMessage, ) -> Result<UpdatedMessage, Error>

PATCH /v0/inboxes/{inbox_id}/messages/{message_id} – update a message’s labels (read state is a label, e.g. add/remove unread). Returns the message id and its labels after the change, not the full message body.

Source

pub async fn delete_message( &self, inbox_id: &str, message_id: &str, ) -> Result<(), Error>

DELETE /v0/inboxes/{inbox_id}/messages/{message_id} – permanently deletes a message.

Source

pub async fn list_messages_filtered( &self, inbox_id: &str, filters: MessageListFilters, ) -> Result<MessageList, Error>

GET /v0/inboxes/{inbox_id}/messages with filters and pagination. Pass MessageListFilters with any filter fields set to narrow results. Feed MessageList::next_page_token back in as MessageListFilters::page_token until it comes back None.

Source

pub async fn search_messages( &self, inbox_id: &str, query: &str, ) -> Result<MessageList, Error>

GET /v0/inboxes/{inbox_id}/messages/search with filters. Feed MessageList::next_page_token back in as MessageListFilters::page_token until it comes back None.

Source

pub async fn search_messages_page( &self, inbox_id: &str, query: &str, filters: MessageListFilters, ) -> Result<MessageList, Error>

GET /v0/inboxes/{inbox_id}/messages/search with pagination.

Source

pub async fn forward_message( &self, inbox_id: &str, message_id: &str, message: SendMessage, ) -> Result<SentMessage, Error>

POST /v0/inboxes/{inbox_id}/messages/{message_id}/forward, forward a message. Reuses SendMessage for the new recipients and any added body.

Source

pub async fn get_raw_message( &self, inbox_id: &str, message_id: &str, ) -> Result<RawMessage, Error>

GET /v0/inboxes/{inbox_id}/messages/{message_id}/raw, a presigned URL for the message’s raw RFC 822 (.eml) source. Fetch the bytes with Client::download_raw.

Source

pub async fn download_raw(&self, raw: &RawMessage) -> Result<Vec<u8>, Error>

Download the raw .eml bytes from a RawMessage’s presigned URL, without the API bearer token (the URL is already authenticated).

Source

pub async fn batch_get_messages( &self, inbox_id: &str, message_ids: Vec<String>, ) -> Result<BatchGetMessagesResponse, Error>

POST /v0/inboxes/{inbox_id}/messages/batch-get, fetch many messages by id in one call.

Source

pub async fn batch_update_messages( &self, inbox_id: &str, update: BatchUpdateMessages, ) -> Result<BatchUpdateMessagesResponse, Error>

POST /v0/inboxes/{inbox_id}/messages/batch-update, apply the same label changes to many messages at once.

Source§

impl Client

Source

pub async fn get_metrics_events( &self, query: MetricsQuery, ) -> Result<MetricsEvents, Error>

GET /v0/metrics/events, event counts bucketed over time, keyed by event type.

Source

pub async fn get_metrics_usage( &self, query: MetricsQuery, ) -> Result<MetricsUsage, Error>

GET /v0/metrics/usage, usage values bucketed over time, keyed by usage type.

Source§

impl Client

Source

pub async fn get_organization(&self) -> Result<Organization, Error>

GET /v0/organizations, the organization the current key belongs to, including its resource counts and plan limits.

Source§

impl Client

Source

pub async fn create_pod(&self, pod: CreatePod) -> Result<Pod, Error>

POST /v0/pods, create a pod.

Source

pub async fn list_pods(&self) -> Result<PodList, Error>

GET /v0/pods (first page; see Client::list_pods_page).

Source

pub async fn list_pods_page(&self, page: Page) -> Result<PodList, Error>

GET /v0/pods with pagination. Feed PodList::next_page_token back in as Page::page_token until it comes back None.

Source

pub async fn get_pod(&self, pod_id: &str) -> Result<Pod, Error>

GET /v0/pods/{pod_id}

Source

pub async fn delete_pod(&self, pod_id: &str) -> Result<(), Error>

DELETE /v0/pods/{pod_id}

Source§

impl Client

Source

pub async fn list_threads(&self, inbox_id: &str) -> Result<ThreadList, Error>

GET /v0/inboxes/{inbox_id}/threads (first page; see Client::list_threads_page).

Source

pub async fn list_threads_page( &self, inbox_id: &str, page: Page, ) -> Result<ThreadList, Error>

GET /v0/inboxes/{inbox_id}/threads with pagination. Feed ThreadList::next_page_token back in as Page::page_token until it comes back None.

Source

pub async fn list_threads_filtered( &self, inbox_id: &str, filters: ThreadListFilters, ) -> Result<ThreadList, Error>

GET /v0/inboxes/{inbox_id}/threads with filters and pagination. Pass ThreadListFilters with any fields set to narrow results.

Source

pub async fn search_threads( &self, inbox_id: &str, query: &str, ) -> Result<ThreadList, Error>

GET /v0/inboxes/{inbox_id}/threads/search, full-text search over the inbox’s threads. The matched fragments come back in Thread::highlights.

Source

pub async fn search_threads_page( &self, inbox_id: &str, query: &str, filters: ThreadListFilters, ) -> Result<ThreadList, Error>

GET /v0/inboxes/{inbox_id}/threads/search with filters and pagination.

Source

pub async fn get_thread( &self, inbox_id: &str, thread_id: &str, ) -> Result<Thread, Error>

GET /v0/inboxes/{inbox_id}/threads/{thread_id}, the full thread with its messages.

Source

pub async fn update_thread( &self, inbox_id: &str, thread_id: &str, update: UpdateThread, ) -> Result<UpdatedThread, Error>

PATCH /v0/inboxes/{inbox_id}/threads/{thread_id}, add and/or remove labels across the thread. Returns the thread id and its labels after the change.

Source

pub async fn delete_thread( &self, inbox_id: &str, thread_id: &str, ) -> Result<(), Error>

DELETE /v0/inboxes/{inbox_id}/threads/{thread_id}.

Source§

impl Client

Source

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.

Source

pub async fn list_webhooks(&self) -> Result<WebhookList, Error>

GET /v0/webhooks (first page; see Client::list_webhooks_page).

Source

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.

Source

pub async fn get_webhook(&self, webhook_id: &str) -> Result<Webhook, Error>

GET /v0/webhooks/{webhook_id}

Source

pub async fn update_webhook( &self, webhook_id: &str, update: UpdateWebhook, ) -> Result<Webhook, Error>

PATCH /v0/webhooks/{webhook_id}, edit event types and inbox/pod targeting. Inbox and pod sets change by delta (see UpdateWebhook).

Source

pub async fn delete_webhook(&self, webhook_id: &str) -> Result<(), Error>

DELETE /v0/webhooks/{webhook_id}

Source§

impl Client

Source

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.

Source

pub fn from_env() -> Result<Self, Error>

From AGENTMAIL_API_KEY (+ optional AGENTMAIL_BASE_URL).

Source

pub fn with_retry_policy(self, policy: RetryPolicy) -> Self

Available on crate feature retries only.

Replace the RetryPolicy. Set max_retries to 0 to disable retries.

Requires the retries feature (on by default).

Trait Implementations§

Source§

impl Debug for Client

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more