Copied to clipboard!
Logo

TempMail API

Documentation v1.0

Giới thiệu

Chào mừng đến với tài liệu API TempMail. API này cung cấp quyền truy cập vào dịch vụ email tạm thời, cho phép bạn tạo địa chỉ email dùng một lần, nhận tin nhắn và quản lý hộp thư đến một cách lập trình.

Lưu ý: API này tuân thủ chuẩn RESTful và trả về phản hồi JSON. Tất cả các endpoint đều hỗ trợ CORS cho các yêu cầu cross-origin.

Base URL

Tất cả các yêu cầu API cần được gửi đến URL cơ sở sau:

http://web.cmsnpa.com/api.php

Xác thực

Hiện tại, API này không yêu cầu xác thực. Tất cả các endpoint đều có thể truy cập công khai.

Quan trọng: Vui lòng sử dụng API này một cách có trách nhiệm và tránh các yêu cầu quá nhiều có thể làm quá tải dịch vụ.

API Endpoints

1 GET

Lấy danh sách Domain

Lấy danh sách các domain email có sẵn để tạo địa chỉ email tạm thời.

Endpoint:

GET /api.php?action=get_domains

Tham số:

Không yêu cầu tham số

Ví dụ phản hồi:

{
  "data": [
    {
      "domain": "cmsnpa.com",
      "status": "active"
    },
    {
      "domain": "example.com",
      "status": "active"
    }
  ]
}
2 GET

Tạo Email Random

Tạo một địa chỉ email ngẫu nhiên. Mặc định ưu tiên domain cmsnpa.com hoặc clonenpa.com.

Endpoint:

GET /api.php?action=generate_email
GET /api.php?action=generate_email&domain={domain}

Tham số:

Tham số Kiểu Bắt buộc Mô tả
domain string Tùy chọn Domain cụ thể để tạo email. Nếu không có, ưu tiên cmsnpa.com hoặc clonenpa.com

Ví dụ phản hồi:

{
  "success": true,
  "email": "[email protected]",
  "message": "Email generated successfully"
}
3 GET

Kiểm tra Email mới

Kiểm tra xem có email mới cho một địa chỉ email cụ thể mà không cần lấy toàn bộ nội dung.

Endpoint:

GET /api.php?action=check_mail&email={email}

Tham số:

Tham số Kiểu Bắt buộc Mô tả
email string Bắt buộc Địa chỉ email cần kiểm tra tin nhắn mới

Ví dụ phản hồi:

{
  "success": true,
  "email": "[email protected]",
  "has_new_mail": true,
  "total_mails": 3,
  "latest_mail": {
    "from": "[email protected]",
    "subject": "Latest Message",
    "date": "2025-11-13 11:00:00"
  }
}
4 GET

Lấy danh sách Email

Lấy tất cả các email cho một địa chỉ email cụ thể.

Endpoint:

GET /api.php?action=get_mails&email={email}

Tham số:

Tham số Kiểu Bắt buộc Mô tả
email string Bắt buộc Địa chỉ email cần lấy tin nhắn

Ví dụ phản hồi:

{
  "success": true,
  "email": "[email protected]",
  "data": [
    {
      "from": "[email protected]",
      "from_field": "Sender Name <[email protected]>",
      "subject": "Welcome to our service",
      "date": "2025-11-13 10:30:00",
      "code": "123456",
      "html_content": "<p>Email content here...</p>",
      "text_content": "Email content here..."
    }
  ]
}
5 GET

Lấy mã OTP

Trích xuất các mã OTP (4-8 chữ số) từ tất cả email trong hộp thư.

Endpoint:

GET /api.php?action=get_otp&email={email}

Tham số:

Tham số Kiểu Bắt buộc Mô tả
email string Bắt buộc Địa chỉ email cần kiểm tra tin nhắn mới

Ví dụ phản hồi:

{
  "success": true,
  "email": "[email protected]",
  "has_new_mail": true,
  "total_mails": 3,
  "latest_mail": {
    "from": "[email protected]",
    "subject": "Latest Message",
    "date": "2025-11-13 11:00:00"
  }
}

Xử lý lỗi

API trả về thông báo lỗi phù hợp khi yêu cầu thất bại hoặc thiếu tham số.

Phản hồi lỗi phổ biến:

{
  "success": false,
  "message": "Email parameter is required",
  "data": []
}

Các trường hợp lỗi:

Thiếu tham số Email

Xảy ra khi tham số email bắt buộc không được cung cấp.

Action không hợp lệ

Xảy ra khi tham số action không được hỗ trợ.

Dịch vụ không khả dụng

Xảy ra khi dịch vụ email nguồn tạm thời không khả dụng.

Ví dụ Code

JavaScript (Fetch API)

// Get available domains
fetch('http://web.cmsnpa.com/api.php?action=get_domains')
  .then(response => response.json())
  .then(data => {
    console.log('Domains:', data.data);
  })
  .catch(error => console.error('Error:', error));

// Get mails for an email address
const email = '[email protected]';
fetch(`http://web.cmsnpa.com/api.php?action=get_mails&email=${encodeURIComponent(email)}`)
  .then(response => response.json())
  .then(data => {
    console.log('Mails:', data.data);
  })
  .catch(error => console.error('Error:', error));

