MailHail API v1

Endpoints for mail flow, domains, mailboxes, diagnostics and automation.

Base URLhttps://mailhail.com/api/v1
AuthAuthorization: Bearer mh_live_...
Formatapplication/json
Tokens

Tokens sind separat verwaltet und können granular auf Mailbox, Domain oder Global Scope begrenzt werden.

Effective Permissions

Ein Token kann nie mehr als sein Owner. Entzogene User-Rechte wirken sofort auch auf bestehende Tokens.

Pagination

Mail-Listen nutzen Cursor Pagination und laden nur Metadaten, Preview und Flags.

Endpoints

Jede Karte ist ausklappbar und enthält Permission, Curl-Beispiel, Request und Response.

Core
GETCurrent principal/api/v1/meauthenticated

Returns the authenticated mailbox, admin flags, delegated domains and token prefix when a bearer token is used.

Curl

curl -H "Authorization: Bearer $MAILHAIL_TOKEN" https://mailhail.com/api/v1/me

Response

{
  "mailbox": "user@example.com",
  "global_admin": false,
  "domain_admins": ["example.com"],
  "token_prefix": "4f6c1e..."
}
Tokens
GETList API tokens/api/v1/tokenstokens.manage

Lists tokens owned by the authenticated mailbox, including grants, prefix and last-use metadata. Full secrets are never returned again.

Curl

curl -H "Authorization: Bearer $MAILHAIL_TOKEN" https://mailhail.com/api/v1/tokens

Response

{
  "tokens": [
    {
      "id": 42,
      "name": "deploy",
      "prefix": "ab12cd34ef56",
      "grants": [{"permission":"mail.send","scope_type":"mailbox","scope_key":"user@example.com"}]
    }
  ]
}
POSTCreate API token/api/v1/tokenstokens.manage

Creates a scoped token. The returned token string is shown once. Grants cannot exceed the current user's effective permissions.

Curl

curl -X POST -H "Content-Type: application/json" -b mh-session.txt https://mailhail.com/api/v1/tokens -d @token.json

Request JSON

{
  "name": "deploy sender",
  "expires_at": "2026-06-14T00:00:00Z",
  "grants": [
    {"permission":"mail.send","scope_type":"mailbox","scope_key":"user@example.com"}
  ]
}

Response

{
  "token": "mh_live_ab12cd34ef56_...",
  "record": {"id":42,"name":"deploy sender","prefix":"ab12cd34ef56"}
}
DELETERevoke API token/api/v1/tokens/{id}tokens.manage

Revokes one of the current mailbox's API tokens.

Curl

curl -X DELETE -H "Authorization: Bearer $MAILHAIL_TOKEN" https://mailhail.com/api/v1/tokens/42

Response

{"ok":true}
Mail
GETList folders/api/v1/mail/folders?mailbox=user@example.commail.folders.read

Returns folder metadata, total visible messages and unread counts for a mailbox.

Curl

curl -H "Authorization: Bearer $MAILHAIL_TOKEN" "https://mailhail.com/api/v1/mail/folders?mailbox=user@example.com"

Response

{
  "mailbox": "user@example.com",
  "folders": [{"Name":"INBOX","Count":15731,"Unread":12}]
}
GETList message metadata/api/v1/mail/messages?mailbox=user@example.com&folder=INBOX&limit=50&cursor=...mail.metadata.read

Returns a cursor-paginated message list. The list endpoint returns metadata and previews only, not full bodies.

Curl

curl -H "Authorization: Bearer $MAILHAIL_TOKEN" "https://mailhail.com/api/v1/mail/messages?mailbox=user@example.com&folder=INBOX&limit=50"

Response

{
  "mailbox": "user@example.com",
  "messages": [{"row_id":24145,"subject":"Hello","seen":false}],
  "next_cursor": "MTcx..."
}
GETRead message/api/v1/mail/messages/{row_id}mail.content.read

Returns sanitized body content, headers and attachment metadata for one message.

Curl

curl -H "Authorization: Bearer $MAILHAIL_TOKEN" https://mailhail.com/api/v1/mail/messages/24145

Response

{
  "row_id": 24145,
  "subject": "Hello",
  "body_plain": "Message text",
  "attachments": [{"index":1,"filename":"invoice.pdf"}]
}
GETDownload raw RFC822/api/v1/mail/messages/{row_id}/rawmail.raw.read

Streams the immutable raw message as message/rfc822.

Curl

curl -OJ -H "Authorization: Bearer $MAILHAIL_TOKEN" https://mailhail.com/api/v1/mail/messages/24145/raw

Response

message/rfc822
GETDownload attachment/api/v1/mail/messages/{row_id}/attachments/{part}mail.attachments.read

Streams a decoded attachment by part index.

Curl

curl -OJ -H "Authorization: Bearer $MAILHAIL_TOKEN" https://mailhail.com/api/v1/mail/messages/24145/attachments/1

Response

application/octet-stream or original content type
PATCHUpdate flags and Thunderbird labels/api/v1/mail/messages/{row_id}/flagsmail.flags.write

Supports set, add, remove and toggle. Thunderbird labels use $label1 through $label5.

Curl

