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.
Resources that exist at more than one scope (threads, webhooks, lists,
domains, …) are reached through a scope handle (Client::org,
Client::inbox, or Client::pod), so the compiler rejects an
operation the scope doesn’t support. Inbox-only resources (messages, drafts)
live on Client::inbox.
let client = agentmail::Client::from_env()?; // AGENTMAIL_API_KEY
let inbox = client
.org()
.create_inbox(agentmail::CreateInbox {
username: Some("my-agent".into()),
display_name: Some("My Agent".into()),
..Default::default()
})
.await?; // my-agent@agentmail.to
client
.inbox(&inbox.inbox_id)
.send_text("someone@example.com", "Hello", "From an agent's own inbox.")
.await?;§Coverage
Inboxes (incl. search and authorization), threads, messages
(send/reply/forward/raw/batch, open tracking), drafts (incl. attachment
deltas), attachments, webhooks (incl. custom delivery headers), domains
(incl. provider setup links), pods, allow/block lists, metrics
(events/usage/rates), inbox events, calendars, accounts, apps, API keys
(bearer and public-key), organization, auth, and agent onboarding. Every
list call is paginated (Page), and requests carry automatic retries with
backoff.
Not bound as REST: the official SDKs’ WebSocket / realtime event
stream is bound behind the websockets feature (see
RealtimeStream); the REST surface here is complete without it.
§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.websockets(off by default):Client::connect_realtimefor the realtime event stream, so agents without a public webhook URL can receive mail. Addstokio-tungstenite(rustls, webpki roots) andfutures-util; see theRealtimeStreamtype.
Structs§
- Account
- A human account (an app connection): who signed in to which app, through which inbox, and when.
- Account
List - One page of accounts from
list_accounts. - Accounts
List Filters - List filters for
list_accounts(includes pagination, like the other filter structs). - Agent
Attach Human - Request body for
agent_attach_human: email a claim link that connects a human to this agent’s organization. - Agent
Attach Human Result - The response to
agent_attach_human. - Agent
Signup - Request body for
agent_sign_up: start onboarding a new agent, which emails a one-time code tohuman_emailwhen given.usernameis the only required field; withouthuman_emailthe inbox is created unattached to a human (attach one later withcrate::Client::agent_attach_human). - Agent
Signup Result - The response to
agent_sign_up: the new organization, inbox, and its API key. - Agent
Verify Result - The result of
agent_verify. - ApiKey
- An API key, as the API returns it. The wire shape is a oneOf over bearer
keys and
public_keycredentials; every field defaults so both parse. The secret material itself is never returned here (seeCreatedApiKey). - ApiKey
Creator - The agent that created a
public_keyAPI key. - ApiKey
List - One page of API keys from
list_api_keys_page. - App
- An app that can connect to AgentMail inboxes, from the app directory.
- AppAccount
List - One page of an app’s accounts from
list_app_accounts. - AppList
- One page of apps from
list_apps. - AppSearch
List - One page of apps from
search_apps(no pagination cursor). - Apps
List Filters - List filters for
list_apps(includes pagination). - 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. - Authorize
Inbox - Body for
authorize_inbox: complete a human authorization started in the browser. Theauth_tokencomes from that flow. - Authorize
Inbox Result - The response to
authorize_inbox. - Batch
GetMessages - Request body for
batch_get_messages. - Batch
GetMessages Response - Response to
batch_get_messages. - Batch
Update Messages - Request body for
batch_update_messages: apply the same label changes to many messages at once. - Batch
Update Messages Response - Response to
batch_update_messages. - Bounce
Payload websockets - Bounce details, from
message.bounced. - Calendar
- An inbox’s calendar, from
get_calendar/update_calendar. - Calendar
Attendee - An attendee on an event.
- Calendar
Event - A calendar event, as the API returns it.
- Calendar
Event Created Event websockets - A decoded event frame; see the module docs for the protocol.
- Calendar
Event Deleted Event websockets - A decoded event frame; see the module docs for the protocol.
- Calendar
Event Ending Event websockets - A decoded event frame; see the module docs for the protocol.
- Calendar
Event List - One page of occurrences from
get_agendaorlist_event_instances. - Calendar
Event Mutation - The response to an event create/update: the mutated event plus the operation id (used by the API’s event stream to ack the change).
- Calendar
Event Previous websockets - A calendar event’s state before an update, all fields optional.
- Calendar
Event Responded Event websockets - A decoded event frame; see the module docs for the protocol.
- Calendar
Event Starting Event websockets - A decoded event frame; see the module docs for the protocol.
- Calendar
Event Updated Event websockets - A decoded event frame; see the module docs for the protocol.
- Calendar
Events Query - Windowing and pagination for
get_agendaandlist_event_instances. - Client
- An authenticated handle on the AgentMail API. Cheap to clone-ish (it owns
a pooled
reqwest::Client); construct once and share by reference. - Complaint
Payload websockets - Complaint details, from
message.complained. - Connect
App - Body for
connect_app: start a human’s connection to an app. The human opensConnectAppResult::magic_urland approves; the API key id in the result is the connection’s credential handle. - Connect
AppResult - The response to
connect_app. - Create
ApiKey - Request body for
create_api_key. The default (nopublic_key) mints a bearer key; settingpublic_keyregisters apublic_keycredential instead. The full secret of a bearer key is returned exactly once, inCreatedApiKey::api_key. - Create
Calendar Event - Body for
create_calendar_event.title,start, andendare required by the API. - Create
Domain - Request body for
create_domain. - Create
Draft - Request body for
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
create_inbox. All fields optional; the API generates a username when none is given. - Create
List Entry - Request body for
create_list_entry. - Create
Pod - Request body for
create_pod. All fields optional. - Create
Webhook - Request body for
create_webhook. - Created
ApiKey - The response to
create_api_key. The fullapi_keysecret is returned exactly once, here; store it now, as it cannot be retrieved again. - Delete
Calendar Event Result - The response to
delete_calendar_event;eventcarries the deleted state when the API returns it. - Dispatch
Payload websockets - Send/delivery details, from
message.sentandmessage.delivered. - Domain
- A sending domain, as the API returns it.
- Domain
List - One page of domains from
list_domains_page. - Domain
Setup Link - The provider setup link for a domain, from
get_domain_setup_link. WhenDomainSetupLink::supportedis false the registrar/provider flow isn’t available and DNS records must be configured manually. - Domain
Verified Event websockets - A decoded event frame; see the module docs for the protocol.
- 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
list_drafts_page. - Event
Recipient websockets - A per-recipient delivery status, from bounce events.
- Identity
- Who the current API key authenticates as, from
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
list_inbox_events_page. - Inbox
List - One page of inboxes from
list_inboxes_page. - Inbox
Scope - A single inbox scope (
/v0/inboxes/{inbox_id}/...). - List
Entries - One page of list entries from
list_list_entries_page. - List
Entry - A single allow/block list entry.
- Message
- A message as the API returns it. List and search items are a subset of the full get-message shape; every non-id field defaults so all three parse.
- Message
Bounced Event websockets - A decoded event frame; see the module docs for the protocol.
- Message
Complained Event websockets - A decoded event frame; see the module docs for the protocol.
- Message
Delivered Event websockets - A decoded event frame; see the module docs for the protocol.
- Message
List - One page of messages from
list_messages_page. - Message
List Filters - Filters for
list_messages_filteredandsearch_messages_page. Pagination fields (limit,page_token) live here because they share the same query-parameter namespace as the filter fields. - Message
Opened Event websockets - A decoded event frame; see the module docs for the protocol.
- Message
Received Event websockets - One event off the wire, decoded.
- Message
Rejected Event websockets - A decoded event frame; see the module docs for the protocol.
- Message
Sent Event websockets - A decoded event frame; see the module docs for the protocol.
- Metric
Bucket - One time-bucket of an event metric.
- Metrics
Query - Query parameters for the metrics endpoints (
get_metrics_events,get_metrics_usage,get_metrics_rates).typesfilters by event/usage/rate type; leave it empty for all.windowis only meaningful for rates (the bucket the rate is computed over, in seconds). - Open
Payload websockets - Recipient-open details, from
message.opened. - OrgScope
- The organization scope (top-level,
/v0/...), spanning every inbox. - Organization
- The organization the current API key belongs to, from
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
list_pods_page. - PodScope
- A single pod scope (
/v0/pods/{pod_id}/...). - Public
KeyMaterial - The public-key material bound to a
public_keyAPI key (JWK plus its RFC 7638 thumbprint), as the API returns it. - Rate
Point - One time-bucket of a rate metric (bounce/complaint percentages).
- RawMessage
- The presigned download for a message’s raw RFC 822 source, from
get_raw_message. Fetch the bytes withdownload_raw. - Realtime
Stream websockets - An open realtime stream. Send one
Subscribe(done for you byClient::connect_realtime), then pollRealtimeStream::next_event. - Recurrence
- Recurrence rule and exceptions on an event.
rdatesentries are either an RFC 3339 timestamp or a{start, end?, duration?}object, so they are kept as raw JSON. - Reject
Payload websockets - Rejection details, from
message.rejected. - Reply
ToMessage - Request body for
reply_to_messageandreply_all_to_message.tooverrides the derived recipients when non-empty; at least one oftext/htmlis required by the API. - Respond
ToCalendar Event - Body for
respond_to_calendar_event: the inbox’s reply to an invite. - Retry
Policy retries - How the client retries transient failures. Applied to every request at the
one HTTP chokepoint.
Defaultretries twice with exponential backoff. - Scoped
- A
Clientbound to aScope. Returned byClient::org,Client::inbox, andClient::pod; the resource methods it exposes depend on which capability traits the scopeSimplements. - 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
send_message. At least one recipient intoand one oftext/htmlare required by the API. - Sent
Message - The API’s acknowledgement of a send.
- Subscribe
websockets - A subscribe request: which events, and for which inboxes or pods. Empty filters mean “everything the key can see”.
- Subscribed
websockets - The server’s acknowledgement of a
Subscribeframe. - 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
list_threads_filteredandsearch_threads_page. Pagination fields (limit,page_token) share the same query-parameter namespace as the filters. - Update
Account - Body for
update_account. Fields leftNonestay unchanged. - Update
ApiKey - Body for
update_api_key. Fields leftNonestay unchanged. - Update
Calendar Event - Body for
update_calendar_event. Fields leftNonestay unchanged; there is no way to set a field back to null from this client (the API accepts nulls fordescription/location/metadata/recurrence, butNonehere means “leave alone”, matchingcrate::UpdateDraft). - Update
Domain - Request body for
update_domain. Fields leftNonestay unchanged. - Update
Draft - Request body for
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
update_inbox. Fields leftNoneare omitted and stay unchanged; setmetadatatoSome(Value::Null)to clear it. - Update
Message - Request body for
update_message. - Update
Thread - Request body for
update_thread: labels to add and/or remove. - Update
Webhook - Request body for
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. - Update
Webhook Headers - Body for
update_webhook_headers: headers to set or replace, plus names to remove. Applied to every delivery of that webhook. - Updated
Message - The API’s response to
update_message: the message id and its labels after the update. - Updated
Thread - The API’s response to
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
Header Names - The header names configured on a webhook, from
get_webhook_headers(values are never returned). - Webhook
List - One page of webhooks from
list_webhooks_page.
Enums§
- Consistency
- Read-staleness control for calendar reads.
primary(the API default) reads the authoritative store;eventualmay serve a replica. - Duration
Mode - How an event’s
duration_valueis interpreted. - Entry
Type - Whether a list entry is an address or a whole domain.
- Error
- Everything that can go wrong talking to AgentMail.
- Event
Kind - Whether an event occurs once or as part of a series.
- Event
Source - Where an event came from.
- Event
Status - Confirmation state of an event.
- List
Direction - Which traffic direction a list governs. A path input only (there is no wire value to decode), so it has no unknown variant.
- List
Kind - Whether a list allows or blocks its entries. A path input only, so it has no unknown variant.
- Mutation
Mode - Which occurrences a series mutation applies to.
- Realtime
Event websockets - One frame from the stream.
- Response
Status - The organizer’s response state on an event the inbox was invited to.
- 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).
- DEFAULT_
WEBSOCKET_ URL websockets - The production realtime host. See the module docs for how the URL is derived and overridden.
Traits§
- ApiKeys
- Scopes with API keys (org / inbox / pod).
- Domains
- Scopes with domains (org / pod). Inboxes have no domains.
- Drafts
- Scopes with readable drafts (org / inbox / pod). Draft writes (create,
update, delete, send) are inbox-only and live on
Scoped<InboxScope>. - Inboxes
- Scopes that contain inboxes (org / pod): list, create, get, update, delete inboxes within the scope. A pod owns its inboxes; the org owns all of them.
- Lists
- Scopes with allow/block lists (org / inbox / pod).
- Metrics
- Scopes with metrics (org / inbox / pod).
- Scope
- A scope’s URL prefix. Implemented by
OrgScope,InboxScope, andPodScope. - Threads
- Scopes with threads (org / inbox / pod).
- Webhooks
- Scopes with webhooks (org / inbox / pod).
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§
- ApiKey
Permissions - An API key’s permission flags, keyed by permission name (e.g.
message_send,calendar_event_create). Modeled as a map so permission additions don’t require a client release; unknown names are preserved. - Metrics
Events - Event metrics keyed by event type (e.g.
message.received). - Metrics
Rates - Rate metrics keyed by rate type (
bounce,complaint). - Metrics
Usage - Usage metrics keyed by usage type.