MailGate API Reference

Dịch vụ gửi email giao dịch (mock) cho English app — biên nhận thanh toán, báo thất bại, chào mừng Premium. Đối tác thứ 2 bên cạnh PayGate.

Base URL: http://localhost:4343 · Đặc tả: openapi.yaml

Server giả phục vụ đào tạo. Dữ liệu trong RAM, mất khi restart.

Giới thiệu

REST API trả JSON. Tài nguyên: templates (mẫu email có sẵn) và messages (email đã gửi + trạng thái giao). Mọi request /v1/* cần khóa Bearer.

Xác thực

Header Authorization: Bearer mg_test_.... Lưu ý: khóa MailGate KHÁC khóa PayGate — mỗi đối tác 1 khóa riêng.

Header
Authorization: Bearer mg_test_demo_4343

Lỗi

HTTPcodeÝ nghĩa
400missing_fieldThiếu to/template
400invalid_emailĐịa chỉ email sai định dạng
400template_not_foundTemplate không tồn tại
401unauthorizedThiếu/sai khóa
429rate_limitedGửi quá nhiều
Gửi tới bounce@... để mô phỏng email bị trả về: message tạo thành công nhưng status: "bounced" + bounce_reason. Đây là case dạy "gửi OK ≠ giao thành công".

GET/v1/templates

Liệt kê template + biến bắt buộc. Template: receiptpayment_failedwelcome_premium

curl -s $BASE/v1/templates \
  -H "Authorization: Bearer mg_test_demo_4343"

POST/v1/messages

Gửi 1 email theo template với biến điền sẵn.

Tham sốMô tả
to bắt buộcEmail người nhận
template bắt buộcreceipt | payment_failed | welcome_premium
variablesBiến điền vào template
Request
curl -s $BASE/v1/messages \
  -H "Authorization: Bearer mg_test_demo_4343" \
  -d '{"to":"hv@example.com","template":"receipt",
       "variables":{"customer_name":"A","amount":"99.000đ","charge_id":"ch_abc"}}'
Response 201
{ "id":"msg_...", "to":"hv@example.com",
  "template":"receipt", "status":"delivered" }

GET/v1/messages/{id}

Tra trạng thái giao email. Trạng thái: queueddeliveredbouncedfailed

curl -s $BASE/v1/messages/msg_abc \
  -H "Authorization: Bearer mg_test_demo_4343"

GET/v1/messages

Liệt kê email đã gửi (phân trang qua ?limit=).

curl -s $BASE/v1/messages?limit=5 \
  -H "Authorization: Bearer mg_test_demo_4343"

MailGate mock · tài liệu phục vụ Buổi 6 — Integrate.