Bỏ qua, tới nội dung chính

Tài liệu

Mailera API

Quản lý hộp thư Microsoft (Outlook, Hotmail, Microsoft 365) từ A đến Z qua REST: thêm hộp thư, kiểm tra còn hoạt động, đọc thư, lấy OTP, gửi thư, kéo khỏi Spam và nhận webhook.

Giới thiệu

Mọi endpoint nằm dưới một địa chỉ gốc, nhận và trả về JSON.

  1. 1Tạo tài khoản và workspace riêng (miễn phí).
  2. 2Vào Cài đặt → API key, tạo key và chọn quyền.
  3. 3Gửi key qua header X-API-Key trong mọi lượt gọi.

Thành công trả về trường data; lỗi trả về trường error gồm code và message.

Tạo workspace miễn phí
Địa chỉ gốc
https://mailera.app/api/public/v1# 200{ "data": [ ... ], "next_cursor": "..." }# 4xx / 5xx{ "error": { "code": "not_found", "message": "..." } }

Xác thực

Gửi API key trong header X-API-Key. Key bắt đầu bằng mh_live_ và chỉ hiện một lần khi tạo; nếu làm mất, hãy tạo key mới và thu hồi key cũ.

Header Authorization dạng Bearer với cùng key cũng được chấp nhận.

Key có thể giới hạn theo danh sách IP; gọi từ IP khác sẽ nhận lỗi 403.

cURL
curl https://mailera.app/api/public/v1/mailboxes \  -H "X-API-Key: mh_live_..."

Quyền của key

Mỗi key mang một hoặc nhiều quyền. Gọi endpoint mà key không có quyền sẽ nhận lỗi 403 forbidden.

QuyềnCho phép
readĐọc hộp thư, thư, OTP và vị trí Inbox/Spam
moveKéo khỏi Spam và di chuyển thư
importThêm hộp thư
syncYêu cầu đồng bộ ngay
sendGửi, trả lời và chuyển tiếp thư
manageTạm dừng, bật lại và xoá hộp thư
webhooksQuản lý webhook

Mã lỗi

Lỗi luôn có code ổn định và message tiếng Anh. Hãy xử lý theo code, không theo nội dung message.

HTTPMãÝ nghĩa
401unauthorizedThiếu, sai, hết hạn hoặc đã thu hồi API key
403forbiddenKey không có quyền cần thiết hoặc IP không nằm trong danh sách cho phép
404not_foundHộp thư hoặc thư không tồn tại, hoặc không thuộc workspace của key
409mailbox_unavailableHộp thư cần kết nối lại, đang tạm dừng hoặc chỉ dùng IMAP (chưa hỗ trợ)
422validation_errorDữ liệu gửi lên sai định dạng
429rate_limitedVượt 300 lượt/phút cho mỗi key — chờ theo header Retry-After
503upstream_errorMicrosoft đang lỗi hoặc giới hạn tốc độ — thử lại sau
500internal_errorLỗi hệ thống

Giới hạn và phân trang

Mỗi key được 300 lượt mỗi phút. Vượt giới hạn trả về 429 kèm header Retry-After.

Danh sách trả về next_cursor; gửi lại giá trị đó qua tham số cursor để lấy trang tiếp theo. Khi hết dữ liệu, next_cursor là null.

Tham số limit đặt số dòng mỗi trang.

cURL
curl "https://mailera.app/api/public/v1/mailboxes?limit=50&cursor=NEXT_CURSOR" \  -H "X-API-Key: mh_live_..."

Hộp thư

