Mail API
Let a script read a mailbox, move and delete messages, send mail and manage contacts and calendars with an hfm_ token made in Mail's Settings.
Mail has a JSON API under /api/v1. Its own interface uses it in the browser; with an API token your scripts and
programs can use it too: an order form that sends from your address, a job that files invoices into a folder, a
program that keeps your contacts in step with another list.
| Address | https://mail.yourdomain.com/api/v1/… (also /mail/api/v1/… on the panel's address) |
| Sign-in | Authorization: Bearer hfm_… on every request; no cookie and no CSRF token |
| Reaches | the one mailbox the token was made in, and nothing else |
GET /api/v1 lists the addresses a token can call. It needs no token.
Make a token
Where: Mail › Settings › API tokens
- Type a Name that says what uses the token, for example Order form.
- Choose What it may do: Read only, or Read, change & send.
- Optional: choose how long it Works for (30, 90 or 365 days; No end date by default), and limit it to the
IP addresses it is used from under Only from these IP addresses (addresses and ranges such as
203.0.113.7 198.51.100.0/24). - Type Your mailbox password and click Make a token.
- Copy the token. It starts with
hfm_and is shown only once.
A mailbox can have up to 20 tokens. The list shows when each was made and last used, from which address, when it ends and where it works from. Remove stops a token at once.
| Rule | What it means |
|---|---|
| One mailbox | a token reads and sends as its own mailbox only; mail always goes out from that mailbox's address |
| Read only | a read-only token changes nothing: it cannot send, move, delete or flag, and reading a message does not mark it read |
| No settings | no token can change settings, filters, the autoresponder, two-factor login, app passwords or tokens |
| Stored as a hash | the server keeps only a SHA-256 of the token, so a lost token cannot be shown again: make a new one |
| Wrong tokens | a wrong token counts as a failed sign-in for the address it came from; after 10 in 15 minutes that address waits |
| Request limit | 600 requests a minute for each token (X-RateLimit-Limit, -Remaining and -Reset on every answer); over it, 429 with Retry-After |
| Sending limits | the same as for any mail from the mailbox: the hosting plan's hourly and daily limits and the server's spam checks |
| Password change | a token keeps working after the mailbox password changes; a deleted mailbox's tokens are deleted with it |
| Made by the owner | a token is made with the mailbox password, not from a mailbox opened from the Control Panel |
| Licence | the server's plan must include the API and Email |
Note: these tokens are Mail's own. The token API (
hf_tokens) creates and manages mailboxes; it does not read their mail.hf_andhff_tokens do not work here.
Answers
A call that worked answers its data as JSON with status 200. Anything else answers {"error": "…"}:
| Status | Means |
|---|---|
| 400 | refused; the message says why ("field" names the value it is about) |
| 401 | unknown, removed or expired token, or the mailbox no longer exists |
| 402 | the server's licence needs attention |
| 403 | the token is read-only, is used from an address outside its list, or asks for something tokens cannot do; or the plan has no API |
| 404, 405 | no such address, or the wrong method |
| 409, 422 | an Idempotency-Key that is still running, or was used for another request |
| 429 | too many requests, or too many wrong tokens from this address |
| 502 | the mail server could not be reached, or refused the message |
| 503 | Mail is not available, or tokens are not set up on this server |
Changes are sent as JSON (Content-Type: application/json).
Folders and messages
f is a folder name as GET /api/v1/folders gives it (INBOX when left out); uid is a message's number in that
folder.
| Call | What it does |
|---|---|
GET /api/v1/folders |
the folders with their message and unread counts, and the space used |
POST /api/v1/folders/change |
{"do":"create","name","parent"}, {"do":"rename","old","name"} or {"do":"delete","old","confirm":"1"} |
GET /api/v1/messages?f=INBOX |
one page of the list, newest first: p page, q search words, in = all, from, subject, to or body, show = unread or flagged |
GET /api/v1/message?f=INBOX&uid=7 |
sender, recipients, subject, date and the attachments (each with its part). A read-and-change token marks the message read |
GET /api/v1/message/body?f=INBOX&uid=7 |
text, and html made safe to show (scripts and tracking removed; img=1 keeps pictures from the internet) |
GET /api/v1/message/attachment?f=INBOX&uid=7&part=2 |
one attachment, as a download |
GET /api/v1/message/source?f=INBOX&uid=7 |
the whole message as it was received (message/rfc822) |
POST /api/v1/act |
{"f","uids":[7,9],"do"} with do = read, unread, flag, unflag, delete (to Trash; for good from Trash and Junk), spam, notspam or move (with "to": the folder). {"f","do":"empty"} empties Trash or Junk |
M=https://mail.yourdomain.com
T='Authorization: Bearer hfm_xxx'
curl -s -H "$T" "$M/api/v1/messages?f=INBOX&show=unread"
curl -s -H "$T" -H 'Content-Type: application/json' $M/api/v1/act \
-d '{"f":"INBOX","uids":[7],"do":"move","to":"Invoices"}'
Send a message
POST /api/v1/send with to, cc, bcc (addresses separated by commas; 100 at most together), subject and
body (plain text). The message is sent from the mailbox's own address with the name set in Settings, and a copy is
kept in Sent.
curl -s -H "$T" -H 'Content-Type: application/json' -H 'Idempotency-Key: order-1042' $M/api/v1/send \
-d '{"to":"sarah@example.com","subject":"Your order","body":"Thank you for your order."}'
For attachments send the same fields as multipart/form-data with the files as files[] (25 MB at most together):
curl -s -H "$T" $M/api/v1/send -F to=sarah@example.com -F subject=Invoice -F body='Attached.' -F 'files[]=@invoice.pdf'
Tip: send an
Idempotency-Keyheader (any text of your own, up to 255 characters, different for each message) with aPOST. If the connection drops and your program tries again with the same key within 24 hours, it gets the first answer back and the message is not sent twice.
Contacts
| Call | What it does |
|---|---|
GET /api/v1/contacts |
the contacts (q search, group) and the groups |
POST /api/v1/contacts/save |
{"name","emails":["…"],"phones":["…"],"org","title","note","groups":["…"]} adds a contact; with "id" it changes that one |
POST /api/v1/contacts/delete |
{"id"} or {"ids":[…]} |
Calendar
| Call | What it does |
|---|---|
GET /api/v1/cal?from=2026-11-01&to=2026-11-30 |
the calendars, and the events between the two days (tz: a time zone such as Europe/London) |
GET /api/v1/cal/event?cal=default&id=… |
one event |
POST /api/v1/cal/save |
{"cal":"default","title","start":"2026-11-12T09:00","end":"2026-11-12T10:00","tz","location","description","allday"} adds an event; with "id" it changes that one. "attendees" with "send":"1" emails the invitations |
POST /api/v1/cal/delete |
{"cal","id"} |
Calendar and contacts apps do not need a token: they sync over CalDAV and CardDAV, see Mail apps and phones.