agentmail 0.3.7 → 0.3.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/dist/cjs/BaseClient.js +2 -2
  2. package/dist/cjs/api/resources/inboxes/resources/messages/client/Client.js +2 -1
  3. package/dist/cjs/api/resources/inboxes/resources/messages/client/requests/ListMessagesRequest.d.ts +1 -0
  4. package/dist/cjs/api/resources/inboxes/resources/threads/client/Client.js +2 -1
  5. package/dist/cjs/api/resources/inboxes/resources/threads/client/requests/ListThreadsRequest.d.ts +1 -0
  6. package/dist/cjs/api/resources/pods/resources/domains/client/Client.d.ts +12 -0
  7. package/dist/cjs/api/resources/pods/resources/domains/client/Client.js +63 -0
  8. package/dist/cjs/api/resources/pods/resources/threads/client/Client.js +2 -1
  9. package/dist/cjs/api/resources/pods/resources/threads/client/requests/ListThreadsRequest.d.ts +1 -0
  10. package/dist/cjs/api/types/IncludeTrash.d.ts +4 -0
  11. package/dist/cjs/api/types/IncludeTrash.js +3 -0
  12. package/dist/cjs/api/types/index.d.ts +1 -0
  13. package/dist/cjs/api/types/index.js +1 -0
  14. package/dist/cjs/serialization/types/IncludeTrash.d.ts +7 -0
  15. package/dist/cjs/serialization/types/IncludeTrash.js +39 -0
  16. package/dist/cjs/serialization/types/index.d.ts +1 -0
  17. package/dist/cjs/serialization/types/index.js +1 -0
  18. package/dist/cjs/version.d.ts +1 -1
  19. package/dist/cjs/version.js +1 -1
  20. package/dist/esm/BaseClient.mjs +2 -2
  21. package/dist/esm/api/resources/inboxes/resources/messages/client/Client.mjs +2 -1
  22. package/dist/esm/api/resources/inboxes/resources/messages/client/requests/ListMessagesRequest.d.mts +1 -0
  23. package/dist/esm/api/resources/inboxes/resources/threads/client/Client.mjs +2 -1
  24. package/dist/esm/api/resources/inboxes/resources/threads/client/requests/ListThreadsRequest.d.mts +1 -0
  25. package/dist/esm/api/resources/pods/resources/domains/client/Client.d.mts +12 -0
  26. package/dist/esm/api/resources/pods/resources/domains/client/Client.mjs +63 -0
  27. package/dist/esm/api/resources/pods/resources/threads/client/Client.mjs +2 -1
  28. package/dist/esm/api/resources/pods/resources/threads/client/requests/ListThreadsRequest.d.mts +1 -0
  29. package/dist/esm/api/types/IncludeTrash.d.mts +4 -0
  30. package/dist/esm/api/types/IncludeTrash.mjs +2 -0
  31. package/dist/esm/api/types/index.d.mts +1 -0
  32. package/dist/esm/api/types/index.mjs +1 -0
  33. package/dist/esm/serialization/types/IncludeTrash.d.mts +7 -0
  34. package/dist/esm/serialization/types/IncludeTrash.mjs +3 -0
  35. package/dist/esm/serialization/types/index.d.mts +1 -0
  36. package/dist/esm/serialization/types/index.mjs +1 -0
  37. package/dist/esm/version.d.mts +1 -1
  38. package/dist/esm/version.mjs +1 -1
  39. package/dist/llms-full.txt +623 -184
  40. package/dist/llms.txt +2 -0
  41. package/package.json +1 -1
  42. package/reference.md +57 -0
@@ -171,6 +171,45 @@ Follow this guide to make your first AgentMail API request and create a new
171
171
  email inbox.
172
172
  ------------
173
173
 