Thêm, kiểm tra, đồng bộ, tạm dừng và xoá hộp thư.

  • GET/mailboxes

    Danh sách hộp thư

    Quyền:
    read
    Query:
    status, q, cursor, limit
  • POST/mailboxes/import

    Nhập hộp thư hàng loạt (email:password:refresh_token:client_id, hoặc dấu |)

    Quyền:
    import
    Body:
    lines, text, group_id, duplicate_mode
  • GET/mailboxes/import

    Tiến độ lần nhập và kết quả từng dòng

    Quyền:
    import
    Query:
    job_id
  • GET/mailboxes/{id}

    Chi tiết hộp thư và bộ đếm thư mục

    Quyền:
    read
  • PATCH/mailboxes/{id}

    Tạm dừng hoặc bật lại hộp thư

    Quyền:
    manage
    Body:
    action (bắt buộc)
  • DELETE/mailboxes/{id}

    Xoá hộp thư

    Quyền:
    manage
  • GET/mailboxes/{id}/status

    Kiểm tra trực tiếp với Microsoft xem hộp thư còn hoạt động

    Quyền:
    read
  • POST/mailboxes/{id}/sync

    Đồng bộ ngay

    Quyền:
    sync
    Body:
    wait
Nhập hộp thư và xem tiến độ
curl -X POST https://mailera.app/api/public/v1/mailboxes/import \  -H "X-API-Key: mh_live_xxx" -H "content-type: application/json" \  -d '{"lines":["user@hotmail.com:pass:M.C5_refresh...:9e5f94bc-..."]}'# → { "data": { "job_id": "..." } }curl "https://mailera.app/api/public/v1/mailboxes/import?job_id=JOB_ID" -H "X-API-Key: mh_live_xxx"

Thư

Đọc, tìm kiếm, lấy OTP và gửi thư.

  • GET/mailboxes/{id}/messages

    Danh sách thư theo thư mục

    Quyền:
    read
    Query:
    folder, unread, cursor, limit
  • GET/mailboxes/{id}/messages/{msgId}

    Nội dung một thư

    Quyền:
    read
  • GET/mailboxes/{id}/otp

    Lấy mã OTP mới nhất

    Quyền:
    read
    Query:
    from, subject, since_minutes
  • POST/mailboxes/{id}/send

    Gửi, trả lời hoặc chuyển tiếp thư

    Quyền:
    send
    Body:
    to, cc, bcc, subject, html, text, importance, reply_to_message_id, mode, attachments
  • GET/messages/search

    Tìm thư trên mọi hộp thư

    Quyền:
    read
    Query:
    q, folder, limit
Gửi thư
curl -X POST https://mailera.app/api/public/v1/mailboxes/MAILBOX_ID/send \  -H "X-API-Key: mh_live_xxx" -H "content-type: application/json" \  -d '{"to":["customer@example.com"],"subject":"Hello","text":"Message body"}'

Spam

Kiểm tra vị trí Inbox/Spam và kéo thư khỏi Spam.

  • POST/mailboxes/{id}/messages/{msgId}/move

    Chuyển thư (ví dụ từ Spam về Inbox)

    Quyền:
    move
    Body:
    destination (bắt buộc)
  • POST/mailboxes/{id}/unspam

    Kéo toàn bộ hoặc theo người gửi khỏi Spam

    Quyền:
    move
    Body:
    filter
  • GET/mailboxes/{id}/placement

    Thư vào Inbox hay Spam

    Quyền:
    read
    Query:
    from, subject, since_minutes
Thư vào Inbox hay Spam, rồi kéo khỏi Spam
curl "https://mailera.app/api/public/v1/mailboxes/MAILBOX_ID/placement?from=me@example.com" -H "X-API-Key: mh_live_xxx"curl -X POST https://mailera.app/api/public/v1/mailboxes/MAILBOX_ID/unspam -H "X-API-Key: mh_live_xxx" \  -H "content-type: application/json" -d '{"filter":{"type":"sender","value":"me@example.com"}}'

Webhook

Đăng ký URL nhận sự kiện.

Với mỗi sự kiện, Mailera gửi POST JSON tới URL của bạn. Nếu endpoint trả lỗi hoặc không phản hồi, Mailera tự gửi lại với khoảng chờ tăng dần.

Sự kiệnKhi nào
message.receivedCó thư mới vào Inbox
message.junkCó thư mới rơi vào Spam
mailbox.disconnectedHộp thư mất kết nối (token bị thu hồi, đổi mật khẩu…)

