> ## Documentation Index
> Fetch the complete documentation index at: https://docs.ancha.io/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> These docs describe the Ancha CLI, npm package @ancha-labs/cli, and the hosted workspace at app.ancha.io. Coding agents should start at https://docs.ancha.io/coding-agents. Run the CLI as `ancha` after `npm install -g @ancha-labs/cli`, or as `npx -y @ancha-labs/cli` without installing. Pass --json for machine-readable output, or set ANCHA_JSON=1. Every command ends with a `next:` line naming the next command. Exit codes: 0 pass, 1 a check failed or a comparison regressed, 2 usage, config or authentication error, 3 infrastructure error, 4 unimplemented endpoint with --strict.

# Connect your agent to the Outlook mock

> Read mail, draft replies, send messages and manage attachments through Microsoft Graph. Seed renewal conversations and check mailbox state.

Use Microsoft Graph v1.0 to read mail, draft or send replies, organize folders and download attachments. Your agent can review a renewal conversation and its schedule PDF, then send a reply you check in the mailbox.

The [Outlook API mock page](https://ancha.io/tools/outlook) has a scene and checks you can copy.

Select this tool with `twins: [outlook]` in a scene or `--tools outlook` when creating a world. Inspect its API coverage and connection code:

```bash theme={null}
ancha twins coverage outlook
ancha connect outlook --lang ts
```

## Connect

| Variable | Value |
| - | - |
| `MICROSOFT_GRAPH_API_URL` | Base URL, standing in for `https://graph.microsoft.com`. Paths start with `/v1.0/`. |
| `MICROSOFT_GRAPH_ACCESS_TOKEN` | Fake delegated access token for the signed-in user. Send `Authorization: Bearer <token>`. |
| `MICROSOFT_GRAPH_TOKEN_URL` | Token endpoint for application authentication. |
| `MICROSOFT_GRAPH_CLIENT_ID` | Fake application client ID. |
| `MICROSOFT_GRAPH_CLIENT_SECRET` | Fake application client secret. |

```ts TypeScript theme={null}
import { Client } from '@microsoft/microsoft-graph-client';
const token = process.env.MICROSOFT_GRAPH_ACCESS_TOKEN!;
const graph = Client.init({ baseUrl: process.env.MICROSOFT_GRAPH_API_URL + '/', defaultVersion: 'v1.0', authProvider: (done) => done(null, token), fetchOptions: { headers: { authorization: 'Bearer ' + token } } });
const files = await graph.api('/me/mailFolders/inbox/messages').select('id,subject,from,bodyPreview').top(10).get();
// Next page: graph.api(files['@odata.nextLink'].slice(files['@odata.nextLink'].indexOf('/v1.0') + 5)).get()
```

Set the lower-case `authorization` header in `fetchOptions`. The Graph client otherwise omits it for the world's URL. To follow an `@odata.nextLink`, pass the part after `/v1.0` to `api()`.

In a world with Outlook and [Microsoft Word](https://docs.ancha.io/tools/microsoft-word.md), both tools share the same Graph base URL and token.

For application authentication, exchange the client ID and secret at `MICROSOFT_GRAPH_TOKEN_URL` with `grant_type=client_credentials` and `scope=https://graph.microsoft.com/.default`. Use the returned token on `/v1.0/users/{id or userPrincipalName}/…`. Microsoft Graph requires delegated authentication for `/me`.

## Endpoints

The mail paths below also work under `/v1.0/users/{id or userPrincipalName}` in place of `/v1.0/me`.

| Method | Path | Notes |
| - | - | - |
| `GET` | `/v1.0/me` | The signed-in user. |
| `GET`, `POST` | `/v1.0/me/messages` | List messages or create a draft. |
| `GET`, `PATCH`, `DELETE` | `/v1.0/me/messages/{id}` | Read, update or delete a message. |
| `POST` | `/v1.0/me/messages/{id}/move` | Move to `destinationId`. |
| `POST` | `/v1.0/me/messages/{id}/copy` | Copy to `destinationId`. |
| `POST` | `/v1.0/me/messages/{id}/send` | Send a draft. |
| `POST` | `/v1.0/me/messages/{id}/reply` | Send a reply. |
| `POST` | `/v1.0/me/messages/{id}/replyAll` | Reply to all recipients. |
| `POST` | `/v1.0/me/messages/{id}/forward` | Forward a message. |
| `POST` | `/v1.0/me/messages/{id}/createReply` | Create a reply draft. |
| `POST` | `/v1.0/me/messages/{id}/createReplyAll` | Create a reply-all draft. |
| `POST` | `/v1.0/me/messages/{id}/createForward` | Create a forward draft. |
| `POST` | `/v1.0/me/sendMail` | Send a message; `saveToSentItems` controls the sent copy. |
| `GET`, `POST` | `/v1.0/me/mailFolders` | List or create top-level folders. |
| `GET`, `PATCH`, `DELETE` | `/v1.0/me/mailFolders/{id}` | Well-known folder names or folder IDs. |
| `GET`, `POST` | `/v1.0/me/mailFolders/{id}/childFolders` | List or create child folders. |
| `GET` | `/v1.0/me/mailFolders/{id}/messages` | List a folder's messages. |
| `GET` | `/v1.0/me/mailFolders/{id}/messages/delta` | Initial snapshot and incremental changes, with paging and `@odata.deltaLink`. |
| `GET`, `POST` | `/v1.0/me/messages/{id}/attachments` | List or add file and message attachments. |
| `GET`, `DELETE` | `/v1.0/me/messages/{id}/attachments/{attachment-id}` | Read or remove an attachment. |
| `GET` | `/v1.0/me/messages/{id}/attachments/{attachment-id}/$value` | File bytes. |
| `POST` | `/v1.0/me/messages/{id}/attachments/createUploadSession` | Create a ranged upload session. |
| `PUT` | `/upload/{id}` | Upload sequential byte ranges to the session's URL. |
| `POST` | `/{tenant}/oauth2/v2.0/token` | Exchange client credentials for an application token. |

Message lists accept `$select`, `$filter`, `$orderby`, `$top`, `$skip`, `$search` and `$count`. Add `Prefer: outlook.body-content-type="text"` to receive text bodies.

## Starter data

Inspect the starter records and the fields you can use in a scene:

```bash theme={null}
ancha sandbox configuration --tools outlook --json
ancha twins seed outlook
```

The starter data has mailboxes for Ancha Assistant (`ancha@acme.example`), Anna Fischer and Tom Hughes. It includes the Kestrel renewal conversation, `renewal-schedule.pdf`, a renewal review draft and Pinecrest's invoice approval message. Anna and Tom grant Ancha Assistant delegated access to their mailboxes.

This scene seed adds the renewal request and its PDF:

```yaml theme={null}
twins:
  - outlook
seed:
  outlook:
    me: ancha@acme.example
    users:
      - email: ancha@acme.example
        displayName: Ancha Assistant
    folders:
      - ref: renewals
        mailbox: ancha@acme.example
        displayName: Renewals
        parent: inbox
    messages:
      - ref: renewal-request
        mailbox: ancha@acme.example
        received: -4h
        conversation: kestrel-renewal
        subject: Kestrel renewal documents
        body:
          contentType: html
          content: <p>Please review the attached renewal schedule before Friday.</p>
        from:
          emailAddress:
            address: laura@kestrel.example
            name: Laura
        toRecipients:
          - emailAddress:
              address: ancha@acme.example
        attachments:
          - "@odata.type": "#microsoft.graph.fileAttachment"
            name: renewal-schedule.pdf
            contentType: application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wMDAwMDA1NzYgMDAwMDAgbiAKdHJhaWxlcgo8PCAvU2l6ZSA3IC9Sb290IDEgMCBSIC9JbmZvIDYgMCBSID4+CnN0YXJ0eHJlZgo2NDkKJSVFT0YK
            isInline: false
```

A scene uses the data you put in its `seed` field.

## Checks

Use `outlook.message` to check a message in a mailbox and folder:

```yaml theme={null}
checks:
  - id: renewal_attached
    state:
      outlook.message:
        mailbox: ancha@acme.example
        folder: inbox
        subject_contains: renewal
        attachment_name_contains: .pdf
        exists: true
```

This check confirms the seeded renewal PDF is in the inbox. Set `folder: sentitems` to check a sent reply, or `folder: drafts` to check a draft. Add `from`, `to` or `text_contains` to match the sender, recipient or body. `mailbox` accepts an email address or user ID and defaults to the signed-in user. `folder` accepts a well-known name, seed folder ref or folder ID. Text and attachment names compare without regard to case. Set `exists: false` to check absence.

## Behavior

* Sending delivers messages to seeded mailboxes and saves a sent copy according to `saveToSentItems`.
* Replies retain the conversation and reply headers. Reply-all deduplicates recipients and excludes the current mailbox.
* Moving a message changes its default ID. Deleting moves it to Deleted Items; deleting it there removes it permanently.
* Delegated access to another mailbox follows its `users[].delegatedAccess` seed setting.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.