174
+ ## Quickest start
175
+
176
+ <CodeBlocks>
177
+ ```bash title="Python"
178
+ pip install agentmail
179
+ ```
180
+
181
+ ```bash title="TypeScript"
182
+ npm install agentmail
183
+ ```
184
+ </CodeBlocks>
185
+
186
+ Get your API key from the [Console](https://console.agentmail.to) and replace `am_...` in the code below.
187
+
188
+ <CodeBlocks>
189
+ ```python title="Python"
190
+ from agentmail import AgentMail
191
+
192
+ client = AgentMail(api_key="am_...")
193
+ inbox = client.inboxes.create()
194
+ client.inboxes.messages.send(inbox.inbox_id, to="user@example.com", subject="Hello", text="Hello from my agent!")
195
+ ```
196
+
197
+ ```typescript title="TypeScript"
198
+ import { AgentMailClient } from "agentmail";
199
+
200
+ (async () => {
201
+ const client = new AgentMailClient({ apiKey: "am_..." });
202
+ const inbox = await client.inboxes.create();
203
+ await client.inboxes.messages.send(inbox.inboxId, { to: "user@example.com", subject: "Hello", text: "Hello from my agent!" });
204
+ })();
205
+ ```
206
+ </CodeBlocks>
207
+
208
+ <Tip>
209
+ When receiving emails, messages include `extracted_text` and `extracted_html`
210
+ for reply content without quoted history.
211
+ </Tip>
212
+
174
213
  This guide will walk you through installing the AgentMail SDK, authenticating with your API key, and creating your first email inbox.
175
214
 
176
215
  <Steps>
@@ -235,11 +274,10 @@ This guide will walk you through installing the AgentMail SDK, authenticating wi
235
274
  # Send Email
236
275
 
237
276
  client.inboxes.messages.send(
238
- inbox_id="your-email@example.com",
239
- to="contact@agentmail.to",
240
- subject="Hello from AgentMail!",
241
- text="This is my first email sent with the AgentMail API."
242
-
277
+ inbox.inbox_id,
278
+ to="your-email@example.com",
279
+ subject="Hello from AgentMail!",
280
+ text="This is my first email sent with the AgentMail API.",
243
281
  )
244
282
 
245
283
  ```
@@ -619,6 +657,8 @@ You can retrieve the details of any specific `Message` by providing its ID along
619
657
  ```
620
658
  </CodeBlocks>
621
659
 
660
+ When receiving replies or forwards, use `extracted_text` or `extracted_html` for just the new content—quoted history is stripped automatically.
661
+
622
662
  ### Crafting Your Message: HTML, Text, and CSS
623
663
 
624
664
  When sending a `Message`, you can provide the body in two formats: `text` for a plain-text version and `html` for a rich, styled version.
@@ -1180,6 +1220,99 @@ This is where `Labels` become truly powerful. You can list `Threads`, `Messages`
1180
1220
  </Callout>
1181
1221
 
1182
1222
 
1223
+ ***
1224
+
1225
+ title: Lists
1226
+ subtitle: Filter emails by allowing or blocking specific addresses and domains.
1227
+ slug: lists
1228
+ description: >-
1229
+ Learn how to use Lists to control which email addresses and domains your
1230
+ agents can send to or receive from.
1231
+ -----------------------------------
1232
+
1233
+ ## What are Lists?
1234
+
1235
+ `Lists` allow you to filter emails by allowing or blocking specific email addresses or domains. There are four list types based on two dimensions:
1236
+
1237
+ * **Direction**: `send` or `receive`
1238
+ * **Type**: `allow` or `block`
1239
+
1240
+ | List | Description |
1241
+ | ------------- | ---------------------------------------------------- |
1242
+ | Receive allow | Only accept emails from these addresses or domains |
1243
+ | Receive block | Reject emails from these addresses or domains |
1244
+ | Send allow | Only send emails to these addresses or domains |
1245
+ | Send block | Prevent sending emails to these addresses or domains |
1246
+
1247
+ Each entry can be either a full email address (e.g., `partner@example.com`) or an entire domain (e.g., `example.com`).
1248
+
1249
+ ## SDK examples
1250
+
1251
+ ### List entries
1252
+
1253
+ Retrieve entries from a list with optional pagination.
1254
+
1255
+ <CodeBlocks>
1256
+ ```python title="Python"
1257
+ entries = client.lists.list("receive", "allow", limit=10)
1258
+ ```
1259
+
1260
+ ```typescript title="TypeScript"
1261
+ const entries = await client.lists.list("receive", "allow", { limit: 10 });
1262
+ ```
1263
+ </CodeBlocks>
1264
+
1265
+ ### Create entry
1266
+
1267
+ Add an email address or domain to a list. The `reason` parameter is optional and available on block lists.
1268
+
1269
+ <CodeBlocks>
1270
+ ```python title="Python"
1271
+ # allow list - no reason needed
1272
+ client.lists.create("receive", "allow", entry="partner@example.com")
1273
+
1274
+ # block list - reason optional
1275
+ client.lists.create("receive", "block", entry="spam@example.com", reason="spam")
1276
+ ```
1277
+
1278
+ ```typescript title="TypeScript"
1279
+ // allow list - no reason needed
1280
+ await client.lists.create("receive", "allow", { entry: "partner@example.com" });
1281
+
1282
+ // block list - reason optional
1283
+ await client.lists.create("receive", "block", { entry: "spam@example.com", reason: "spam" });
1284
+ ```
1285
+ </CodeBlocks>
1286
+
1287
+ ### Get entry
1288
+
1289
+ Retrieve a specific entry from a list by its email address or domain.
1290
+
1291
+ <CodeBlocks>
1292
+ ```python title="Python"
1293
+ entry = client.lists.get("receive", "allow", entry="partner@example.com")
1294
+ ```
1295
+
1296
+ ```typescript title="TypeScript"
1297
+ const entry = await client.lists.get("receive", "allow", "partner@example.com");
1298
+ ```
1299
+ </CodeBlocks>
1300
+
1301
+ ### Delete entry
1302
+
1303
+ Remove an entry from a list.
1304
+
1305
+ <CodeBlocks>
1306
+ ```python title="Python"
1307
+ client.lists.delete("receive", "allow", entry="partner@example.com")
1308
+ ```
1309
+
1310
+ ```typescript title="TypeScript"
1311
+ await client.lists.delete("receive", "allow", "partner@example.com");
1312
+ ```
1313
+ </CodeBlocks>
1314
+
1315
+
1183
1316
  ***
1184
1317
 
1185
1318
  title: Attachments
@@ -2196,6 +2329,164 @@ Email is critical to identity and communication on the internet. Much of the con
2196
2329
  These are just a few select verticals, but we have seen AgentMail be effective in automating any email task across every function. If a human does it with email, it can be automated with AgentMail.
2197
2330
 
2198
2331
 
2332
+ ***
2333
+
2334
+ title: x402
2335
+ subtitle: Pay-per-use AgentMail with the x402 payment protocol
2336
+ slug: integrations/x402
2337
+ description: AgentMail's x402 integration for HTTP-native payments
2338
+ ------------------------------------------------------------------
2339
+
2340
+ ## Getting started
2341
+
2342
+ [x402](https://www.x402.org/) is an open payment protocol that enables HTTP-native payments. By integrating x402 with AgentMail, your agents can pay for API usage directly over HTTP without managing API keys or subscriptions.
2343
+
2344
+ ### Base URLs
2345
+
2346
+ To authenticate with x402 instead of an API key, you must use the x402-specific base URLs below. These replace the default AgentMail base URLs and route requests through the x402 payment layer.
2347
+
2348
+ | Protocol | URL |
2349
+ | --------- | ----------------------- |
2350
+ | HTTP | `x402.api.agentmail.to` |
2351
+ | WebSocket | `x402.ws.agentmail.to` |
2352
+
2353
+ ### Prerequisites
2354
+
2355
+ * A crypto wallet with USDC funds (EVM-compatible wallet on Base, or a Solana wallet)
2356
+ * Node.js installed
2357
+
2358
+ ### Install dependencies
2359
+
2360
+ <CodeBlocks>
2361
+ ```bash title="EVM"
2362
+ npm install agentmail @x402/fetch @x402/evm viem
2363
+ ```
2364
+
2365
+ ```bash title="Solana"
2366
+ npm install agentmail @x402/fetch @x402/svm @solana/kit @scure/base
2367
+ ```
2368
+ </CodeBlocks>
2369
+
2370
+ ### Quickstart
2371
+
2372
+ <CodeBlocks>
2373
+ ```typescript title="EVM"
2374
+ import { privateKeyToAccount } from "viem/accounts";
2375
+ import { x402Client } from "@x402/fetch";
2376
+ import { ExactEvmScheme } from "@x402/evm/exact/client";
2377
+
2378
+ import { AgentMailClient } from "agentmail";
2379
+
2380
+
2381
+ // setup x402 client
2382
+
2383
+ const PRIVATE_KEY = "0x...";
2384
+
2385
+ const signer = privateKeyToAccount(PRIVATE_KEY);
2386
+
2387
+ const x402 = new x402Client();
2388
+ x402.register("eip155:*", new ExactEvmScheme(signer));
2389
+
2390
+
2391
+ // setup AgentMail client
2392
+
2393
+ export const client = new AgentMailClient({ x402 });
2394
+
2395
+
2396
+ // create inbox
2397
+
2398
+ const inboxRes = await client.inboxes.create({
2399
+ username: `x402-${Date.now()}`,
2400
+ });
2401
+ console.log("Created inbox: ", inboxRes.inboxId);
2402
+
2403
+
2404
+ // subscribe to inbox
2405
+
2406
+ const socket = await client.websockets.connect();
2407
+ console.log("Connected to websocket");
2408
+
2409
+ socket.on("message", async (event) => {
2410
+ if (event.type === "subscribed") {
2411
+ console.log("Subscribed to", event.inboxIds);
2412
+ } else if (event.type === "event" && event.eventType === "message.received") {
2413
+ console.log("Received message from: ", event.message.from);
2414
+ }
2415
+ });
2416
+
2417
+ socket.sendSubscribe({
2418
+ type: "subscribe",
2419
+ inboxIds: [inboxRes.inboxId],
2420
+ });
2421
+ ```
2422
+
2423
+ ```typescript title="Solana"
2424
+ import { createKeyPairSignerFromBytes } from "@solana/kit";
2425
+ import { base58 } from "@scure/base";
2426
+ import { x402Client } from "@x402/fetch";
2427
+ import { ExactSvmClient, toClientSvmSigner } from "@x402/svm";
2428
+
2429
+ import { AgentMailClient } from "agentmail";
2430
+
2431
+
2432
+ // setup x402 client
2433
+
2434
+ const PRIVATE_KEY = "base58-encoded-private-key...";
2435
+
2436
+ const keypair = await createKeyPairSignerFromBytes(
2437
+ base58.decode(PRIVATE_KEY)
2438
+ );
2439
+
2440
+ const x402 = new x402Client();
2441
+ x402.register("solana:*", new ExactSvmClient(toClientSvmSigner(keypair)));
2442
+
2443
+
2444
+ // setup AgentMail client
2445
+
2446
+ export const client = new AgentMailClient({ x402 });
2447
+
2448
+
2449
+ // create inbox
2450
+
2451
+ const inboxRes = await client.inboxes.create({
2452
+ username: `x402-${Date.now()}`,
2453
+ });
2454
+ console.log("Created inbox: ", inboxRes.inboxId);
2455
+
2456
+
2457
+ // subscribe to inbox
2458
+
2459
+ const socket = await client.websockets.connect();
2460
+ console.log("Connected to websocket");
2461
+
2462
+ socket.on("message", async (event) => {
2463
+ if (event.type === "subscribed") {
2464
+ console.log("Subscribed to", event.inboxIds);
2465
+ } else if (event.type === "event" && event.eventType === "message.received") {
2466
+ console.log("Received message from: ", event.message.from);
2467
+ }
2468
+ });
2469
+
2470
+ socket.sendSubscribe({
2471
+ type: "subscribe",
2472
+ inboxIds: [inboxRes.inboxId],
2473
+ });
2474
+ ```
2475
+ </CodeBlocks>
2476
+
2477
+ ## How it works
2478
+
2479
+ When you pass an `x402` client to `AgentMailClient`, the SDK automatically handles payment negotiation for each API request. If the server responds with a `402 Payment Required` status, the x402 client signs a payment using your wallet and retries the request with the payment attached.
2480
+
2481
+ This means your agent can use the full AgentMail API (inboxes, messages, threads, attachments) without needing a traditional API key. Payment happens per-request over HTTP.
2482
+
2483
+ ## Resources
2484
+
2485
+ * [x402 documentation](https://www.x402.org/)
2486
+ * [AgentMail API reference](/api-reference)
2487
+ * [WebSockets overview](/websockets)
2488
+
2489
+
2199
2490
  ***
2200
2491
 
2201
2492
  title: 'Guide: Sending & Receiving Email'
@@ -2289,6 +2580,11 @@ Here's the step-by-step logic for a polling-based conversational agent.
2289
2580
  const messageIdToReplyTo = lastMessage.message_id;
2290
2581
  ```
2291
2582
  </CodeBlocks>
2583
+
2584
+ <Tip>
2585
+ Use `last_message.extracted_text` (or `extracted_html`) when you need
2586
+ just the new reply content, without quoted history.
2587
+ </Tip>
2292
2588
  </Step>
2293
2589
 
2294
2590
  <Step title="3. Send the Reply and Update Labels">
@@ -3218,6 +3514,23 @@ This event-driven approach is more efficient and allows you to build fast, respo
3218
3514
  * **Real-Time Speed:** Build conversational agents that can reply to incoming emails in seconds.
3219
3515
  * **Efficiency:** Eliminates the need for constant polling, which saves you computational resources and simplifies your application logic.
3220
3516
 
3517
+ ## Available Events
3518
+
3519
+ AgentMail supports seven webhook event types. When creating a webhook, you can subscribe to specific events or receive all of them. See [Webhook Events](/events) for full payload details.
3520
+
3521
+ **Message events:**
3522
+
3523
+ * **`message.received`** — New email received and processed in one of your inboxes
3524
+ * **`message.sent`** — Message successfully sent from your inbox
3525
+ * **`message.delivered`** — Delivery confirmed by the recipient's mail server
3526
+ * **`message.bounced`** — Message failed to deliver and bounced back
3527
+ * **`message.complained`** — Recipient marked your message as spam
3528
+ * **`message.rejected`** — Message rejected before send (validation or policy)
3529
+
3530
+ **Domain events:**
3531
+
3532
+ * **`domain.verified`** — Custom domain successfully verified
3533
+
3221
3534
  ## The Webhook Workflow
3222
3535
 
3223
3536
  The process is straightforward:
@@ -3233,26 +3546,30 @@ The process is straightforward:
3233
3546
  <CodeBlocks>
3234
3547
  ```python
3235
3548
  client.webhooks.create(
3236
- url="https://<your-ngrok-url>.ngrok-free.app/webhooks"
3549
+ url="https://<your-ngrok-url>.ngrok-free.app/webhooks",
3550
+ events=["message.received", "message.sent"],
3237
3551
  )
3238
3552
  ```
3239
3553
 
3240
3554
  ```typescript
3241
3555
  await client.webhooks.create({
3242
3556
  url: "https://<your-ngrok-url>.ngrok-free.app/webhooks",
3557
+ events: ["message.received", "message.sent"],
3243
3558
  });
3244
3559
  ```
3245
3560
  </CodeBlocks>
3561
+
3562
+ Specify which events to receive; omit `events` to subscribe to all event types.
3246
3563
  </Step>
3247
3564
 
3248
3565
  <Step title="3. AgentMail Sends Events">
3249
- When a new message is received in one of your inboxes, AgentMail will immediately send a `POST` request with a JSON payload to your registered URL.
3566
+ When an event occurs (e.g. a new message is received, a message is delivered, or a domain is verified), AgentMail sends a `POST` request with a JSON payload to your registered URL.
3250
3567
  </Step>
3251
3568
  </Steps>
3252
3569
 
3253
3570
  ## Payload Structure
3254
3571
 
3255
- When AgentMail sends a webhook, the payload will have the following structure.
3572
+ When AgentMail sends a webhook, the payload includes `event_type` and `event_id`, plus event-specific data. The example below shows a `message.received` payload; other events use different top-level objects (`send`, `delivery`, `bounce`, etc.). See [Webhook Events](/events) for each event's payload shape.
3256
3573
 
3257
3574
  ```json Webhook Payload
3258
3575
  {
@@ -3294,7 +3611,7 @@ When AgentMail sends a webhook, the payload will have the following structure.
3294
3611
 
3295
3612
  ### Field Descriptions
3296
3613
 
3297
- * **`event_type`** (`string`): The name of the event. Currently, this will always be `message.received`.
3614
+ * **`event_type`** (`string`): The event type (e.g. `message.received`, `message.sent`, `message.delivered`). Payload structure varies by event—see [Webhook Events](/events) for each event's shape.
3298
3615
  * **`event_id`** (`string`): A unique identifier for this specific event delivery.
3299
3616
  * **`message`** (`object`): A dictionary containing the full details of the received email message.
3300
3617
  * **`from_`** (`array<string>`): The sender's email address. Note the trailing underscore to avoid conflict with the Python keyword.
@@ -3349,6 +3666,84 @@ All webhook payloads follow the same basic structure:
3349
3666
  }
3350
3667
  ```
3351
3668
 
3669
+ ## Parsing events with SDKs
3670
+
3671
+ The AgentMail SDKs export typed classes for each webhook event, so you can parse raw payloads into fully typed objects.
3672
+
3673
+ <CodeBlocks>
3674
+ ```typescript title="TypeScript"
3675
+ import { serialization } from "agentmail";
3676
+
3677
+ async function handleWebhook(payload: Record<string, unknown>) {
3678
+ const eventType = payload.event_type;
3679
+
3680
+ if (eventType === "message.received") {
3681
+ const event = await serialization.events.MessageReceivedEvent.parse(payload);
3682
+ // access typed fields
3683
+ console.log(event.message.subject);
3684
+ console.log(event.thread.messageCount);
3685
+ } else if (eventType === "message.sent") {
3686
+ const event = await serialization.events.MessageSentEvent.parse(payload);
3687
+ console.log(event.send.recipients);
3688
+ } else if (eventType === "message.bounced") {
3689
+ const event = await serialization.events.MessageBouncedEvent.parse(payload);
3690
+ console.log(event.bounce.type);
3691
+ } else if (eventType === "message.delivered") {
3692
+ const event = await serialization.events.MessageDeliveredEvent.parse(payload);
3693
+ console.log(event.delivery.recipients);
3694
+ } else if (eventType === "message.complained") {
3695
+ const event = await serialization.events.MessageComplainedEvent.parse(payload);
3696
+ console.log(event.complaint.type);
3697
+ } else if (eventType === "message.rejected") {
3698
+ const event = await serialization.events.MessageRejectedEvent.parse(payload);
3699
+ console.log(event.reject.reason);
3700
+ } else if (eventType === "domain.verified") {
3701
+ const event = await serialization.events.DomainVerifiedEvent.parse(payload);
3702
+ console.log(event.domain.status);
3703
+ }
3704
+ }
3705
+ ```
3706
+
3707
+ ```python title="Python"
3708
+ from agentmail import (
3709
+ MessageReceivedEvent,
3710
+ MessageSentEvent,
3711
+ MessageBouncedEvent,
3712
+ MessageDeliveredEvent,
3713
+ MessageComplainedEvent,
3714
+ MessageRejectedEvent,
3715
+ DomainVerifiedEvent,
3716
+ )
3717
+
3718
+ def handle_webhook(payload: dict):
3719
+ event_type = payload.get("event_type")
3720
+
3721
+ if event_type == "message.received":
3722
+ event = MessageReceivedEvent(**payload)
3723
+ # access typed fields
3724
+ print(event.message.subject)
3725
+ print(event.thread.message_count)
3726
+ elif event_type == "message.sent":
3727
+ event = MessageSentEvent(**payload)
3728
+ print(event.send.recipients)
3729
+ elif event_type == "message.bounced":
3730
+ event = MessageBouncedEvent(**payload)
3731
+ print(event.bounce.type)
3732
+ elif event_type == "message.delivered":
3733
+ event = MessageDeliveredEvent(**payload)
3734
+ print(event.delivery.recipients)
3735
+ elif event_type == "message.complained":
3736
+ event = MessageComplainedEvent(**payload)
3737
+ print(event.complaint.type)
3738
+ elif event_type == "message.rejected":
3739
+ event = MessageRejectedEvent(**payload)
3740
+ print(event.reject.reason)
3741
+ elif event_type == "domain.verified":
3742
+ event = DomainVerifiedEvent(**payload)
3743
+ print(event.domain.status)
3744
+ ```
3745
+ </CodeBlocks>
3746
+
3352
3747
  ## Message Events
3353
3748
 
3354
3749
  ### `message.received`
@@ -3375,26 +3770,30 @@ All webhook payloads follow the same basic structure:
3375
3770
  "message_id": "msg_123abc",
3376
3771
  "labels": ["received"],
3377
3772
  "timestamp": "2023-10-27T10:00:00Z",
3378
- "from": [
3379
- {
3380
- "name": "Jane Doe",
3381
- "email": "jane@example.com"
3382
- }
3383
- ],
3384
- "to": [
3385
- {
3386
- "name": "Support Agent",
3387
- "email": "support@agentmail.to"
3388
- }
3389
- ],
3773
+ "from": "Jane Doe <jane@example.com>",
3774
+ "to": ["Support Agent <support@agentmail.to>"],
3390
3775
  "subject": "Question about my account",
3391
3776
  "preview": "A short preview of the email text...",
3392
3777
  "text": "The full text body of the email.",
3393
3778
  "html": "<html>...</html>",
3779
+ "size": 2048,
3780
+ "updated_at": "2023-10-27T10:00:00Z",
3394
3781
  "created_at": "2023-10-27T10:00:00Z"
3395
3782
  },
3396
3783
  "thread": {
3397
- // ... thread properties
3784
+ "inbox_id": "inbox_456def",
3785
+ "thread_id": "thd_789ghi",
3786
+ "labels": ["received"],
3787
+ "timestamp": "2023-10-27T10:00:00Z",
3788
+ "senders": ["Jane Doe <jane@example.com>"],
3789
+ "recipients": ["Support Agent <support@agentmail.to>"],
3790
+ "subject": "Question about my account",
3791
+ "preview": "A short preview of the email text...",
3792
+ "last_message_id": "msg_123abc",
3793
+ "message_count": 1,
3794
+ "size": 2048,
3795
+ "updated_at": "2023-10-27T10:00:00Z",
3796
+ "created_at": "2023-10-27T10:00:00Z"
3398
3797
  }
3399
3798
  }
3400
3799
  ```
@@ -3699,6 +4098,7 @@ webhook_url = "https://your-subdomain.ngrok-free.app/webhooks"
3699
4098
 
3700
4099
  webhook = client.webhooks.create(
3701
4100
  url=webhook_url,
4101
+ events=["message.received"], # add others (e.g. message.sent) as needed
3702
4102
  client_id="webhook-demo-webhook" # Ensures idempotency
3703
4103
  )
3704
4104
 
@@ -3941,7 +4341,13 @@ The easiest way to verify webhooks is using the official Svix library, which han
3941
4341
  except WebhookVerificationError as e:
3942
4342
  return ('', 400)
3943
4343
 
3944
- # Do something with the message...
4344
+ # handle by event type (msg is the verified payload)
4345
+ if msg.get("event_type") == "message.received":
4346
+ # process incoming email...
4347
+ pass
4348
+ elif msg.get("event_type") == "domain.verified":
4349
+ # enable domain features...
4350
+ pass
3945
4351
 
3946
4352
  return ('', 204)
3947
4353
 
@@ -3975,8 +4381,12 @@ The easiest way to verify webhooks is using the official Svix library, which han
3975
4381
  const wh = new Webhook(secret);
3976
4382
  const msg = wh.verify(payload, headers);
3977
4383
 
3978
- // Do something with the message...
3979
- console.log("Webhook verified:", msg);
4384
+ // handle by event type (msg is the verified payload)
4385
+ if (msg.event_type === "message.received") {
4386
+ // process incoming email...
4387
+ } else if (msg.event_type === "domain.verified") {
4388
+ // enable domain features...
4389
+ }
3980
4390
 
3981
4391
  res.status(204).send();
3982
4392
  } catch (err) {
@@ -4031,7 +4441,13 @@ Create a webhook server file:
4031
4441
  print(f"Verification failed: {e}")
4032
4442
  return ('', 400)
4033
4443
 
4034
- # Do something with the message...
4444
+ # handle by event type (msg is the verified payload)
4445
+ if msg.get("event_type") == "message.received":
4446
+ # process incoming email...
4447
+ pass
4448
+ elif msg.get("event_type") == "domain.verified":
4449
+ # enable domain features...
4450
+ pass
4035
4451
 
4036
4452
  return ('', 204)
4037
4453
 
@@ -4064,8 +4480,12 @@ Create a webhook server file:
4064
4480
  const wh = new Webhook(secret);
4065
4481
  const msg = wh.verify(payload, headers);
4066
4482
 
4067
- // Do something with the message...
4068
- console.log("Webhook verified:", msg);
4483
+ // handle by event type (msg is the verified payload)
4484
+ if (msg.event_type === "message.received") {
4485
+ // process incoming email...
4486
+ } else if (msg.event_type === "domain.verified") {
4487
+ // enable domain features...
4488
+ }
4069
4489
 
4070
4490
  res.status(204).send();
4071
4491
  } catch (err) {
@@ -7634,6 +8054,11 @@ practices and security.
7634
8054
  [Webhooks Overview](/overview).
7635
8055
  </Accordion>
7636
8056
 
8057
+ <Accordion title="How do I get just the new content from a reply?">
8058
+ Use `extracted_text` or `extracted_html` on the Message object. AgentMail
8059
+ strips quoted text automatically, so you get only the new reply content.
8060
+ </Accordion>
8061
+
7637
8062
  <Accordion title="How do I make sure I don't end up in spam?">
7638
8063
  Email deliverability is a complex topic. We go in depth in our [Email
7639
8064
  Deliverability best practices guide](/email-deliverability).
@@ -17654,8 +18079,8 @@ client = AgentMail(
17654
18079
 
17655
18080
  client.inboxes.metrics.get(
17656
18081
  inbox_id="inbox_id",
17657
- start_timestamp=datetime.fromisoformat("2024-01-15T09:30:00Z"),
17658
- end_timestamp=datetime.fromisoformat("2024-01-15T09:30:00Z")
18082
+ start_timestamp=datetime.fromisoformat("2024-01-15T09:30:00+00:00"),
18083
+ end_timestamp=datetime.fromisoformat("2024-01-15T09:30:00+00:00")
17659
18084
  )
17660
18085
 
17661
18086
  ```
@@ -21862,37 +22287,34 @@ components:
21862
22287
 
21863
22288
  ## SDK Code Examples
21864
22289
 
21865
- ```python
21866
- import requests
21867
-
21868
- url = "https://api.agentmail.to/v0/lists/send/allow"
22290
+ ```typescript
22291
+ import { AgentMailClient } from "agentmail";
21869
22292
 
21870
- payload = { "entry": "entry" }
21871
- headers = {
21872
- "Authorization": "Bearer <api_key>",
21873
- "Content-Type": "application/json"
22293
+ async function main() {
22294
+ const client = new AgentMailClient({
22295
+ apiKey: "YOUR_TOKEN_HERE",
22296
+ });
22297
+ await client.lists.create("send", "allow", {
22298
+ entry: "entry",
22299
+ });
21874
22300
  }
22301
+ main();
21875
22302
 
21876
- response = requests.post(url, json=payload, headers=headers)
21877
-
21878
- print(response.json())
21879
22303
  ```
21880
22304
 
21881
- ```javascript
21882
- const url = 'https://api.agentmail.to/v0/lists/send/allow';
21883
- const options = {
21884
- method: 'POST',
21885
- headers: {Authorization: 'Bearer <api_key>', 'Content-Type': 'application/json'},
21886
- body: '{"entry":"entry"}'
21887
- };
22305
+ ```python
22306
+ from agentmail import AgentMail
22307
+
22308
+ client = AgentMail(
22309
+ api_key="YOUR_TOKEN_HERE"
22310
+ )
22311
+
22312
+ client.lists.create(
22313
+ direction="send",
22314
+ type="allow",
22315
+ entry="entry"
22316
+ )
21888
22317
 
21889
- try {
21890
- const response = await fetch(url, options);
21891
- const data = await response.json();
21892
- console.log(data);
21893
- } catch (error) {
21894
- console.error(error);
21895
- }
21896
22318
  ```
21897
22319
 
21898
22320
  ```go
@@ -22171,29 +22593,31 @@ components:
22171
22593
 
22172
22594
  ## SDK Code Examples
22173
22595
 
22174
- ```python
22175
- import requests
22596
+ ```typescript
22597
+ import { AgentMailClient } from "agentmail";
22176
22598
 
22177
- url = "https://api.agentmail.to/v0/lists/send/allow"
22599
+ async function main() {
22600
+ const client = new AgentMailClient({
22601
+ apiKey: "YOUR_TOKEN_HERE",
22602
+ });
22603
+ await client.lists.list("send", "allow", {});
22604
+ }
22605
+ main();
22178
22606
 
22179
- headers = {"Authorization": "Bearer <api_key>"}
22607
+ ```
22180
22608
 
22181
- response = requests.get(url, headers=headers)
22609
+ ```python
22610
+ from agentmail import AgentMail
22182
22611
 
22183
- print(response.json())
22184
- ```
22612
+ client = AgentMail(
22613
+ api_key="YOUR_TOKEN_HERE"
22614
+ )
22185
22615
 
22186
- ```javascript
22187
- const url = 'https://api.agentmail.to/v0/lists/send/allow';
22188
- const options = {method: 'GET', headers: {Authorization: 'Bearer <api_key>'}};
22616
+ client.lists.list(
22617
+ direction="send",
22618
+ type="allow"
22619
+ )
22189
22620
 
22190
- try {
22191
- const response = await fetch(url, options);
22192
- const data = await response.json();
22193
- console.log(data);
22194
- } catch (error) {
22195
- console.error(error);
22196
- }
22197
22621
  ```
22198
22622
 
22199
22623
  ```go
@@ -22442,29 +22866,32 @@ components:
22442
22866
 
22443
22867
  ## SDK Code Examples
22444
22868
 
22445
- ```python
22446
- import requests
22869
+ ```typescript
22870
+ import { AgentMailClient } from "agentmail";
22447
22871
 
22448
- url = "https://api.agentmail.to/v0/lists/send/allow/entry"
22872
+ async function main() {
22873
+ const client = new AgentMailClient({
22874
+ apiKey: "YOUR_TOKEN_HERE",
22875
+ });
22876
+ await client.lists.get("send", "allow", "entry");
22877
+ }
22878
+ main();
22449
22879
 
22450
- headers = {"Authorization": "Bearer <api_key>"}
22880
+ ```
22451
22881
 
22452
- response = requests.get(url, headers=headers)
22882
+ ```python
22883
+ from agentmail import AgentMail
22453
22884
 
22454
- print(response.json())
22455
- ```
22885
+ client = AgentMail(
22886
+ api_key="YOUR_TOKEN_HERE"
22887
+ )
22456
22888
 
22457
- ```javascript
22458
- const url = 'https://api.agentmail.to/v0/lists/send/allow/entry';
22459
- const options = {method: 'GET', headers: {Authorization: 'Bearer <api_key>'}};
22889
+ client.lists.get(
22890
+ direction="send",
22891
+ type="allow",
22892
+ entry="entry"
22893
+ )
22460
22894
 
22461
- try {
22462
- const response = await fetch(url, options);
22463
- const data = await response.json();
22464
- console.log(data);
22465
- } catch (error) {
22466
- console.error(error);
22467
- }
22468
22895
  ```
22469
22896
 
22470
22897
  ```go
@@ -22669,29 +23096,32 @@ components:
22669
23096
 
22670
23097
  ## SDK Code Examples
22671
23098
 
22672
- ```python
22673
- import requests
23099
+ ```typescript
23100
+ import { AgentMailClient } from "agentmail";
22674
23101
 
22675
- url = "https://api.agentmail.to/v0/lists/send/allow/entry"
23102
+ async function main() {
23103
+ const client = new AgentMailClient({
23104
+ apiKey: "YOUR_TOKEN_HERE",
23105
+ });
23106
+ await client.lists.delete("send", "allow", "entry");
23107
+ }
23108
+ main();
22676
23109
 
22677
- headers = {"Authorization": "Bearer <api_key>"}
23110
+ ```
22678
23111
 
22679
- response = requests.delete(url, headers=headers)
23112
+ ```python
23113
+ from agentmail import AgentMail
22680
23114
 
22681
- print(response.json())
22682
- ```
23115
+ client = AgentMail(
23116
+ api_key="YOUR_TOKEN_HERE"
23117
+ )
22683
23118
 
22684
- ```javascript
22685
- const url = 'https://api.agentmail.to/v0/lists/send/allow/entry';
22686
- const options = {method: 'DELETE', headers: {Authorization: 'Bearer <api_key>'}};
23119
+ client.lists.delete(
23120
+ direction="send",
23121
+ type="allow",
23122
+ entry="entry"
23123
+ )
22687
23124
 
22688
- try {
22689
- const response = await fetch(url, options);
22690
- const data = await response.json();
22691
- console.log(data);
22692
- } catch (error) {
22693
- console.error(error);
22694
- }
22695
23125
  ```
22696
23126
 
22697
23127
  ```go
@@ -26658,8 +27088,8 @@ client = AgentMail(
26658
27088
  )
26659
27089
 
26660
27090
  client.metrics.list(
26661
- start_timestamp=datetime.fromisoformat("2024-01-15T09:30:00Z"),
26662
- end_timestamp=datetime.fromisoformat("2024-01-15T09:30:00Z")
27091
+ start_timestamp=datetime.fromisoformat("2024-01-15T09:30:00+00:00"),
27092
+ end_timestamp=datetime.fromisoformat("2024-01-15T09:30:00+00:00")
26663
27093
  )
26664
27094
 
26665
27095
  ```
@@ -33005,37 +33435,35 @@ components:
33005
33435
 
33006
33436
  ## SDK Code Examples
33007
33437
 
33008
- ```python
33009
- import requests
33010
-
33011
- url = "https://api.agentmail.to/v0/pods/pod_id/lists/send/allow"
33438
+ ```typescript
33439
+ import { AgentMailClient } from "agentmail";
33012
33440
 
33013
- payload = { "entry": "entry" }
33014
- headers = {
33015
- "Authorization": "Bearer <api_key>",
33016
- "Content-Type": "application/json"
33441
+ async function main() {
33442
+ const client = new AgentMailClient({
33443
+ apiKey: "YOUR_TOKEN_HERE",
33444
+ });
33445
+ await client.pods.lists.create("pod_id", "send", "allow", {
33446
+ entry: "entry",
33447
+ });
33017
33448
  }
33449
+ main();
33018
33450
 
33019
- response = requests.post(url, json=payload, headers=headers)
33020
-
33021
- print(response.json())
33022
33451
  ```
33023
33452
 
33024
- ```javascript
33025
- const url = 'https://api.agentmail.to/v0/pods/pod_id/lists/send/allow';
33026
- const options = {
33027
- method: 'POST',
33028
- headers: {Authorization: 'Bearer <api_key>', 'Content-Type': 'application/json'},
33029
- body: '{"entry":"entry"}'
33030
- };
33453
+ ```python
33454
+ from agentmail import AgentMail
33455
+
33456
+ client = AgentMail(
33457
+ api_key="YOUR_TOKEN_HERE"
33458
+ )
33459
+
33460
+ client.pods.lists.create(
33461
+ pod_id="pod_id",
33462
+ direction="send",
33463
+ type="allow",
33464
+ entry="entry"
33465
+ )
33031
33466
 
33032
- try {
33033
- const response = await fetch(url, options);
33034
- const data = await response.json();
33035
- console.log(data);
33036
- } catch (error) {
33037
- console.error(error);
33038
- }
33039
33467
  ```
33040
33468
 
33041
33469
  ```go
@@ -33330,29 +33758,32 @@ components:
33330
33758
 
33331
33759
  ## SDK Code Examples
33332
33760
 
33333
- ```python
33334
- import requests
33761
+ ```typescript
33762
+ import { AgentMailClient } from "agentmail";
33335
33763
 
33336
- url = "https://api.agentmail.to/v0/pods/pod_id/lists/send/allow"
33764
+ async function main() {
33765
+ const client = new AgentMailClient({
33766
+ apiKey: "YOUR_TOKEN_HERE",
33767
+ });
33768
+ await client.pods.lists.list("pod_id", "send", "allow", {});
33769
+ }
33770
+ main();
33337
33771
 
33338
- headers = {"Authorization": "Bearer <api_key>"}
33772
+ ```
33339
33773
 
33340
- response = requests.get(url, headers=headers)
33774
+ ```python
33775
+ from agentmail import AgentMail
33341
33776
 
33342
- print(response.json())
33343
- ```
33777
+ client = AgentMail(
33778
+ api_key="YOUR_TOKEN_HERE"
33779
+ )
33344
33780
 
33345
- ```javascript
33346
- const url = 'https://api.agentmail.to/v0/pods/pod_id/lists/send/allow';
33347
- const options = {method: 'GET', headers: {Authorization: 'Bearer <api_key>'}};
33781
+ client.pods.lists.list(
33782
+ pod_id="pod_id",
33783
+ direction="send",
33784
+ type="allow"
33785
+ )
33348
33786
 
33349
- try {
33350
- const response = await fetch(url, options);
33351
- const data = await response.json();
33352
- console.log(data);
33353
- } catch (error) {
33354
- console.error(error);
33355
- }
33356
33787
  ```
33357
33788
 
33358
33789
  ```go
@@ -33617,29 +34048,33 @@ components:
33617
34048
 
33618
34049
  ## SDK Code Examples
33619
34050
 
33620
- ```python
33621
- import requests
34051
+ ```typescript
34052
+ import { AgentMailClient } from "agentmail";
33622
34053
 
33623
- url = "https://api.agentmail.to/v0/pods/pod_id/lists/send/allow/entry"
34054
+ async function main() {
34055
+ const client = new AgentMailClient({
34056
+ apiKey: "YOUR_TOKEN_HERE",
34057
+ });
34058
+ await client.pods.lists.get("pod_id", "send", "allow", "entry");
34059
+ }
34060
+ main();
33624
34061
 
33625
- headers = {"Authorization": "Bearer <api_key>"}
34062
+ ```
33626
34063
 
33627
- response = requests.get(url, headers=headers)
34064
+ ```python
34065
+ from agentmail import AgentMail
33628
34066
 
33629
- print(response.json())
33630
- ```
34067
+ client = AgentMail(
34068
+ api_key="YOUR_TOKEN_HERE"
34069
+ )
33631
34070
 
33632
- ```javascript
33633
- const url = 'https://api.agentmail.to/v0/pods/pod_id/lists/send/allow/entry';
33634
- const options = {method: 'GET', headers: {Authorization: 'Bearer <api_key>'}};
34071
+ client.pods.lists.get(
34072
+ pod_id="pod_id",
34073
+ direction="send",
34074
+ type="allow",
34075
+ entry="entry"
34076
+ )
33635
34077
 
33636
- try {
33637
- const response = await fetch(url, options);
33638
- const data = await response.json();
33639
- console.log(data);
33640
- } catch (error) {
33641
- console.error(error);
33642
- }
33643
34078
  ```
33644
34079
 
33645
34080
  ```go
@@ -33853,29 +34288,33 @@ components:
33853
34288
 
33854
34289
  ## SDK Code Examples
33855
34290
 
33856
- ```python
33857
- import requests
34291
+ ```typescript
34292
+ import { AgentMailClient } from "agentmail";
33858
34293
 
33859
- url = "https://api.agentmail.to/v0/pods/pod_id/lists/send/allow/entry"
34294
+ async function main() {
34295
+ const client = new AgentMailClient({
34296
+ apiKey: "YOUR_TOKEN_HERE",
34297
+ });
34298
+ await client.pods.lists.delete("pod_id", "send", "allow", "entry");
34299
+ }
34300
+ main();
33860
34301
 
33861
- headers = {"Authorization": "Bearer <api_key>"}
34302
+ ```
33862
34303
 
33863
- response = requests.delete(url, headers=headers)
34304
+ ```python
34305
+ from agentmail import AgentMail
33864
34306
 
33865
- print(response.json())
33866
- ```
34307
+ client = AgentMail(
34308
+ api_key="YOUR_TOKEN_HERE"
34309
+ )
33867
34310
 
33868
- ```javascript
33869
- const url = 'https://api.agentmail.to/v0/pods/pod_id/lists/send/allow/entry';
33870
- const options = {method: 'DELETE', headers: {Authorization: 'Bearer <api_key>'}};
34311
+ client.pods.lists.delete(
34312
+ pod_id="pod_id",
34313
+ direction="send",
34314
+ type="allow",
34315
+ entry="entry"
34316
+ )
33871
34317
 
33872
- try {
33873
- const response = await fetch(url, options);
33874
- const data = await response.json();
33875
- console.log(data);
33876
- } catch (error) {
33877
- console.error(error);
33878
- }
33879
34318
  ```
33880
34319
 
33881
34320
  ```go