Use the Cloud REST API
Make your first request, choose a mailbox, and look up operation arguments.
Call POST https://cloud.fluxmail.ai/api/mail/{operation} with JSON arguments and an Authorization: Bearer header. REST and MCP use the same operations, mailbox grants, and scopes.
Mail operations need a connected mailbox and a Cloud agent key. The examples below use mail.read. Complete the quickstart if you haven't created a key yet.
Verify a read-only connection
Make your key available privately as FLUXMAIL_CLOUD_AGENT_KEY in your terminal's environment. Keep its value out of shell history, source files, and logs.
1. List your mailboxes
curl --fail-with-body https://cloud.fluxmail.ai/api/mail/list_accounts \
--header "Authorization: Bearer $FLUXMAIL_CLOUD_AGENT_KEY" \
--header 'Content-Type: application/json' \
--data '{}'The response contains only mailboxes available to the key. An example response:
{
"data": [
{
"id": "11111111-1111-4111-8111-111111111111",
"email": "you@example.com",
"provider": "gmail",
"shared": false,
"enabled": true
}
]
}2. List your 5 most recent emails
Copy the intended mailbox's id into this request, replacing MAILBOX_ID:
curl --fail-with-body https://cloud.fluxmail.ai/api/mail/list_emails \
--header "Authorization: Bearer $FLUXMAIL_CLOUD_AGENT_KEY" \
--header 'Content-Type: application/json' \
--data '{"accountId":"MAILBOX_ID","pageSize":5,"includeSnippet":false}'A successful response contains up to 5 email summaries. These two calls verify the key, its mailbox access, and the provider connection without opening message bodies or changing mail. A mailbox with fewer than 5 emails returns fewer results.
Operations and arguments
| Operation | Scope | Arguments |
|---|---|---|
get_connection_status | Any scope | {} |
send_feedback | None | message (1 to 4,000 characters), optional category (bug, feature, or other; defaults to other), requestId, toolName, errorCode, expectedBehavior, actualBehavior, contactEmail |
list_accounts | mail.read | {} |
list_emails | mail.read | accountId, optional query in the search syntax, folder, rawProviderQuery, pageSize (1 to 100), pageToken, includeSnippet, and includeSearchContext |
list_emails_batch | mail.read | accounts (1 to 20 objects with accountId and optional pageToken), optional query, a folder role, pageSize, includeSnippet, and includeSearchContext |
search_emails, search_emails_batch | mail.read | Other names for list_emails and list_emails_batch, with the same arguments |
get_email | mail.read | accountId, messageId, optional includeHeaders |
get_email_body | mail.read | accountId, messageId, bodyFormat (text or html), optional offset and maxChars (1 to 50,000) |
get_thread | mail.read | accountId, threadId |
list_folders, list_labels, list_send_as | mail.read | accountId |
create_folder | mail.organize | accountId, name (a folder name, or a subfolder path such as Projects/2026) |
delete_folder | mail.organize | accountId, folder (a folder ID from list_folders, or the folder name) |
rename_folder | mail.organize | accountId, folder (a folder ID from list_folders, or the folder name), name (the folder's new name, without its parent path) |
move_folder | mail.organize | accountId, folder (a folder ID from list_folders, or the folder name), and either parent (the ID or name of the folder to move it under) or topLevel: true |
create_label | mail.organize | accountId, name (a label name, or a nested Gmail label path such as Projects/2026) |
delete_label | mail.organize | accountId, label (a label ID from list_labels, or the label name) |
download_attachment | mail.read | accountId, messageId, attachmentId |
get_draft | mail.drafts | accountId, draftId |
create_draft | mail.drafts | accountId, message fields |
update_draft | mail.drafts | accountId, draftId, message fields |
create_attachment_upload | mail.drafts | accountId, draftId, filename, optional mimeType |
delete_draft | mail.drafts | accountId, draftId |
preview_send | mail.send, plus mail.drafts with draftId | accountId, message fields or draftId |
send_email | mail.send, plus mail.drafts with draftId | accountId, idempotencyKey, message fields or draftId, optional sendAt |
forward_email | mail.send and mail.read | accountId, idempotencyKey, messageId, to, optional cc, bcc, from, comment, includeAttachments, and sendAt |
get_delivery_operation | mail.send | accountId, operationId (the send's idempotency key) |
list_scheduled_emails | mail.read | optional accountId |
cancel_scheduled_email | mail.drafts | scheduleId, optional accountId |
modify_emails | mail.organize, mail.trash, or mail.delete, depending on action | accountId, messageIds, action, and folder or labels when required |
Modification actions require mail.organize for flags, labels, archive, and move; mail.trash for trash and untrash; or mail.delete for permanent deletion. Generic moves cannot target Trash or Archive or restore messages from Trash. Cloud returns succeededIds, failed (each with a messageId and error code), and uncertainIds. If the provider stops partway through, for example because of a rate limit or a network error, Cloud can't tell which messages changed and lists them all in uncertainIds. Check uncertain messages before you retry them. A move to a folder the mailbox doesn't have changes nothing and fails the whole call with not_found; use a folder ID from list_folders. On an IMAP mailbox, archive, trash and untrash fail the whole call with unsupported_capability when Cloud has no folder to use as the Archive or Trash. The mailbox's owner chooses one in the dashboard.
create_folder also creates any missing parent folders. If the folder already exists, Cloud returns it unchanged. Names of system folders, such as Inbox, Sent and Trash, are refused. In Gmail, the folder is a label.
delete_folder deletes an empty folder and returns its id and name in deleted. A folder that still has messages or subfolders is refused, so move or trash its mail and delete its subfolders first. In Gmail, remove the label from its messages instead. System folders, such as Inbox, Sent and Trash, can't be deleted, and neither can a folder the account uses as one. A folder the mailbox doesn't have returns not_found. IMAP can't delete a folder only if it's empty, so Fluxmail counts its messages just before deleting it. A message that another mail app or a server filter files into the folder in that moment is deleted with it.
rename_folder renames a folder and returns it as folder, with the folder as it was in previous. The folder stays under the same parent and keeps its messages and subfolders, so name can't contain the character the mailbox uses between folder levels. A name another folder has is refused. In Gmail, the labels nested under the renamed label are renamed too. System folders, such as Inbox, Sent and Trash, can't be renamed, and neither can a folder the account uses as one. A folder the mailbox doesn't have returns not_found. In an IMAP mailbox, the folder and its subfolders get new IDs. Message IDs normally stay the same. If one stops working, list the folder again.
move_folder moves a folder under another folder, or to the top level of the mailbox, and returns it as folder, with the folder as it was in previous. The folder keeps its own name, its messages and its subfolders. Send either parent or topLevel: true, not both. The destination can't be the folder itself, one of its subfolders, or the trash, and it can't already hold a folder with the same name. In Gmail, the labels nested under the moved label move with it. System folders can't be moved, and neither can a folder the account uses as one. In an IMAP mailbox, the folder and its subfolders get new IDs. Message IDs normally stay the same. If one stops working, list the folder again.
create_label creates a Gmail label or an Outlook category and returns it. If one with the name already exists, Cloud returns it unchanged. In Gmail, a path such as Projects/2026 creates a nested label and any missing parents, and the label also works as a folder. Gmail refuses names it uses for system labels and folders, such as Inbox, Archive and Starred. A new Outlook category has no color. delete_label deletes a Gmail label or an Outlook category and returns its id and name in deleted. Deleting a Gmail label removes it from its messages, which stay in the mailbox. Deleting an Outlook category removes it from the mailbox's category list, but messages that have it keep its name. A Gmail label with nested labels, and a Gmail system label such as Inbox, can't be deleted. A label the mailbox doesn't have returns not_found, and IMAP mailboxes return unsupported_capability. An Outlook mailbox connected before Cloud could change categories returns permission_denied until you reconnect it.
get_connection_status returns workspace, connection (its kind, name, scopes, mailbox mode and expiration), mailboxes with their IDs, subscription (whether the plan is active, with its status and end dates), and dashboard links. It doesn't contact a mail provider.
For mailbox operations, use IDs returned by Cloud and include accountId to select a mailbox. list_emails filters through a query string such as from:ann@example.com is:unread after:2026-01-01 invoice. Use folder for a custom folder or label; if the query also sets in:, the two must name the same folder. Search words can't be combined with rawProviderQuery. list_emails_batch returns one group per mailbox, each with a page of results or an error, and fails only when every mailbox fails. Dates use YYYY-MM-DD. Follow returned pagination tokens; the default page size is 25. A page token expires after an hour and works only with the same mailbox, filters, and page size.
Message fields include to, cc, and bcc as arrays of address strings, subject, bodyText, bodyHtml, optional from, attachments, replyToMessageId, and replyAll. Attachments use filename, mimeType, and base64 content, with optional inline-image fields. To attach a file that is already in the mailbox, give its messageId and attachmentId instead; this needs mail.read. A message's attachments can total 15 MB. A new message or draft needs at least one recipient. Replying to a message requires mail.read as well as the operation's scope so Cloud can read the original.
Attach a large file
A file sent as base64 makes the request about a third larger than the file. To skip that, save a draft and call create_attachment_upload with its draftId and the file's filename. The response has an uploadUrl that works once and expires after 15 minutes, its expiresAt time, and maxBytes, the room left in the draft. Open the link in a browser and choose the file, or send the file to it:
curl --fail-with-body -T contract.pdf UPLOAD_URLThe request must state its Content-Length, which curl -T and browsers do. Cloud adds the file to the draft in the mailbox, returns HTTP 201 with the draft's attachments, and doesn't keep a copy of the file. Send the file itself as the request body; a form upload, such as curl -F, is refused. If the upload stops before the whole file arrives, you can send it to the same link again before it expires. A draft that is scheduled to send can't take a file this way; cancel the schedule first. Send the draft with send_email and its draftId.
Modification actions are markRead, markUnread, star, unstar, archive, trash, untrash, delete, move, addLabels, and removeLabels. move requires folder; label actions require labels. Permanent deletion is unavailable for Gmail OAuth connections. MCP lists each action as a separate tool with the same arguments minus action: mark_emails_read, mark_emails_unread, star_emails, unstar_emails, archive_emails, trash_emails, restore_emails, delete_emails, move_emails, add_labels, and remove_labels.
Send feedback
Call send_feedback with a message the user has reviewed and approved, along with any approved diagnostics. It needs an active agent key, no mail scope or mailbox access, and works after the plan ends. Submit only at the user's request; do not retry automatically.
| Field | Constraint |
|---|---|
message | Required; 1 to 4,000 characters |
category | Optional; bug, feature, or other (default) |
requestId | Optional; the related failed call's UUID |
toolName, errorCode | Optional; 1 to 64 lowercase letters or underscores each |
expectedBehavior, actualBehavior | Optional; 1 to 1,000 characters each |
contactEmail | Optional; one valid email address, at most 320 characters, confirmed by the user |
The text in message, expectedBehavior and actualBehavior must not be blank or contain NUL characters. Omit diagnostics you do not know. Never select a connected mailbox address as contactEmail automatically. Cloud includes the signed-in account email separately and uses it for replies if contactEmail is omitted. Reports also include account and workspace IDs, the product version, submission request ID and transport. Keep email contents, attachments, raw tool arguments, provider responses, logs, conversation history and credentials out of feedback. See the privacy policy for recipients and retention.
The response contains feedbackId, the exact message, category, product, optional version and the submitted diagnostics. It echoes a caller-provided reply address without exposing the automatically resolved account email.
Each user can submit five reports per hour across keys and workspaces; further submissions return rate_limited. Feedback doesn't count toward mail usage. Cloud keeps reports for 90 days, or until the account or workspace is deleted; downstream copies have separate retention.
Download an attachment
Unlike the other operations, download_attachment returns the file's bytes as the response body, for attachments up to 50 MB. Content-Type carries the attachment's MIME type and Content-Disposition carries its filename, so you can save the body as is. Content-Length is present for Gmail attachments. Outlook and IMAP downloads usually arrive without it, so read the response until it ends. A download has 90 seconds to finish, so a 50 MB file needs a connection of about 5 Mbit/s. Use the message ID and the attachment's id from get_email:
curl --fail-with-body https://cloud.fluxmail.ai/api/mail/download_attachment \
--header "Authorization: Bearer $FLUXMAIL_CLOUD_AGENT_KEY" \
--header 'Content-Type: application/json' \
--data '{"accountId":"MAILBOX_ID","messageId":"MESSAGE_ID","attachmentId":"ATTACHMENT_ID"}' \
--output report.pdfIf the provider reports an invalid MIME type, Cloud sends application/octet-stream. Errors use the usual JSON error body. With --output, curl writes that error body to the file and exits with code 22, so check the exit code before opening the file.
Search example
Send this body to /api/mail/list_emails with a read-scoped key:
{
"accountId": "MAILBOX_ID",
"query": "subject:invoice after:2026-10-01",
"pageSize": 10
}Call from Node.js
Save this helper in an .mjs file and run it with a Node.js release that includes fetch. Supply your key and the mailbox ID from list_accounts as environment variables before running it.
const token = process.env.FLUXMAIL_CLOUD_AGENT_KEY;
const accountId = process.env.FLUXMAIL_CLOUD_ACCOUNT_ID;
if (!token || !accountId) {
throw new Error('Set FLUXMAIL_CLOUD_AGENT_KEY and FLUXMAIL_CLOUD_ACCOUNT_ID.');
}
async function call(operation, args) {
const response = await fetch(
`https://cloud.fluxmail.ai/api/mail/${operation}`,
{
method: 'POST',
headers: {
Authorization: `Bearer ${token}`,
'Content-Type': 'application/json',
},
body: JSON.stringify(args),
}
);
const result = await response.json();
if (!response.ok) {
const code = result.error?.code ?? response.status;
const requestId = result.requestId ?? response.headers.get('x-request-id');
throw new Error(`${operation}: ${code}; request ${requestId}`);
}
return result.data;
}
await call('list_emails', { accountId, pageSize: 5, includeSnippet: false });
console.log('Fluxmail Cloud mailbox access verified.');The helper makes one request per call and leaves retries to your application. It parses every response as JSON, so read download_attachment responses with response.arrayBuffer() instead. It prints neither message contents nor the key.
Send status and duplicate protection
Every send requires an idempotencyKey. See sending and retries for message examples and the steps to take after a timeout. Never retry an uncertain send with a fresh key.
Errors and retries
Failures return an error with a code and message. Keep the requestId or x-request-id response header for troubleshooting. See errors and retries for status codes and limits for quotas and attachment sizes.
Cloud uses /api/mail/{operation} paths, separate from the self-hosted package's versioned API. Agent keys cannot manage mailbox connections or create keys; use the dashboard for those actions.
Last updated