> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://agentinbox.space/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://agentinbox.space/_mcp/server.

# Вложения

> Узнайте, как отправлять файлы вложениями и скачивать входящие вложения из сообщений и тредов.

## Что такое `Attachments`?

`Attachment` — файл, связанный с `Message`. Это может быть счёт PDF, отчёт CSV или изображение (хотя в первом письме изображения лучше не слать — подробнее в разделе [доставляемости](/email-deliverability)). Агенты могут и отправлять `Attachments` в исходящих `Messages`, и обрабатывать вложения во входящих `Messages`.

## Отправка `Attachments`

Чтобы отправить файл, передайте массив `Attachments` при отправке `Message`. Каждый элемент — один файл; обязательно поле `content`.

* **`content`** (обязательно): содержимое файла в Base64.
* **`filename`** (необязательно): имя файла (например `invoice.pdf`).
* **`content_type`** (необязательно): MIME-тип (например `application/pdf`).

```python
import base64

# Простой текстовый файл для примера

file_content = "This is the content of our report."

# Содержимое нужно закодировать в Base64 перед отправкой

encoded_content = base64.b64encode(file_content.encode()).decode()

sent_message = client.inboxes.messages.send(
inbox_id="reports@agentinbox.space",
to=["supervisor@example.com"],
subject="Q4 Financial Report",
text="Please see the attached report.",
attachments=[{
"content": encoded_content,
"filename": "Q4-report.txt",
"content_type": "text/plain"
}]
)

```

**`TypeScript`**

```typescript title="TypeScript"
// Простой текстовый файл для примера
const fileContent = "This is the content of our report.";
// Содержимое нужно закодировать в Base64 перед отправкой
const encodedContent = Buffer.from(fileContent).toString("base64");

const sentMessage = await client.inboxes.messages.send("reports@agentinbox.space", {
  to: ["supervisor@example.com"],
  subject: "Q4 Financial Report",
  text: "Please see the attached report.",
  attachments: [{
    content: encodedContent,
    filename: "Q4-report.txt",
    contentType: "text/plain",
  }],
});
```

**`CLI`**

```bash title="CLI"
# отправить сообщение с вложением в base64
agentinbox inboxes:messages send \
  --inbox-id reports@agentinbox.space \
  --to supervisor@example.com \
  --subject "Q4 Financial Report" \
  --text "Please see the attached report." \
  --attachment.content "VGhpcyBpcyB0aGUgY29udGVudCBvZiBvdXIgcmVwb3J0Lg==" \
  --attachment.filename "Q4-report.txt" \
  --attachment.content-type "text/plain"
```

## Получение `Attachments`

Нужен `attachment_id` из массива `attachments` объекта `Message`. По ID можно скачать файл.

Ответ API при получении вложения — сырые байты файла; их можно сохранить на диск или обработать в памяти.

### Из конкретного `Message`

Если известны inbox, сообщение и вложение — запрос напрямую.

```python
inbox_id = "inbox_123"
message_id = "<def456@agentinbox.space>"
attachment_id = "attach_789" # Из объекта сообщения

file_data = client.inboxes.messages.get_attachment(
inbox_id=inbox_id,
message_id=message_id,
attachment_id=attachment_id
)

# Сохранение файла

with open("downloaded_file.pdf", "wb") as f:
f.write(file_data)

```

**`TypeScript`**

```typescript title="TypeScript"
const inboxId = "inbox_123";
const messageId = "<def456@agentinbox.space>";
const attachmentId = "attach_789"; // Из объекта сообщения

const fileData = await client.inboxes.messages.get_attachment(
  inboxId,
  messageId,
  attachmentId
);

// fileData — Blob/Buffer для обработки
// Например в Node.js:
// import fs from 'fs';
// fs.writeFileSync('downloaded_file.pdf', fileData);
```

**`CLI`**

```bash title="CLI"
# вложение из конкретного сообщения
agentinbox inboxes:messages get-attachment \
  --inbox-id inbox_123 \
  --message-id "<def456@agentinbox.space>" \
  --attachment-id attach_789
```

### Из конкретного `Thread`

То же, если известны inbox, тред и вложение — удобно для длинных переписок.

```python
inbox_id = "inbox_123"
thread_id = "thread_abc"
attachment_id = "attach_789" # Из сообщения в треде

file_data = client.inboxes.threads.get_attachment(
inbox_id=inbox_id,
thread_id=thread_id,
attachment_id=attachment_id
)

```

**`TypeScript`**

```typescript title="TypeScript"
const inboxId = "inbox_123";
const threadId = "thread_abc";
const attachmentId = "attach_789"; // Из сообщения в треде

const fileData = await client.inboxes.threads.get_attachment(
  inboxId,
  threadId,
  attachmentId
);
```

**`CLI`**

```bash title="CLI"
# вложение из треда
agentinbox inboxes:threads get-attachment \
  --inbox-id inbox_123 \
  --thread-id thread_abc \
  --attachment-id attach_789
```

## Скопировать в Cursor / Claude

Скопируйте один из блоков ниже для полного контекста по вложениям.

**`Python`**

```python title="Python"
"""
Agent Inbox Attachments — copy into Cursor/Claude.

Send: attachments=[{ content: base64_string, filename?, content_type? }] in messages.send/reply.
Get attachment_id from message.attachments or thread.attachments.

- messages.get_attachment(inbox_id, message_id, attachment_id) → bytes
- threads.get_attachment(inbox_id, thread_id, attachment_id) → bytes
"""
import base64
from agentinbox import Agentinbox

client = Agentinbox(api_key="YOUR_API_KEY")

encoded = base64.b64encode(b"file content").decode()
client.inboxes.messages.send(
  "agent@agentinbox.space",
  to="user@example.com",
  subject="Report",
  text="See attachment",
  attachments=[{"content": encoded, "filename": "report.txt", "content_type": "text/plain"}],
)

data = client.inboxes.messages.get_attachment("inbox@am.to", "<abc123@agentinbox.space>", "att_456")
with open("downloaded.pdf", "wb") as f:
  f.write(data)
```

**`TypeScript`**

```typescript title="TypeScript"
/**
 * Agent Inbox Attachments — copy into Cursor/Claude.
 *
 * Send: attachments: [{ content: base64String, filename?, contentType? }] in messages.send/reply.
 * Get attachmentId from message.attachments or thread.attachments.
 *
 * - messages.get_attachment(inboxId, messageId, attachmentId) → Buffer/Blob
 * - threads.get_attachment(inboxId, threadId, attachmentId) → Buffer/Blob
 */
import { AgentinboxClient } from "agentinbox";

const client = new AgentinboxClient({ apiKey: "YOUR_API_KEY" });

const encoded = Buffer.from("file content").toString("base64");
await client.inboxes.messages.send("agent@agentinbox.space", {
  to: "user@example.com",
  subject: "Report",
  text: "See attachment",
  attachments: [{ content: encoded, filename: "report.txt", contentType: "text/plain" }],
});

const data = await client.inboxes.messages.get_attachment("inbox@am.to", "<abc123@agentinbox.space>", "att_456");
```