Để xác minh, tính HMAC-SHA256 của chuỗi timestamp, dấu chấm và body bằng secret của webhook, rồi so sánh với header chữ ký.

Header đi kèm: X-MailHub-Event X-MailHub-Delivery X-MailHub-Timestamp X-MailHub-Signature

  • GET/webhooks

    Danh sách webhook

    Quyền:
    webhooks
  • POST/webhooks

    Tạo webhook (secret ký chỉ trả về một lần)

    Quyền:
    webhooks
    Body:
    url (bắt buộc), events, group_id
  • PATCH/webhooks/{id}

    Bật/tắt, đổi sự kiện hoặc URL của webhook

    Quyền:
    webhooks
  • DELETE/webhooks/{id}

    Xoá webhook

    Quyền:
    webhooks
Xác minh chữ ký webhook (Node.js)
import crypto from "node:crypto";// X-MailHub-Signature: sha256=<hex>   X-MailHub-Timestamp: <unix seconds>const expected = "sha256=" + crypto.createHmac("sha256", SECRET)  .update(timestamp + "." + rawBody).digest("hex");const ok = expected.length === signature.length &&  crypto.timingSafeEqual(Buffer.from(expected), Buffer.from(signature));

Ví dụ

Thay MAILBOX_ID và key bằng giá trị của bạn.

Nhập hộp thư và xem tiến độ
curl -X POST https://mailera.app/api/public/v1/mailboxes/import \  -H "X-API-Key: mh_live_xxx" -H "content-type: application/json" \  -d '{"lines":["user@hotmail.com:pass:M.C5_refresh...:9e5f94bc-..."]}'# → { "data": { "job_id": "..." } }curl "https://mailera.app/api/public/v1/mailboxes/import?job_id=JOB_ID" -H "X-API-Key: mh_live_xxx"
Kiểm tra hộp thư còn hoạt động
curl https://mailera.app/api/public/v1/mailboxes/MAILBOX_ID/status -H "X-API-Key: mh_live_xxx"
Lấy mã OTP mới nhất (15 phút gần đây)
curl "https://mailera.app/api/public/v1/mailboxes/MAILBOX_ID/otp?from=noreply@service.com&since_minutes=15" \  -H "X-API-Key: mh_live_xxx"# → { "data": { "code": "482913", "folder": "inbox", ... } }  or  { "data": { "code": null } }
Gửi thư
curl -X POST https://mailera.app/api/public/v1/mailboxes/MAILBOX_ID/send \  -H "X-API-Key: mh_live_xxx" -H "content-type: application/json" \  -d '{"to":["customer@example.com"],"subject":"Hello","text":"Message body"}'
Thư vào Inbox hay Spam, rồi kéo khỏi Spam
curl "https://mailera.app/api/public/v1/mailboxes/MAILBOX_ID/placement?from=me@example.com" -H "X-API-Key: mh_live_xxx"curl -X POST https://mailera.app/api/public/v1/mailboxes/MAILBOX_ID/unspam -H "X-API-Key: mh_live_xxx" \  -H "content-type: application/json" -d '{"filter":{"type":"sender","value":"me@example.com"}}'
JavaScript (phía máy chủ)
const res = await fetch("https://mailera.app/api/public/v1/mailboxes?limit=50", {  headers: { "X-API-Key": process.env.MAILERA_API_KEY },});const { data, next_cursor } = await res.json();
Python
import os, requestsr = requests.get(    "https://mailera.app/api/public/v1/mailboxes/MAILBOX_ID/messages",    params={"folder": "inbox", "limit": 20},    headers={"X-API-Key": os.environ["MAILERA_API_KEY"]},)print(r.json()["data"])
Xác minh chữ ký webhook (Node.js)
import crypto from "node:crypto";// X-MailHub-Signature: sha256=<hex>   X-MailHub-Timestamp: <unix seconds>const expected = "sha256=" + crypto.createHmac("sha256", SECRET)  .update(timestamp + "." + rawBody).digest("hex");const ok = expected.length === signature.length &&  crypto.timingSafeEqual(Buffer.from(expected), Buffer.from(signature));