---
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/th/api-reference/receive-emails/routes/raw-message

รับอีเมล: เส้นทาง

# Raw Message

ดาวน์โหลด .eml ดิบของข้อความหรือไฟล์แนบเป็นข้อมูลไบนารี

GET `https://g.sendcorex.com/v1/raw`

id ข้อความเป็น base64 จึงมี `+`, `/` และ `=` ให้เข้ารหัส URL ไลบรารี HTTP ทำให้เองเมื่อส่งเป็นพารามิเตอร์ query ดังตัวอย่างด้านล่าง

ไฟล์แนบส่งเป็น `attachment` พร้อม `application/octet-stream` เสมอ ชนิดเดิมอยู่ในเฮดเดอร์ตอบกลับ `X-Original-Content-Type` ถือว่าไฟล์แนบเป็นไฟล์ที่ไม่น่าเชื่อถือ

## พารามิเตอร์ query

- `message_id` string จำเป็น
`message_uid` ของข้อความ
- `attachment_id` string ไม่บังคับ
`attachment_id` ที่ `get_messages` ส่งกลับ เมื่อระบุ จะส่งไฟล์แนบแทนอีเมลทั้งฉบับ

## เริ่มต้นอย่างรวดเร็ว

```
import axios from 'axios';
import { writeFileSync } from 'node:fs';

const response = await axios.get('https://g.sendcorex.com/v1/raw', {
  params: { message_id: 'Vj0xQUJDMTIz', attachment_id: 'Vj0xQVRUMDE' },
  headers: { Authorization: process.env.SENDCOREX_TOKEN },
  responseType: 'arraybuffer',
});

writeFileSync('attachment.bin', Buffer.from(response.data));
```

## การตอบกลับ

```
HTTP/1.1 200 OK
Content-Type: application/octet-stream
Content-Disposition: attachment
X-Original-Content-Type: application/pdf

<binary data>
```

### ฟิลด์การตอบกลับ

- `Content-Type`
`message/rfc822` สำหรับอีเมลดิบ หรือ `application/octet-stream` สำหรับไฟล์แนบ
- `X-Original-Content-Type`
ชนิด MIME จริงของไฟล์แนบ เช่น `application/pdf`

## ดาวน์โหลดอีเมลทั้งฉบับ

ไม่ใส่ `attachment_id` เพื่อรับข้อความต้นฉบับเป็นไฟล์ `.eml`

Node.js

```
import axios from 'axios';
import { writeFileSync } from 'node:fs';

const res = await axios.get('https://g.sendcorex.com/v1/raw', {
  params: { message_id: 'Vj0xQUJDMTIz' },
  headers: { Authorization: process.env.SENDCOREX_TOKEN },
  responseType: 'arraybuffer',
});

writeFileSync('message.eml', Buffer.from(res.data));
```

## ข้อผิดพลาด

ข้อผิดพลาดระดับ HTTP ส่งกลับ `type`, `code` และ `message` ข้อผิดพลาดที่มีเครื่องหมาย CMD จะกลับมาในผลลัพธ์ของคำสั่ง พร้อม HTTP 200

- 401`MISSING_AUTH_HEADER`
ไม่ได้ส่งเฮดเดอร์ Authorization
- 401`INVALID_TOKEN`
โทเค็นผิดรูปแบบ ไม่รู้จัก หรือถูกเพิกถอน
- 401`TOKEN_EXPIRED`
access token หมดอายุแล้ว เรียก Refresh Token แล้วส่งคำขอซ้ำ
- 429`RATE_LIMITED`
เกิน 15 คำขอ/วินาที หรือ 15 คำขอพร้อมกันสำหรับ IP + กล่องจดหมายเดียวกัน รอจำนวนวินาทีใน Retry-After
