API Docs

Mail Tạm Thời · DichVuGame

Về trang chính

Giới thiệu

Mail Tạm Thời cung cấp REST API để tạo địa chỉ email tạm, đọc hộp thưxem nội dung từng email. Phù hợp cho: bot nhận OTP tự động, lưu test mail cho QA, hoặc bất kỳ workflow nào cần email dùng một lần.

Phiên bản này không dùng mật khẩu cho mailbox. Truy cập hộp thư bằng token (trả về khi tạo) hoặc chỉ bằng chính địa chỉ email. Ai biết địa chỉ đều đọc được thư — chỉ dùng cho mục đích tạm thời.

Base URL

https://your-domain.com

Format

JSON

Token TTL

7 ngày

Rate limit login

10 / 15 phút / IP

Xác thực

Khi tạo mailbox hoặc gọi /api/mailbox/login, server trả về một JWT token. Gửi kèm token ở header cho các endpoint cần xác thực:

Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9....

Ngoài ra /api/mailbox/inbox còn chấp nhận chỉ email trong JSON body (không cần token, không cần mật khẩu) — tiện cho client đơn giản.

GET

/api/domains

Lấy danh sách domain đang hoạt động để dùng khi tạo mailbox. Không cần xác thực.

Response — 200 OK

{ "domains": ["yourdomain.com", "anotherdomain.net"] }

Ví dụ

curl https://your-domain.com/api/domains
POST

/api/mailbox/create

Tạo mailbox mới trên một domain đang hoạt động. Phần tên (local part) luôn được sinh ngẫu nhiên — không thể tự chọn. Response trả về địa chỉ email và một JWT token dùng được ngay.

Request body

{ "domain": "yourdomain.com" }

Response — 200 OK

{ "email": "abc123xyz456@yourdomain.com", "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...." }

Không còn trường password. Lưu lại email (hoặc token) để truy cập inbox sau này.

Ví dụ

curl -X POST https://your-domain.com/api/mailbox/create \ -H "Content-Type: application/json" \ -d '{"domain":"yourdomain.com"}'
const res = await fetch('https://your-domain.com/api/mailbox/create', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ domain: 'yourdomain.com' }), }); const { email, token } = await res.json();
import requests r = requests.post('https://your-domain.com/api/mailbox/create', json={ 'domain': 'yourdomain.com', }) data = r.json() print(data['email']) token = data['token'] # dùng luôn, không cần login lại
POST

/api/mailbox/login

Lấy JWT token cho một địa chỉ. Chỉ cần email — không cần mật khẩu. Nếu địa chỉ chưa tồn tại thì server tự tạo (miễn là domain đang hoạt động) rồi trả token luôn.

Request body

{ "email": "abc123@yourdomain.com" }

Response — 200 OK

{ "email": "abc123@yourdomain.com", "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...." }

Domain không được phục vụ hoặc email sai định dạng → 400.

Ví dụ

curl -X POST https://your-domain.com/api/mailbox/login \ -H "Content-Type: application/json" \ -d '{"email":"abc123@yourdomain.com"}'
const res = await fetch('https://your-domain.com/api/mailbox/login', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ email: 'abc123@yourdomain.com' }), }); const { token } = await res.json();
import requests r = requests.post('https://your-domain.com/api/mailbox/login', json={ 'email': 'abc123@yourdomain.com', }) token = r.json()['token']
GET

/api/mailbox/inbox

Trả về danh sách tối đa 20 message gần nhất. Không kèm body để response nhẹ — gọi /api/mailbox/message/:id để lấy nội dung.

Cách 1 — Header (token)

Authorization: Bearer <token>

Cách 2 — dùng POST với chỉ email trong body (không cần token):

{ "email": "abc123@yourdomain.com" }

Response — 200 OK

{ "email": "abc123@yourdomain.com", "messages": [ { "id": 42, "from_addr": "noreply@shop.com", "from_name": "Shop ABC", "subject": "Mã xác thực của bạn là 123456", "received_at": 1775638000000 } ] }

Schema (mỗi message)

Field Kiểu Mô tả
idnumberID message, dùng cho endpoint đọc chi tiết
from_addrstringEmail người gửi
from_namestringTên hiển thị (có thể rỗng)
subjectstringTiêu đề email
received_atnumberUnix timestamp (ms)

Ví dụ

curl https://your-domain.com/api/mailbox/inbox \ -H "Authorization: Bearer eyJhbGciOi..."
curl -X POST https://your-domain.com/api/mailbox/inbox \ -H "Content-Type: application/json" \ -d '{"email":"abc123@yourdomain.com"}'
const res = await fetch('https://your-domain.com/api/mailbox/inbox', { headers: { Authorization: 'Bearer ' + token }, }); const { messages } = await res.json();
r = requests.get( 'https://your-domain.com/api/mailbox/inbox', headers={'Authorization': f'Bearer {token}'}, ) messages = r.json()['messages']
GET

