# API tempmail.org free

# 1. Tạo hòm thư

curl --location --request POST 'https://mob2.temp-mail.org/mailbox' \
--header 'Host: mob2.temp-mail.org' \
--header 'user-agent: 3.49' \
--header 'accept: application/json' \
--header 'content-length: 0' \
--header 'accept-encoding: gzip'
import requests

url = "https://mob2.temp-mail.org/mailbox"

payload = {}
headers = {
  'Host': 'mob2.temp-mail.org',
  'user-agent': '3.49',
  'accept': 'application/json',
  'content-length': '0',
  'accept-encoding': 'gzip'
}

response = requests.request("POST", url, headers=headers, data=payload)

print(response.text)

# Kết quả trả về

{
    "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVM",
    "mailbox": "[email protected]"
}

# 2. Đọc danh sách hòm thư

curl --location 'https://mob2.temp-mail.org/messages' \
--header 'Host: mob2.temp-mail.org' \
--header 'user-agent: 3.49' \
--header 'accept: application/json' \
--header 'content-length: 0' \
--header 'accept-encoding: gzip' \
--header 'authorization: YOUR_TOKEN'
import requests

url = "https://mob2.temp-mail.org/messages"

payload = {}
headers = {
  'Host': 'mob2.temp-mail.org',
  'user-agent': '3.49',
  'accept': 'application/json',
  'content-length': '0',
  'accept-encoding': 'gzip',
  'authorization': YOUR_TOKEN # lấy từ bước 1
}

response = requests.request("GET", url, headers=headers, data=payload)

print(response.text)

# Kết quả trả về

{
    "mailbox": "[email protected]",
    "messages": [
        {
            "_id": "67370c50a7d7030033c512e7",
            "receivedAt": 1731660880,
            "from": "abc",
            "subject": "subject",
            "bodyPreview": " body ",
            "attachmentsCount": 0
        }
    ]
}

# 3. Đọc hòm thư theo id

curl --location 'https://mob2.temp-mail.org/messages/YOUR_ID' \
--header 'Host: mob2.temp-mail.org' \
--header 'user-agent: 3.49' \
--header 'accept: application/json' \
--header 'content-length: 0' \
--header 'accept-encoding: gzip' \
--header 'authorization: YOUR_TOKEN'
import requests

url = f"https://mob2.temp-mail.org/messages/{YOUR_ID}" # id lấy từ bước 2

payload = {}
headers = {
  'Host': 'mob2.temp-mail.org',
  'user-agent': '3.49',
  'accept': 'application/json',
  'content-length': '0',
  'accept-encoding': 'gzip',
  'authorization': YOUR_TOKEN # lấy từ bước 1
}

response = requests.request("GET", url, headers=headers, data=payload)

print(response.text)

# Kết quả trả về

{
    "_id": "123",
    "receivedAt": 1731660880,
    "user": "123",
    "mailbox": "[email protected]",
    "from": "mail",
    "subject": "subject",
    "bodyPreview": "bodyPreview",
    "bodyHtml": "bodyHtml",
    "attachmentsCount": 0,
    "attachments": [],
    "createdAt": "2024-11-15T08:54:40.124Z"
}