9send-Mail · Developer

วิธีการใช้งาน

คู่มือเชื่อมต่อ RESTful API สำหรับดึงเมลชั่วคราวด้วย email + key โดยไม่ต้อง login

Introduction

เราให้บริการ RESTful API เรียกผ่าน HTTP ได้เลย

  • Base URL https://service.9send-otp.shop/api/[PATHS]
  • รองรับ GET และ POST
  • ส่ง key ผ่าน header X-Api-Key หรือ JSON body key เท่านั้น (ไม่รองรับ query string)

Get API Key

ต้องมี API key ทุกครั้งที่เรียก API สร้างได้จากหน้า Mailbox หลังเข้าสู่ระบบ

https://service.9send-otp.shop/mailbox

Key ยาวอย่างน้อย 24 ตัว (สุ่ม 32 เมื่อปล่อยว่าง) · แสดงเต็มครั้งเดียวตอนสร้าง · ใช้ได้เฉพาะเมลของบัญชีที่สร้าง key นั้น

ดูเมลบนเว็บโดยไม่ login ได้ที่ https://service.9send-otp.shop/open


Get Mails

ดึงรายการเมลของที่อยู่ที่ระบุ

Request

POST https://service.9send-otp.shop/api/mail
X-Api-Key: your-long-api-key

หรือใส่ key ใน JSON body (ห้ามใส่ใน query string)

{
  "email": "name{{ $mailDomain }}",
  "key": "your-long-api-key-at-least-24-chars",
  "limit": 50,
  "sync": true
}
  • email (required) — ที่อยู่อีเมลในระบบ
  • key (required ถ้าไม่มี header) — API key จากหน้า Mailbox (หรือใช้ header X-Api-Key)
  • limit (optional) — จำนวนสูงสุดต่อครั้ง ค่าเริ่ม 50 สูงสุด 100
  • sync (optional) — ดึงจากเซิร์ฟเวอร์เมลก่อนตอบ ค่าเริ่ม true

เรียงจากใหม่ไปเก่าตาม received_at

Response

{
  "ok": true,
  "email": "name{{ $mailDomain }}",
  "expired": false,
  "expires_at": "2026-07-26T18:28:14+00:00",
  "count": 2,
  "messages": [
    {
      "id": 12,
      "from_address": "noreply@example.com",
      "from_name": "Example",
      "subject": "Your OTP code",
      "is_read": false,
      "received_at": "2026-07-26T09:04:16+00:00",
      "preview": "Your code is 482917"
    }
  ],
  "sync": {
    "imported": 1,
    "skipped": 0,
    "disabled": false,
    "error": null
  }
}

Get Mail

ดึงเนื้อหาเมลฉบับเดียว

Request

POST https://service.9send-otp.shop/api/mail/{id}
{
  "email": "name{{ $mailDomain }}",
  "key": "your-long-api-key-at-least-24-chars",
  "mark_read": true
}
  • id — รหัสข้อความจากรายการ messages[].id
  • mark_read (optional) — มาร์คว่าอ่านแล้ว ค่าเริ่ม true

Response

{
  "ok": true,
  "email": "name{{ $mailDomain }}",
  "message": {
    "id": 12,
    "from_address": "noreply@example.com",
    "from_name": "Example",
    "subject": "Your OTP code",
    "text_body": "Your code is 482917",
    "html_body": "<p>Your code is 482917</p>",
    "is_read": true,
    "received_at": "2026-07-26T09:04:16+00:00"
  }
}

Send Outbound Mail

ส่งเมลออกจริงจาก admin{{ $mailDomain }} ไปยังผู้รับที่ระบุ (ต่างจาก /api/send-mail ที่ใส่ข้อความเข้า mailbox ในระบบ)

Request

POST https://service.9send-otp.shop/api/outbound-mail
X-Api-Key: your-SEND_API_KEY
Content-Type: application/json
{
  "to": "user@example.com",
  "subject": "หัวข้อ",
  "message": "ข้อความในเนื้อเมล",
  "html": false
}
  • to (required) — อีเมลผู้รับ
  • message (required) — เนื้อหาเมล
  • subject (optional) — หัวข้อ
  • html (optional) — true ถ้า message เป็น HTML

ใช้ server key เดียวกับ SEND_API_KEY (header X-Api-Key)

Response

{
  "ok": true,
  "to": "user@example.com",
  "from": "admin{{ $mailDomain }}",
  "subject": "หัวข้อ"
}

Errors

HTTP ความหมาย
400ส่ง key ผ่าน query string (ไม่รองรับแล้ว)
401ไม่มี key / key ผิด / ไม่ใช่เจ้าของเมล
404ไม่พบ mailbox หรือข้อความ
410mailbox หมดอายุแล้ว
422ข้อมูลไม่ครบ เช่น ไม่ส่ง email
429เรียกถี่เกินไป
{ "error": "Unauthorized" }

Examples

cURL

curl -X POST "https://service.9send-otp.shop/api/mail" \
  -H "Content-Type: application/json" \
  -H "Accept: application/json" \
  -H "X-Api-Key: your-long-api-key-at-least-24-chars" \
  -d "{\"email\":\"name{{ $mailDomain }}\"}"

JavaScript

const res = await fetch("https://service.9send-otp.shop/api/mail", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "Accept": "application/json",
    "X-Api-Key": "your-long-api-key-at-least-24-chars",
  },
  body: JSON.stringify({
    email: "name{{ $mailDomain }}",
  }),
});
const data = await res.json();
console.log(data.messages);