# Send & Receive Emails with Sim (/integrations/frameworks/sim)

<!-- agent-signals: reading_time_min: 4 · est_tokens: 1617 · updated: 2026-09-06 -->
Related: [Send & Receive Emails with Claude Cowork](/integrations/frameworks/claude-cowork.md), [Send & Receive Emails with Claude Code](/integrations/frameworks/claude-code.md), [Send & Receive Emails with OpenAI Codex](/integrations/frameworks/codex.md), [Send & Receive Emails with OpenClaw](/integrations/frameworks/openclaw.md), [Send & Receive Emails with Grok](/integrations/frameworks/grok.md), [Send & Receive Emails with Manus](/integrations/frameworks/manus.md)



# Build a Sim workflow on the AgentMail block

Sim has AgentMail built in as a canvas block: give it an API key and pick an operation. Use this to send, read, and answer email from a workflow's own inbox, including runs triggered the moment an email arrives.

## Do this

1. In Sim, open Settings, then Secrets, and add `AGENTMAIL_API_KEY` (your key from the AgentMail Console) and `AGENTMAIL_INBOX_ID` (the `inboxId` the workflow acts on). Any block field references a secret with double curly braces, like `{{AGENTMAIL_API_KEY}}`.
2. Drag an AgentMail block onto the canvas, rename it before referencing it anywhere, set its API Key field to `{{AGENTMAIL_API_KEY}}`, and pick an Operation. The remaining fields change to match the operation.
3. If you need an inbox, add a block named `CreateInbox` with Operation `Create Inbox`, leave Username empty so AgentMail generates one, click Run, then store the output's `inboxId` in the `AGENTMAIL_INBOX_ID` secret.
4. To send, add a block named `SendEmail` with Operation `Send Message`, Inbox ID `{{AGENTMAIL_INBOX_ID}}`, To, Subject, and Text filled, and click Run. Later blocks read `<SendEmail.messageId>` and `<SendEmail.threadId>` to follow up in the same thread.
5. To read, add a block named `FetchEmails` with Operation `List Messages`, the same Inbox ID, and Limit `10`. For full bodies, add a Loop block set to ForEach with Collection `<FetchEmails.messages>`, and inside it an AgentMail block with Operation `Get Message` and Message ID `<loop.currentItem.messageId>`.

To run the workflow when email arrives, add a Webhook trigger as the entry point, turn on Require Authentication and set a token, deploy the workflow, copy the webhook URL Sim generates, then register it with AgentMail:

```bash
curl -X POST "https://api.agentmail.to/v0/webhooks" \
  -H "Authorization: Bearer $AGENTMAIL_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "<your Sim webhook URL>",
    "event_types": ["message.received"],
    "inbox_ids": ["faircost773@agentmail.to"],
    "headers": { "Authorization": "Bearer <your Sim trigger token>" }
  }'
```

## Facts

* Secrets are referenced with double curly braces, like `{{AGENTMAIL_API_KEY}}`. Sim resolves the value at run time and masks it in the run logs.
* Downstream blocks read an earlier block's output through a connection tag that starts with the block's name, like `<SendEmail.threadId>`. Type `<` in any field to pick from earlier outputs.
* Every operation authenticates with the block's API Key field.
* Message operations: `Send Message`, `Reply to Message` (set `replyAll` to include everyone on the original), `Forward Message`, `List Messages`, `Get Message`, `Update Message` (add or remove labels).
* Thread operations: `List Threads` (filter by labels or a time window), `Get Thread`, `Update Thread Labels`, `Delete Thread` (trash, or permanently with `permanent`).
* Inbox operations: `Create Inbox`, `List Inboxes`, `Get Inbox`, `Update Inbox` (display name), `Delete Inbox`.
* Draft operations: `Create Draft` (set `sendAt` to schedule the send), `List Drafts`, `Get Draft` (check `sendStatus`), `Update Draft`, `Send Draft`, `Delete Draft`.
* To, CC, and BCC each take a comma-separated string when there is more than one recipient.
* `List Messages` returns messages newest first. Each item carries a body `preview` and the `messageId`. `Get Message` returns the full `text` and `html`.
* `Create Inbox` output shows the new inbox's `inboxId` and its `email` address. An empty Username lets AgentMail generate one, and Display Name is optional.
* A sent email typically arrives in about two seconds.
* Webhook registration endpoint: `POST https://api.agentmail.to/v0/webhooks` with `Authorization: Bearer` auth. AgentMail sends the registration's `headers` map with every delivery. Omit `inbox_ids` and the workflow runs for received mail across all inboxes. One webhook watches at most 10 inboxes.
* The registration response includes `webhook_id` (needed to update or delete the subscription), `secret`, and `enabled`.
* The webhook delivery carries the received message and its thread. Blocks after the trigger read fields by name: `<webhook.message.subject>`, `<webhook.message.text>`, `<webhook.message.inbox_id>`, `<webhook.message.message_id>`.
* A `Reply to Message` block with Inbox ID `<webhook.message.inbox_id>` and Message ID `<webhook.message.message_id>` answers in the original thread.
* Full parameter tables for every operation: Sim's AgentMail block reference at `https://docs.sim.ai/integrations/agentmail`.

## Not supported

* A Schedule trigger does not run until the workflow is deployed.
* The Sim webhook URL does not accept requests until the workflow is deployed.
* An empty `List Messages` result does not fail the workflow. The ForEach loop body is skipped and the run continues.
* If Require Authentication is off on the Sim trigger, drop the `headers` map from the registration call.

## Errors

| Error                                    | HTTP status | Cause                                                                | Fix                                                                                          |
| ---------------------------------------- | ----------- | -------------------------------------------------------------------- | -------------------------------------------------------------------------------------------- |
| 403 on `Create Inbox` with `suggestions` | 403         | Chosen username is taken                                             | Open the failed block in the run's logs, pick one of the up to three alternatives, run again |
| `limit_exceeded`                         | 403         | Organization at its plan's inbox limit, whatever username you picked | Free an inbox or raise the plan's limit                                                      |

## Verify

Run the `SendEmail` block and check the recipient account: the email arrives moments later from the agent's address. A successful webhook registration returns a JSON body with a `webhook_id` and `"enabled": true`. For the trigger, send an email to the watched inbox and confirm a run appears in Sim's Logs.

## Related

* `/advanced/webhooks` for event types, payload shapes, signature verification, and delivery retries
* `/advanced/multi-tenant` to give every customer, agent, or workflow its own isolated inbox
* `/quickstart` for generating an API key in a first AgentMail project
