Expand description
Unofficial typed Rust client for AgentMail, the email API for agents (official SDKs exist for Python and TypeScript; this fills the Rust gap).
Wire shapes follow AgentMail’s OpenAPI spec (docs.agentmail.to/openapi.json,
API v0), with full coverage of the surface the official SDKs expose:
inboxes, threads, messages, drafts, attachments, webhooks, domains, pods,
allow/block lists, metrics, API keys, and agent onboarding. Everything
deserializes permissively - unknown fields are ignored, optional fields
default, so spec additions don’t break callers.
let client = agentmail::Client::from_env()?; // AGENTMAIL_API_KEY
let inbox = client
.create_inbox(agentmail::CreateInbox {
username: Some("my-agent".into()),
display_name: Some("My Agent".into()),
..Default::default()
})
.await?;
client
.send_message(
&inbox.inbox_id,
agentmail::SendMessage {
to: vec!["someone@example.com".into()],
subject: Some("Hello".into()),
text: Some("From an agent's own inbox.".into()),
..Default::default()
},
)
.await?;§Coverage
Inboxes, threads, messages (send/reply/forward/raw/batch), drafts,
attachments, webhooks, domains, pods, allow/block lists, metrics, inbox
events, API keys, organization, auth, and agent onboarding. Every list call
is paginated (Page), and requests carry automatic retries with backoff.
§Features
retries(default): automatic retries with exponential backoff. Turn it off withdefault-features = falseto drop the directtokiodependency; tune it withClient::with_retry_policy.webhook-verify(off by default):verify_webhook_signaturefor Svix-signed webhook deliveries. Addsring(already the rustls provider) andbase64.
Structs§
- Agent
Signup - Request body for
Client::agent_sign_up: start onboarding a new agent, which emails a one-time code tohuman_email. - Agent
Signup Result - The response to
Client::agent_sign_up: the new organization, inbox, and its API key. - Agent
Verify Result - The result of
Client::agent_verify. - ApiKey
- An API key’s metadata (never its secret material; see
CreatedApiKey). - ApiKey
List - One page of API keys from
Client::list_api_keys_page. - Attachment
- Attachment metadata as returned in message, thread, and draft responses.
download_url(a short-lived presigned URL) is populated only by the attachment-download endpoints; the other fields describe the attachment in list and get responses. - Batch
GetMessages - Request body for
Client::batch_get_messages. - Batch
GetMessages Response - Response to
Client::batch_get_messages. - Batch
Update Messages - Request body for
Client::batch_update_messages: apply the same label changes to many messages at once. - Batch
Update Messages Response - Response to
Client::batch_update_messages. - Client
- An authenticated handle on the AgentMail API. Cheap to clone-ish (it owns
a pooled
reqwest::Client); construct once and share by reference. - Create
ApiKey - Request body for
Client::create_api_key. - Create
Domain - Request body for
Client::create_domain. - Create
Draft - Request body for
Client::create_draft. At least one recipient or a reply/forward-of reference and one oftext/htmlare required by the API. - Create
Inbox - Request body for
Client::create_inbox. All fields optional; the API generates a username when none is given. - Create
List Entry - Request body for
Client::create_list_entry. - Create
Pod - Request body for
Client::create_pod. All fields optional. - Create
Webhook - Request body for
Client::create_webhook. - Created
ApiKey - The response to
Client::create_api_key. The fullapi_keysecret is returned exactly once, here; store it now, as it cannot be retrieved again. - Domain
- A sending domain, as the API returns it.
- Domain
List - One page of domains from
Client::list_domains_page. - Draft
- A draft message, as the API returns it. List items are a subset of the full get-draft shape; every optional field defaults so both parse.
- Draft
List - One page of drafts from
Client::list_drafts_page. - Identity
- Who the current API key authenticates as, from
Client::auth_me. - Inbox
- An agent-owned inbox, as the API returns it.
- Inbox
Event - An entry in an inbox’s audit log (label changes, deliveries, etc.).
- Inbox
Event List - One page of inbox events from
Client::list_inbox_events_page. - Inbox
List - One page of inboxes from
Client::list_inboxes_page. - List
Entries - One page of list entries from
Client::list_list_entries_page. - List
Entry - A single allow/block list entry.
- Message
- A message as the API returns it. List items are a subset of the full get-message shape; every non-id field defaults so both parse.
- Message
List - One page of messages from
Client::list_messages_page. - Message
List Filters - Filters for
Client::list_messages_filteredandClient::search_messages_page. Pagination fields (limit,page_token) live here because they share the same query-parameter namespace as the filter fields. - Metric
Bucket - One time-bucket of an event metric.
- Metrics
Query - Query parameters for
Client::get_metrics_eventsandClient::get_metrics_usage.typesfilters by event/usage type; leave it empty for all. - Organization
- The organization the current API key belongs to, from
Client::get_organization. - Page
- Pagination controls for the
list_*_pagecalls.Defaultis the API’s own defaults (first page, server-chosen page size). - Pod
- A pod, a container that owns inboxes and other resources.
- PodList
- One page of pods from
Client::list_pods_page. - RawMessage
- The presigned download for a message’s raw RFC 822 source, from
Client::get_raw_message. Fetch the bytes withClient::download_raw. - Reply
ToMessage - Request body for
Client::reply_to_messageandClient::reply_all_to_message. Thetofield is derived from the parent message; at least one oftext/htmlis required by the API. - Retry
Policy retries - How the client retries transient failures. Applied to every request at the
one HTTP chokepoint.
Defaultretries twice with exponential backoff. - Send
Attachment - An attachment to include on an outgoing message or draft. Supply the bytes
inline as base64
content, or aurlfor the API to fetch; setcontent_idto reference the attachment inline from the HTML body. - Send
Message - Request body for
Client::send_message. At least one recipient intoand one oftext/htmlare required by the API. - Sent
Message - The API’s acknowledgement of a send.
- Thread
- A conversation thread. List items omit
messages; the get-thread shape includes them and search results carryhighlights; every optional field defaults so all three parse into this one type. - Thread
List - One page of threads from a list or search call.
- Thread
List Filters - Filters for
Client::list_threads_filteredandClient::search_threads_page. Pagination fields (limit,page_token) share the same query-parameter namespace as the filters. - Update
Domain - Request body for
Client::update_domain. Fields leftNonestay unchanged. - Update
Draft - Request body for
Client::update_draft. Every field is optional; omitted fields are left unchanged on the server. PassSome(vec![])to clear a recipient field; passNoneto leave it alone. - Update
Inbox - Request body for
Client::update_inbox. Fields leftNoneare omitted and stay unchanged; setmetadatatoSome(Value::Null)to clear it. - Update
Message - Request body for
Client::update_message. - Update
Thread - Request body for
Client::update_thread: labels to add and/or remove. - Update
Webhook - Request body for
Client::update_webhook. Every field is optional; leave a field empty to keep it unchanged. Inbox and pod targeting is edited by delta (add/remove lists) rather than by replacing the whole set. - Updated
Message - The API’s response to
Client::update_message: the message id and its labels after the update. - Updated
Thread - The API’s response to
Client::update_thread: the thread id and its labels after the update. - Usage
Point - One time-bucket of a usage metric.
- Verification
Record - A single DNS record to publish for a domain.
- Webhook
- A webhook subscription, as the API returns it.
- Webhook
List - One page of webhooks from
Client::list_webhooks_page.
Enums§
- Entry
Type - Whether a list entry is an address or a whole domain.
- Error
- Everything that can go wrong talking to AgentMail.
- List
Direction - Which traffic direction a list governs.
- List
Kind - Whether a list allows or blocks its entries.
- Scope
Type - What an API key is scoped to.
- Signature
Error webhook-verify - Why webhook verification failed. Verification never “passes open”: a missing or malformed secret, header, or signature is always an error.
Constants§
- DEFAULT_
BASE_ URL - The production API host. Override with
Client::new(key, base_url)for the EU region (https://api.agentmail.eu) or a mock server. - DEFAULT_
TIMEOUT - The per-request timeout applied by
Client::new(connect + response). - DEFAULT_
WEBHOOK_ TOLERANCE webhook-verify - The Svix-recommended timestamp tolerance (5 minutes).
Functions§
- verify_
webhook_ signature webhook-verify - Verify a webhook delivery’s signature.
- verify_
webhook_ timestamp webhook-verify - Reject deliveries whose
svix-timestampis more thantoleranceaway from now (in either direction), the standard defense against replayed payloads. SeeDEFAULT_WEBHOOK_TOLERANCE.
Type Aliases§
- Metrics
Events - Event metrics keyed by event type (e.g.
message.received). - Metrics
Usage - Usage metrics keyed by usage type.