curl -X PATCH -H "Authorization: Bearer $MAILHAIL_TOKEN" -H "Content-Type: application/json" https://mailhail.com/api/v1/mail/messages/24145/flags -d '{"op":"toggle","flags":["\\Flagged","$label1"]}'

Request JSON

{
  "op": "toggle",
  "flags": ["\\Flagged", "$label1"]
}

Response

{
  "ok": true,
  "message": {"row_id":24145,"flagged":true,"label_priority":1}
}
POSTMove message/api/v1/mail/messages/{row_id}/movemail.move

Moves a message to another folder and assigns a new UID in the destination folder.

Curl

curl -X POST -H "Authorization: Bearer $MAILHAIL_TOKEN" -H "Content-Type: application/json" https://mailhail.com/api/v1/mail/messages/24145/move -d '{"folder":"Archive"}'

Request JSON

{"folder":"Archive"}

Response

{"ok":true,"folder":"Archive"}
DELETEDelete message/api/v1/mail/messages/{row_id}mail.delete

Moves non-Trash messages to Trash. Deleting from Trash enters the configured retention/tombstone path.

Curl

curl -X DELETE -H "Authorization: Bearer $MAILHAIL_TOKEN" https://mailhail.com/api/v1/mail/messages/24145

Response

{"ok":true}
POSTSend mail through API/api/v1/mail/sendmail.send

Sends mail as a mailbox. Local recipients are ingested directly, remote recipients are queued for outbound SMTP delivery.

Curl

curl -X POST -H "Authorization: Bearer $MAILHAIL_TOKEN" -H "Content-Type: application/json" https://mailhail.com/api/v1/mail/send -d @send.json

Request JSON

{
  "mailbox": "user@example.com",
  "to": ["friend@example.net"],
  "subject": "Hello",
  "text": "Message",
  "attachments": [{"filename":"note.txt","content_type":"text/plain","data_base64":"SGVsbG8="}]
}

Response

{"ok":true}
Admin
GETList domains/api/v1/admin/domainsdomain.settings.read or global admin

Lists domains visible to the current principal. Bearer tokens still need a matching domain.settings.read grant.

Curl

curl -H "Authorization: Bearer $MAILHAIL_TOKEN" https://mailhail.com/api/v1/admin/domains

Response

{"domains":[{"Name":"example.com","QuotaBytes":53687091200}]}
GETRead domain settings/api/v1/admin/domains/{domain}domain.settings.read

Returns retention, archive, tombstone, catch-all and limit settings for one domain.

Curl

curl -H "Authorization: Bearer $MAILHAIL_TOKEN" https://mailhail.com/api/v1/admin/domains/example.com

Response

{"Name":"example.com","DefaultRetention":30,"QuotaBytes":53687091200}
PATCHUpdate domain settings/api/v1/admin/domains/{domain}domain.settings.write

Updates domain settings. Limit fields additionally require domain.quotas.write.

Curl

curl -X PATCH -H "Authorization: Bearer $MAILHAIL_TOKEN" -H "Content-Type: application/json" https://mailhail.com/api/v1/admin/domains/example.com -d '{"default_retention_days":30,"catch_all_email":"postmaster@example.com"}'

Request JSON

{
  "default_retention_days": 30,
  "catch_all_email": "postmaster@example.com",
  "quota_bytes": 53687091200
}

Response

{"Name":"example.com","DefaultRetention":30,"CatchAllEmail":"postmaster@example.com"}
GETList mailbox metadata/api/v1/admin/mailboxes?domain=example.comdomain.mailboxes.read or global admin

Returns mailbox metadata and usage summaries. It does not expose mailbox message contents to domain admins.

Curl

curl -H "Authorization: Bearer $MAILHAIL_TOKEN" "https://mailhail.com/api/v1/admin/mailboxes?domain=example.com"

Response

{
  "domain": "example.com",
  "mailboxes": [{"Email":"user@example.com","MessageCount":15731,"StorageBytes":844000000}]
}

Error Model

JSON error

{
  "error": {
    "code": "forbidden",
    "message": "missing mail.content.read"
  }
}
Status codes

401 means missing or invalid authentication. 403 means authentication worked, but the principal or token lacks the exact permission for the requested object.

Permission Catalog

Show all permissions
[
  "mail.metadata.read",
  "mail.content.read",
  "mail.raw.read",
  "mail.attachments.read",
  "mail.search",
  "mail.send",
  "mail.import",
  "mail.flags.read",
  "mail.flags.write",
  "mail.folders.read",
  "mail.folders.write",
  "mail.move",
  "mail.delete",
  "mail.restore",
  "mailbox.settings.read",
  "mailbox.settings.write",
  "domain.settings.read",
  "domain.settings.write",
  "domain.mailboxes.read",
  "domain.mailboxes.write",
  "domain.quotas.write",
  "domain.dns.read",
  "domain.dns.write",
  "domain.spam.read",
  "domain.spam.write",
  "events.read",
  "audit.read",
  "serverlogs.read",
  "security.read",
  "debug.enable",
  "jails.read",
  "jails.write",
  "global.settings.read",
  "global.settings.write",
  "global.domains.write",
  "global.users.write",
  "tokens.manage"
]