/api/mailbox/message/:id

Lấy full nội dung của một email, gồm cả text và HTML body. Cần token ở header.

URL params

  • id — ID message lấy từ inbox

Response — 200 OK

{ "id": 42, "mailbox_id": 7, "from_addr": "noreply@shop.com", "from_name": "Shop ABC", "subject": "Mã xác thực của bạn là 123456", "text_body": "Ma xac thuc: 123456\nCo hieu luc trong 5 phut.", "html_body": "<!doctype html><html><body><h2>OTP: <b>123456</b></h2></body></html>", "size_bytes": 512, "received_at": 1775638000000 }

Ví dụ

curl https://your-domain.com/api/mailbox/message/42 \ -H "Authorization: Bearer eyJhbGciOi..."
const res = await fetch('https://your-domain.com/api/mailbox/message/42', { headers: { Authorization: 'Bearer ' + token }, }); const msg = await res.json(); console.log(msg.subject, msg.text_body);
r = requests.get( f'https://your-domain.com/api/mailbox/message/{message_id}', headers={'Authorization': f'Bearer {token}'}, ) msg = r.json() print(msg['subject']) print(msg['text_body'])

Ví dụ đầy đủ — bot lấy OTP tự động

Use case: tạo mailbox tạm, dùng địa chỉ đó đi đăng ký dịch vụ, rồi script tự poll inbox và bắt mã OTP 6 số.

import requests, time, re API = 'https://your-domain.com' # 1. Tao mailbox moi (tra ve email + token) r = requests.post(f'{API}/api/mailbox/create', json={'domain': 'yourdomain.com'}) data = r.json() email, token = data['email'], data['token'] headers = {'Authorization': f'Bearer {token}'} print('Mailbox:', email) # dung email nay di dang ky dich vu # 2. Poll inbox cho toi khi co mail OTP (toi da 60s) for _ in range(30): messages = requests.get(f'{API}/api/mailbox/inbox', headers=headers).json()['messages'] for m in messages: subject = (m['subject'] or '').lower() if 'otp' in subject or 'verification' in subject or 'xac thuc' in subject: full = requests.get(f'{API}/api/mailbox/message/{m["id"]}', headers=headers).json() body = (full.get('text_body') or '') + (full.get('html_body') or '') match = re.search(r'\b(\d{6})\b', body) if match: print('OTP:', match.group(1)) exit() time.sleep(2) print('Timeout: no OTP found')
const API = 'https://your-domain.com'; async function getOtp() { // 1. Tao mailbox moi const { email, token } = await fetch(`${API}/api/mailbox/create`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ domain: 'yourdomain.com' }), }).then(r => r.json()); const auth = { Authorization: `Bearer ${token}` }; console.log('Mailbox:', email); // 2. Poll inbox toi da 60s for (let i = 0; i < 30; i++) { const { messages } = await fetch(`${API}/api/mailbox/inbox`, { headers: auth }) .then(r => r.json()); for (const m of messages) { if (/otp|verification|xac thuc/i.test(m.subject || '')) { const full = await fetch(`${API}/api/mailbox/message/${m.id}`, { headers: auth }) .then(r => r.json()); const body = (full.text_body || '') + (full.html_body || ''); const match = body.match(/\b(\d{6})\b/); if (match) return match[1]; } } await new Promise(r => setTimeout(r, 2000)); } throw new Error('No OTP received'); } getOtp().then(console.log).catch(console.error);

Mã lỗi

Code Ý nghĩa Khi nào
200OKRequest thành công
400Bad RequestThiếu field hoặc dữ liệu sai format (vd domain không tồn tại)
401UnauthorizedThiếu/sai token, token hết hạn, hoặc email không tồn tại
404Not FoundEmail chưa tồn tại (login), hoặc message không thuộc mailbox của bạn
429Too Many RequestsVượt rate limit login (10 / 15 phút / IP)

Lưu ý quan trọng

Token hết hạn sau 7 ngày — cache và tái sử dụng. Khi nhận 401, gọi lại /login với email để lấy token mới.
Chính sách lưu trữ:
  • Mỗi mailbox chỉ giữ tối đa 20 message gần nhất — mail cũ bị đẩy ra khi có mail mới đến.
  • Mọi message cũ hơn 1 ngày (24 giờ) bị xóa tự động, kể cả chưa đầy 20.
  • Địa chỉ mailbox được giữ 1 năm kể từ ngày tạo, sau đó bị xóa vĩnh viễn.
Không có mật khẩu: bất kỳ ai biết địa chỉ email đều đọc được inbox. Đừng dùng địa chỉ này cho thông tin nhạy cảm.
Gọi nhiều lần? Yêu cầu admin thêm IP của bot vào IP whitelist để bypass rate limit hoàn toàn.