---
agent:
  instructions: "Use this search API to find relevant content across this site with keywords or natural-language queries, instead of crawling individual pages. Results are returned in Markdown."
  endpoint: "https://docs.sendcorex.com/.well-known/search?q={query}"
  method: "GET"
  documentation: "https://docs.sendcorex.com/llms.txt"
---

Source: https://docs.sendcorex.com/vi/api-reference/receive-emails/reading/get-messages

Nhận email: đọc thư

# Get Messages

Đọc tối đa 50 thư theo id, kèm nội dung, danh sách tệp đính kèm và header.

POST `https://g.sendcorex.com/v1` command: get_messages

Nội dung HTML được trả về nguyên bản, chưa làm sạch. Hãy làm sạch ở client trước khi hiển thị.

## Tham số

- `ids` string[] không bắt buộc
Tối đa 50 id thư.
- `id` string không bắt buộc
Một id thư. Dùng cái này hoặc `ids`.
- `include` string[] không bắt buộc
Những gì thêm vào mỗi thư: `body`, `attachments`, `headers`, `full_headers`. Mặc định `["body","attachments"]`.
ví dụ `["body", "headers", "attachments"]`

## Bắt đầu nhanh

```
import axios from 'axios';

const response = await axios.post(
  'https://g.sendcorex.com/v1',
  {
    commands: [
      {
        command: "get_messages",
        args: {
          ids: [
            "Vj0xQUJDMTIz"
          ],
          include: [
            "body",
            "headers",
            "attachments"
          ]
        }
      }
    ]
  },
  { headers: { Authorization: process.env.SENDCOREX_TOKEN } },
);

const [result] = response.data.results;
if (result.type !== 'SUCCESS') throw new Error(`${result.code}: ${result.message}`);
console.log(result.data);
```

## Phản hồi

```
{
  "type": "SUCCESS",
  "results": [
    {
      "command": "get_messages",
      "id": "0",
      "type": "SUCCESS",
      "data": {
        "messages": [
          {
            "message_uid": "Vj0xQUJDMTIz",
            "thread_id": "thr_9a1c4e72",
            "message_id": "<3f2a1b4c@SCOREX123MB45.prd.sendcorex.com>",
            "folders": [
              "INBOX"
            ],
            "labels": [
              "cliente-vip"
            ],
            "from_name": "Ana Costa",
            "from_email": "ana@client.com",
            "to": [
              {
                "email": "you@yourdomain.com"
              }
            ],
            "cc": [],
            "bcc": [],
            "subject": "Invoice for September",
            "is_read": false,
            "is_starred": false,
            "is_important": false,
            "snoozed_until": null,
            "received_at": "2026-10-09T14:21:07Z",
            "body": {
              "html": "<p>Hi, attached is the invoice.</p>",
              "text": "Hi, attached is the invoice.",
              "external_images": false
            },
            "headers": {
              "content_type": "multipart/mixed",
              "ip_address": "203.0.113.10",
              "is_tls": true,
              "spf_success": true,
              "dkim_success": true,
              "dmarc_success": true,
              "spam_score": 0.4,
              "list_unsubscribe": null
            },
            "attachments": [
              {
                "attachment_id": "Vj0xQVRUMDE",
                "file_name": "invoice.pdf",
                "mime_type": "application/pdf",
                "size_bytes": 48213,
                "inline": false,
                "content_id": null
              }
            ]
          }
        ],
        "not_found": []
      }
    }
  ]
}
```

### Trường phản hồi

- `messages[]`
Các trường phong bì và trạng thái (`folders`, `labels`, `to`, `cc`, `bcc`, `references`, `snoozed_until`…) cộng với những gì bạn yêu cầu trong `include`.
- `messages[].body`
`{ html, text, external_images }`. HTML là nguyên bản, chưa làm sạch.
- `messages[].headers`
`content_type`, `ip_address`, `is_tls`, `spf_success`, `dkim_success`, `dmarc_success`, `spam_score`, `list_unsubscribe`, `list_id`, `sender_provider` (nơi email được gửi đi, xác minh khi giao), `rules_matched`…
- `messages[].agent_score / agent_reasons`
Chỉ trong `Agents` và `NotSubscribing`: điểm sàng lọc và nguyên nhân.
- `messages[].full_headers`
Mọi thứ trong `headers` cộng `headers_json`, `received_chain`, `spf_result`, `dkim_result`, `dmarc_result` và `spam_result`.
- `messages[].attachments`
Danh sách với `attachment_id`, `file_name`, `mime_type`, `size_bytes`, `inline`, `content_id` và các trường `scan_*`. Không kèm bản thân tệp.
- `not_found`
Id không tồn tại trong hộp thư này.

## Tải tệp đính kèm

Danh sách tệp đính kèm không bao giờ chứa dữ liệu nhị phân. Lấy `attachment_id` và tải tệp bằng tuyến Raw Message.

GET `/v1/raw?message_id=<message_uid>&attachment_id=<attachment_id>`. Kiểu MIME gốc trả về trong `X-Original-Content-Type`.

## Lỗi

Lỗi ở mức HTTP trả về `type`, `code` và `message`. Lỗi đánh dấu CMD được trả về trong kết quả lệnh, với HTTP 200.

- 401`TOKEN_EXPIRED`
Access token đã hết hạn. Gọi Refresh Token và lặp lại yêu cầu.
- 401`INVALID_TOKEN`
Token sai định dạng, không xác định hoặc đã bị thu hồi.
- 429`RATE_LIMITED`
Hơn 15 yêu cầu/giây hoặc 15 yêu cầu đồng thời cho cùng IP + hộp thư. Chờ số giây trong Retry-After.
- CMD`INVALID_ARGS`
Thiếu hoặc sai tham số bắt buộc.
- CMD`INTERNAL`
Lỗi máy chủ. Chi tiết chỉ được ghi vào log máy chủ.
