📋 Mục lục
🌟 Giới thiệu
API Temp Mail cho phép bạn quản lý email tạm thời thông qua các cuộc gọi HTTP. Bạn có thể thực hiện các thao tác sau:
- 📧 Đọc email với phân trang
- 🗑️ Xóa email cụ thể
- 🌐 Thêm domain mới
- ✅ Kiểm tra trạng thái domain
📡 Base URL: https://nguyenngocanhtu.com
🔐 Xác thực: API hiện tại không yêu cầu xác thực, nhưng cần đảm bảo domain và user email hợp lệ.
🔗 API Endpoints
📬 1. Đọc danh sách email
GET
/api/email/{domain}/{user}/
Mô tả: Lấy danh sách email của một user cụ thể với phân trang.
📥 Parameters
domain(path)Tên miền email
user(path)Tên người dùng
page(query, optional)Số trang (mặc định: 1)
limit(query, optional)Số email/trang (mặc định: 20, max: 100)
🔧 Request:
curl -X GET "https://nguyenngocanhtu.com/api/email/example.com/testuser/?page=1&limit=20"
📤 Response:
{
"emails": [
{
"id": 123,
"subject": "Welcome to our service",
"sender": "noreply@company.com",
"date": "2025-07-08T10:30:00",
"body": "Email content here...",
"html_body": "<p>Email content</p>",
"has_attachments": false
}
],
"total": 5,
"page": 1,
"limit": 20,
"has_more": false
}
📖 2. Đọc chi tiết email
GET
/api/email/{domain}/{user}/{email_id}
Mô tả: Lấy nội dung chi tiết của một email cụ thể.
📥 Parameters
domain(path)Tên miền email
user(path)Tên người dùng
email_id(path)ID của email
🔧 Request:
curl -X GET "https://nguyenngocanhtu.com/api/email/example.com/testuser/123"
🗑️ 3. Xóa email
DELETE
/api/email/{domain}/{user}/{email_id}
Mô tả: Xóa một email cụ thể.
🔧 Request:
curl -X DELETE "https://nguyenngocanhtu.com/api/email/example.com/testuser/123"
📤 Response:
{"status": "deleted"}
🌐 4. Thêm domain mới
POST
/api/add-domain/{domain}
Mô tả: Thêm một domain mới vào hệ thống.
🔧 Request:
curl -X POST "https://nguyenngocanhtu.com/api/add-domain/newdomain.com"
📤 Response:
{
"status": "added",
"domain": "newdomain.com",
"is_online": true
}
🎲 5. Lấy danh sách domain
Lấy toàn bộ domain online:
GET
/api/all-domains/
Lấy ngẫu nhiên domain:
GET
/api/random-domains?limit=10
📤 Response:
{
"domains": ["domain1.com", "domain2.com", "domain3.com"],
"total": 3
}
✅ 6. Kiểm tra MX record
GET
/api/check-mx/{domain}
Mô tả: Kiểm tra xem domain có MX record hợp lệ không.
📤 Response:
{"result": "online"}
💻 Ví dụ sử dụng
🐍 Python Example
import requests
BASE_URL = "https://nguyenngocanhtu.com"
class TempMailAPI:
def __init__(self, base_url=BASE_URL):
self.base_url = base_url
def get_emails(self, domain, user, page=1, limit=20):
url = f"{self.base_url}/api/email/{domain}/{user}/"
params = {"page": page, "limit": limit}
response = requests.get(url, params=params)
return response.json()
def delete_email(self, domain, user, email_id):
url = f"{self.base_url}/api/email/{domain}/{user}/{email_id}"
response = requests.delete(url)
return response.json()
def get_random_domains(self, limit=20):
url = f"{self.base_url}/api/random-domains"
params = {"limit": limit}
response = requests.get(url, params=params)
return response.json()
# Usage
api = TempMailAPI()
domains = api.get_random_domains(10)
print("Available domains:", domains)
🟨 JavaScript Example
const BASE_URL = 'https://nguyenngocanhtu.com';
async function getEmails(domain, user, page = 1, limit = 20) {
const response = await fetch(
`${BASE_URL}/api/email/${domain}/${user}/?page=${page}&limit=${limit}`
);
return response.json();
}
async function getRandomDomains(limit = 10) {
const response = await fetch(`${BASE_URL}/api/random-domains?limit=${limit}`);
return response.json();
}
// Usage
(async () => {
const domains = await getRandomDomains(5);
console.log('Domains:', domains);
})();
⚠️ Xử lý lỗi
API trả về các mã lỗi HTTP tiêu chuẩn:
📊 HTTP Status Codes
200Thành công
400Yêu cầu không hợp lệ
404Không tìm thấy
500Lỗi server
📤 Ví dụ Response lỗi:
{"detail": "Domain not found"}
📝 Lưu ý quan trọng
✅ Validation email
Email phải có format hợp lệ (
user@domain.com)
🌐 Domain status
Chỉ các domain có MX record hợp lệ mới được coi là "online"
⚡ Rate limiting
Không có giới hạn rate hiện tại, nhưng nên sử dụng hợp lý
🗂️ Data retention
Email sẽ bị xóa sau 30 ngày