# Download Attachment — Microsoft Outlook Email

> Download an email attachment to /tmp. Use Find Email to locate the message, then Get Message with includeAttachments: true to get the messageId and attachment id fields. Example: after get-message(messageId="AAMk..."…

- Key: `microsoft_outlook-download-attachment`
- Type: Action (Read-only)
- Version: 0.1.5
- App: Microsoft Outlook Email (`microsoft_outlook`) — https://pipedream.com/apps/microsoft-outlook.md
- This page (HTML): https://pipedream.com/apps/microsoft-outlook/actions/download-attachment
- Hints: read-only · open-world
- Source: https://github.com/PipedreamHQ/pipedream/blob/master/components/microsoft_outlook/actions/download-attachment/download-attachment.mjs

## Description

Download an email attachment to `/tmp`. Use **Find Email** to locate the message, then **Get Message** with `includeAttachments: true` to get the `messageId` and attachment `id` fields. Example: after `get-message(messageId="AAMk...", includeAttachments=true)` returns `attachments: [{ id: "AQMk...", name: "report.pdf" }]`, call `download-attachment(messageId="AAMk...", attachmentId="AQMk...", filename="report.pdf")` → writes to `/tmp/report.pdf`. Set `convertToPdf: true` to convert images, HTML, plain text, or DOCX files to PDF. For text attachments (text/*, JSON), the response includes `fileContent` with the decoded text (truncated at 100 KB, flagged by `contentTruncated`), so the content can be read directly without fetching the file. [See the documentation](https://learn.microsoft.com/en-us/graph/api/attachment-get)

## Props

| Prop | Type | Required | Description |
|---|---|---|---|
| `messageId` | `string` | Yes | The Microsoft Graph message ID. Obtain from Find Email or Get Message. |
| `attachmentId` | `string` | Yes | The attachment ID. Obtain from Get Message with includeAttachments: true — each attachment object in the response has an id field. |
| `filename` | `string` | Yes | The filename to save the attachment as in /tmp, e.g. report.pdf. If convertToPdf is true, the .pdf extension is applied automatically. |
| `convertToPdf` | `boolean` | No | When true, converts the attachment to PDF before saving. Supports image, text/plain, HTML, and DOCX files. |
| `userId` | `string` | No | The user ID or UPN of a shared mailbox. Omit to use the authenticated user's mailbox. |
| `syncDir` | `dir` | Yes | SyncDir |

## Run it

**MCP**

```ts
import { Client } from "@modelcontextprotocol/sdk/client/index.js"
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js"
import { PipedreamClient } from "@pipedream/sdk"

const pd = new PipedreamClient({
  projectId: process.env.PIPEDREAM_PROJECT_ID!,
  clientId: process.env.PIPEDREAM_CLIENT_ID!,
  clientSecret: process.env.PIPEDREAM_CLIENT_SECRET!,
  projectEnvironment: "production",
})

const accessToken = await pd.rawAccessToken

const transport = new StreamableHTTPClientTransport(
  new URL("https://remote.mcp.pipedream.net/v3"),
  {
    requestInit: {
      headers: {
        Authorization: `Bearer ${accessToken}`,
        "x-pd-project-id": process.env.PIPEDREAM_PROJECT_ID!,
        "x-pd-environment": "production",
        "x-pd-external-user-id": "{external_user_id}", // any stable ID for this user in your system
        "x-pd-app-slug": "microsoft_outlook",
      },
    },
  },
)

const mcp = new Client({ name: "my-agent", version: "1.0.0" })
await mcp.connect(transport)

const { tools } = await mcp.listTools()

// listTools() hands your model this tool's input schema, so it can
// fill the arguments itself:
const result = await mcp.callTool({
  name: "microsoft_outlook-download-attachment",
  arguments: {
    messageId: "Message ID",
    attachmentId: "Attachment ID",
  },
})
```

**TypeScript**

```ts
import { PipedreamClient } from "@pipedream/sdk"

const pd = new PipedreamClient({
  projectId: process.env.PIPEDREAM_PROJECT_ID!,
  clientId: process.env.PIPEDREAM_CLIENT_ID!,
  clientSecret: process.env.PIPEDREAM_CLIENT_SECRET!,
  projectEnvironment: "production",
})

const result = await pd.actions.run({
  id: "microsoft_outlook-download-attachment",
  externalUserId: "{external_user_id}", // any stable ID for this user in your system
  configuredProps: {
    microsoft_outlook: { authProvisionId: "apn_xxxxxxx" },
    messageId: "Message ID",
    attachmentId: "Attachment ID",
  },
})

console.log(result)
```

**cURL**

```bash
curl -X POST https://api.pipedream.com/v1/connect/{project_id}/actions/run \
  -H "Content-Type: application/json" \
  -H "X-PD-Environment: production" \
  -H "Authorization: Bearer {access_token}" \
  -d '{
    "external_user_id": "{external_user_id}",
    "id": "microsoft_outlook-download-attachment",
    "configured_props": {
      "microsoft_outlook": { "authProvisionId": "apn_xxxxxxx" },
      "messageId": "Message ID",
      "attachmentId": "Attachment ID"
    }
  }'
```

---

- App: https://pipedream.com/apps/microsoft-outlook.md · All apps: https://pipedream.com/apps
