Format response umum
Common response envelope
{
"success": true,
"data": {}
}
{
"success": false,
"error": "Readable error message"
}
Halaman ini menjelaskan request, response, error response, autentikasi, dan contoh penggunaan endpoint penting di aplikasi TempMail berbasis Cloudflare.
Ringkasan singkat tentang cara kerja API TempMail dan pola response yang dipakai di semua endpoint.
{
"success": true,
"data": {}
}
{
"success": false,
"error": "Readable error message"
}
Authorization: Bearer <accessToken>./api/admin/login./api/inboxes/access atau /api/inboxes/:id/unlock.Endpoint untuk domain, pembuatan inbox, login protected inbox, membaca email, memperpanjang inbox, dan manajemen inbox.
/api/domains
Dipakai halaman utama untuk mengisi dropdown domain. Hanya domain aktif dari D1 yang akan dikembalikan.
curl -X GET https://tempmail.example.com/api/domains
{
"success": true,
"data": [
{ "domain": "mail.bsmart.my.id", "isDefault": true },
{ "domain": "alt-mail.bsmart.my.id", "isDefault": false }
]
}
{
"success": false,
"error": "Readable error message"
}
/api/inboxes
Jika `password` kosong maka inbox bersifat temporary. Jika `password` diisi maka inbox menjadi protected lifetime.
{
"username": "demo",
"domain": "mail.bsmart.my.id",
"password": ""
}
curl -X POST https://tempmail.example.com/api/inboxes \
-H "Content-Type: application/json" \
-d '{"username":"demo","domain":"mail.bsmart.my.id","password":""}'
{
"success": true,
"data": {
"id": "inb_abc123456789",
"address": "demo@mail.bsmart.my.id",
"accessToken": "eyJhbGciOi...",
"isProtected": false,
"isLifetime": false,
"expiresAt": "2026-04-18T01:15:00.000Z"
}
}
{
"success": false,
"error": "Selected domain is not available"
}
{
"success": false,
"error": "Too many inboxes created, please slow down"
}
/api/inboxes/access
Dipakai saat token protected inbox hilang. Server akan memverifikasi password dan mengeluarkan access token baru.
{
"address": "demo@mail.bsmart.my.id",
"password": "super-secret-password"
}
curl -X POST https://tempmail.example.com/api/inboxes/access \
-H "Content-Type: application/json" \
-d '{"address":"demo@mail.bsmart.my.id","password":"super-secret-password"}'
{
"success": true,
"data": {
"id": "inb_abc123456789",
"address": "demo@mail.bsmart.my.id",
"accessToken": "eyJhbGciOi...",
"isProtected": true,
"isLifetime": true,
"expiresAt": null
}
}
{
"success": false,
"error": "Invalid password"
}
{
"success": false,
"error": "Too many access attempts"
}
/api/inboxes/:id
Untuk inbox protected tanpa token valid, endpoint ini tetap berguna karena akan memberi tahu bahwa inbox sedang locked.
curl -X GET https://tempmail.example.com/api/inboxes/inb_abc123456789
{
"success": true,
"data": {
"id": "inb_abc123456789",
"address": "demo@mail.bsmart.my.id",
"isProtected": true,
"isLifetime": true,
"status": "active",
"expiresAt": null,
"messageCount": 4,
"locked": true,
"accessGranted": false,
"canExtend": false
}
}
{
"success": false,
"error": "Inbox not found"
}
{
"success": false,
"error": "Inbox expired"
}
/api/inboxes/:id/messages
Gunakan query `q` untuk pencarian sender, subject, atau isi email. Endpoint ini dipakai untuk panel daftar email di UI inbox.
q=facebook
curl -X GET "https://tempmail.example.com/api/inboxes/inb_abc123456789/messages?q=facebook" \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN"
{
"success": true,
"data": [
{
"id": "msg_1",
"senderEmail": "registration@facebookmail.com",
"subject": "15446 is your confirmation code",
"receivedAt": "2026-04-17T01:07:51.000Z",
"status": "unread"
}
]
}
{
"success": false,
"error": "Access denied"
}
{
"success": false,
"error": "Inbox is locked"
}
/api/messages/:id
Response berisi text body, sanitized HTML, attachment metadata, dan data ekstraksi lain yang dibutuhkan UI.
curl -X GET https://tempmail.example.com/api/messages/msg_1 \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN"
{
"success": true,
"data": {
"id": "msg_1",
"inboxId": "inb_abc123456789",
"senderEmail": "registration@facebookmail.com",
"senderName": "Facebook",
"subject": "15446 is your confirmation code",
"textBody": "15446 is your confirmation code",
"htmlBody": "...
",
"attachments": [],
"receivedAt": "2026-04-17T01:07:51.000Z"
}
}
{
"success": false,
"error": "Message not found"
}
{
"success": false,
"error": "Access denied"
}
/api/inboxes/:id/unlock
Setelah berhasil, endpoint ini memutar access token baru. Cocok dipakai dari halaman inbox ketika status inbox masih locked.
{
"password": "super-secret-password"
}
curl -X POST https://tempmail.example.com/api/inboxes/inb_abc123456789/unlock \
-H "Content-Type: application/json" \
-d '{"password":"super-secret-password"}'
{
"success": true,
"data": {
"id": "inb_abc123456789",
"accessToken": "eyJhbGciOi...",
"expiresAt": null,
"isProtected": true,
"isLifetime": true
}
}
{
"success": false,
"error": "Invalid password"
}
{
"success": false,
"error": "Too many unlock attempts"
}
/api/inboxes/:id/extend
Durasi yang diizinkan adalah `24h`, `3d`, dan `7d`. Protected lifetime inbox tidak bisa di-extend.
{
"duration": "24h"
}
curl -X POST https://tempmail.example.com/api/inboxes/inb_abc123456789/extend \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{"duration":"24h"}'
{
"success": true,
"data": {
"id": "inb_abc123456789",
"expiresAt": "2026-04-19T01:15:00.000Z",
"extendedCount": 1
}
}
{
"success": false,
"error": "Permanent inbox does not require extension"
}
{
"success": false,
"error": "Access denied"
}
/api/inboxes/:id
Aksi ini mem-purge email, attachment reference, dan token akses. Tidak bisa di-undo.
curl -X DELETE https://tempmail.example.com/api/inboxes/inb_abc123456789 \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN"
{
"success": true,
"data": {
"deleted": true
}
}
{
"success": false,
"error": "Access denied"
}
Endpoint untuk update inbox realtime melalui long-poll dan WebSocket.
/api/inboxes/:id/wait?timeout=30&since=cursor
Pakai endpoint ini kalau kamu tidak ingin menggunakan WebSocket. Worker akan menunggu sampai timeout atau ada event baru.
timeout=1..30, since=
curl -X GET "https://tempmail.example.com/api/inboxes/inb_abc123456789/wait?timeout=30" \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN"
{
"success": true,
"data": {
"hasUpdate": true,
"cursor": "1713322800",
"type": "message.received"
}
}
{
"success": false,
"error": "Readable error message"
}
/ws/inboxes/:id?token=
Ketika email baru selesai diproses, Durable Object inbox room akan mendorong event `message.received` ke koneksi aktif.
const socket = new WebSocket(
"wss://tempmail.example.com/ws/inboxes/inb_abc123456789?token=YOUR_ACCESS_TOKEN"
);
{
"type": "message.received",
"messageId": "msg_1",
"receivedAt": "2026-04-17T02:20:00.000Z"
}
{
"success": false,
"error": "Readable error message"
}