// Check for new mail
fetch(`http://web.cmsnpa.com/api.php?action=check_mail&email=${encodeURIComponent(email)}`)
  .then(response => response.json())
  .then(data => {
    if (data.has_new_mail) {
      console.log(`You have ${data.total_mails} new messages!`);
    }
  })
  .catch(error => console.error('Error:', error));

// Generate random email (priority: cmsnpa.com or clonenpa.com)
fetch('http://web.cmsnpa.com/api.php?action=generate_email')
  .then(response => response.json())
  .then(data => {
    console.log('Generated email:', data.email);
  })
  .catch(error => console.error('Error:', error));

// Generate email with specific domain
fetch('http://web.cmsnpa.com/api.php?action=generate_email&domain=cmsnpa.com')
  .then(response => response.json())
  .then(data => {
    console.log('Generated email:', data.email);
  })
  .catch(error => console.error('Error:', error));

// Get OTP codes from email
fetch(`http://web.cmsnpa.com/api.php?action=get_otp&email=${encodeURIComponent(email)}`)
  .then(response => response.json())
  .then(data => {
    if (data.success && data.total_otps > 0) {
      console.log('Found OTP codes:', data.data);
      console.log('First OTP:', data.data[0].otp);
    }
  })
  .catch(error => console.error('Error:', error));

PHP (cURL)

<?php
// Get available domains
$url = 'http://web.cmsnpa.com/api.php?action=get_domains';
$response = file_get_contents($url);
$data = json_decode($response, true);
print_r($data['data']);

// Get mails for an email address
$email = '[email protected]';
$url = 'http://web.cmsnpa.com/api.php?action=get_mails&email=' . urlencode($email);
$response = file_get_contents($url);
$data = json_decode($response, true);
print_r($data['data']);

// Check for new mail
$url = 'http://web.cmsnpa.com/api.php?action=check_mail&email=' . urlencode($email);
$response = file_get_contents($url);
$data = json_decode($response, true);
if ($data['has_new_mail']) {
    echo "You have {$data['total_mails']} new messages!";
}

// Generate random email
$url = 'http://web.cmsnpa.com/api.php?action=generate_email';
$response = file_get_contents($url);
$data = json_decode($response, true);
echo "Generated email: {$data['email']}\n";

// Generate email with specific domain
$url = 'http://web.cmsnpa.com/api.php?action=generate_email&domain=cmsnpa.com';
$response = file_get_contents($url);
$data = json_decode($response, true);
echo "Generated email: {$data['email']}\n";

// Get OTP codes
$url = 'http://web.cmsnpa.com/api.php?action=get_otp&email=' . urlencode($email);
$response = file_get_contents($url);
$data = json_decode($response, true);
if ($data['success'] && $data['total_otps'] > 0) {
    echo "Found {$data['total_otps']} OTP codes\n";
    echo "First OTP: {$data['data'][0]['otp']}\n";
}
?>

Python (Requests)

import requests

# Base URL
base_url = 'http://web.cmsnpa.com/api.php'

# Get available domains
response = requests.get(f'{base_url}?action=get_domains')
data = response.json()
print('Domains:', data['data'])

# Get mails for an email address
email = '[email protected]'
response = requests.get(f'{base_url}?action=get_mails&email={email}')
data = response.json()
print('Mails:', data['data'])

# Check for new mail
response = requests.get(f'{base_url}?action=check_mail&email={email}')
data = response.json()
if data['has_new_mail']:
    print(f"You have {data['total_mails']} new messages!")

# Generate random email
response = requests.get(f'{base_url}?action=generate_email')
data = response.json()
print('Generated email:', data['email'])

# Generate email with specific domain
response = requests.get(f'{base_url}?action=generate_email&domain=cmsnpa.com')
data = response.json()
print('Generated email:', data['email'])

# Get OTP codes
response = requests.get(f'{base_url}?action=get_otp&email={email}')
data = response.json()
if data['success'] and data['total_otps'] > 0:
    print('Found OTP codes:', data['data'])
    print('First OTP:', data['data'][0]['otp'])

cURL (Command Line)

# Get available domains
curl -X GET "http://web.cmsnpa.com/api.php?action=get_domains"

# Get mails for an email address
curl -X GET "http://web.cmsnpa.com/[email protected]"

# Check for new mail
curl -X GET "http://web.cmsnpa.com/[email protected]"

# Generate random email (priority domains)
curl -X GET "http://web.cmsnpa.com/api.php?action=generate_email"

# Generate email with specific domain
curl -X GET "http://web.cmsnpa.com/api.php?action=generate_email&domain=cmsnpa.com"

# Get OTP codes from email
curl -X GET "http://web.cmsnpa.com/[email protected]"

Best Practices

Sử dụng khoảng thời gian Polling hợp lý

Khi kiểm tra email mới, sử dụng khoảng thời gian ít nhất 5-10 giây để tránh yêu cầu quá nhiều.

Xử lý lỗi một cách khéo léo

Luôn triển khai xử lý lỗi phù hợp và logic thử lại cho các lỗi mạng.

Cache danh sách Domain

Danh sách domain hiếm khi thay đổi, nên cân nhắc cache cục bộ để giảm lượng API calls.

URL Encode các tham số

Luôn URL-encode địa chỉ email và các tham số khác để đảm bảo định dạng yêu cầu đúng.

Cần trợ giúp?

Nếu bạn gặp bất kỳ vấn đề nào hoặc có câu hỏi về API, vui lòng liên hệ.