Emails DichVuGame cung cấp REST API cho phép bạn đăng nhập mailbox, đọc hộp thư, và xem nội dung từng email.
Phù hợp cho các use case như: bot xác thực OTP tự động, lưu trữ test mail cho QA, hoặc bất kỳ workflow nào cần một địa chỉ email 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
Authentication
Sau khi gọi /api/mailbox/login, server trả về một JWT token.
Gửi kèm token ở header Authorization cho các endpoint cần auth:
Use case: đăng ký dịch vụ với mailbox tạm thời, script tự động poll inbox và parse mã OTP 6 số từ mail xác thực.
import requests, time, re
API = 'https://your-domain.com'
EMAIL = 'otp-bot@yourdomain.com'
PASSWORD = 'your-password'
# 1. Login
r = requests.post(f'{API}/api/mailbox/login',
json={'email': EMAIL, 'password': PASSWORD})
token = r.json()['token']
headers = {'Authorization': f'Bearer {token}'}
# 2. Poll inbox cho tới khi co mail OTP (toi da 60s)
print('Waiting for OTP mail...')
for _ in range(30):
r = requests.get(f'{API}/api/mailbox/inbox', headers=headers)
messages = r.json()['messages']
for m in messages:
subject = (m['subject'] or '').lower()
if 'otp' in subject or 'verification' in subject or 'xac thuc' in subject:
# 3. Doc full noi dung
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';
const EMAIL = 'otp-bot@yourdomain.com';
const PASSWORD = 'your-password';
async function getOtp() {
// 1. Login
const loginRes = await fetch(`${API}/api/mailbox/login`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ email: EMAIL, password: PASSWORD }),
});
const { token } = await loginRes.json();
const auth = { Authorization: `Bearer ${token}` };
// 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 || '')) {
// 3. Doc full noi dung
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
200
OK
Request thành công
400
Bad Request
Thiếu field hoặc dữ liệu sai format
401
Unauthorized
Sai mật khẩu, token hết hạn, hoặc thiếu Authorization header
403
Forbidden
Không có quyền (ví dụ tạo mailbox từ IP không whitelist)
404
Not Found
Message không tồn tại hoặc không thuộc mailbox của bạn
429
Too Many Requests
Vượt rate limit (10 login / 15 phút / IP)
Lưu ý quan trọng
Token hết hạn 7 ngày — cache và tái sử dụng. Khi nhận 401, login lại để 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 khỏi hộp khi có mail mới đến.
Mọi message cũ hơn 1 ngày (24 giờ) sẽ bị xóa tự động, kể cả chưa đầy 20.
Tài khoản mailbox (email + password) được giữ 1 năm kể từ ngày tạo, sau đó sẽ bị xóa vĩnh viễn.
Cần 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.