Read and search Gmail, send, reply and forward, schedule and track sends, work with drafts, labels, send-as aliases and signatures, and catch bounces.
Every call takes the accountId of a Google account connected with scopes=email. Ids are Gmail's own message, thread and label ids, and every object carries provider and accountId.
Before you start
Sending from Gmail needs a payment method on your Zernio workspace. Without one, sends and replies answer 402 payment_required. Reading, labelling and trashing never need one.
List and search threads
GET /v1/email/threads returns threads newest first, from the inbox unless you pass folder:
curl "https://zernio.com/api/v1/email/threads?accountId=ACCOUNT_ID&folder=inbox&unread=true&limit=20" \
-H "Authorization: Bearer $ZERNIO_API_KEY"{
"data": [
{
"id": "18f2c0a9d3b1e7f4",
"accountId": "ACCOUNT_ID",
"provider": "google",
"subject": "Contract for Q4",
"snippet": "Hi Ana, attached is the signed version…",
"unread": true,
"latestMessageReceivedAt": "2026-10-26T09:12:00.000Z"
}
],
"pagination": { "hasMore": true, "nextCursor": "…" },
"meta": { "filteredClientSide": [] }
}GET /v1/email/messages takes the same filters and returns single messages. Both page with cursor and limit (up to 200, default 50).
Filter and search
| Parameter | What it does |
|---|---|
folder | inbox, sent, drafts, trash, spam, archive, or a label id from GET /v1/email/folders |
unread, starred, hasAttachment | true or false |
from, to, cc, bcc, anyEmail | An address. anyEmail matches any participant |
subject | Words in the subject |
after, before | ISO 8601 bounds on the message date |
searchQueryNative | A Gmail search query passed as it is, such as has:attachment larger:5M (up to 500 characters) |
sortOrder | desc (default) or asc |
On Gmail, folders are labels and archive means mail that carries none of the inbox, trash or spam labels. Gmail lists newest first only, so sortOrder=asc reverses each fetched page.
A filter Gmail cannot apply itself is applied to the fetched page and named in meta.filteredClientSide. Such a page can hold fewer than limit items while pagination.hasMore stays true.
Read a thread or message
GET /v1/email/threads/{threadId}?accountId=… returns the thread with its messages. GET /v1/email/messages/{messageId}?accountId=… returns one message with text, html and attachments. Add includeHeaders=true for the headers, or raw=true for the full MIME source.
Add clean=true to either call for a clean object on each message, ready to hand to an LLM:
"clean": {
"text": "Sounds good, Thursday at 3 works.\n\nAna Ruiz\nHead of Ops, Acme",
"status": "stripped",
"removed": { "quoted": true, "forwardHeader": false, "boilerplate": true },
"signature": "Ana Ruiz\nHead of Ops, Acme",
"forwarded": null
}text drops quoted replies, tracking pixels and footers such as "Sent from my iPhone", in the common languages. The signature stays in text and also comes alone in signature.
A forward keeps the forwarded content, and its From, To, Date and Subject come parsed in forwarded.
text is never empty for a mail with a body: when nothing can be stripped safely you get the whole body with status: "fallback". The rules are deterministic; no model reads the mail.
Send an email
POST /v1/email/messages sends from the connected mailbox and returns the sent copy with 201:
curl -X POST "https://zernio.com/api/v1/email/messages" \
-H "Authorization: Bearer $ZERNIO_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"accountId": "ACCOUNT_ID",
"to": [{ "email": "client@example.com", "name": "Client" }],
"subject": "Your booking",
"html": "<p>See you on Tuesday.</p>",
"attachments": [{ "filename": "invoice.pdf", "contentType": "application/pdf", "url": "https://example.com/invoice.pdf" }],
"metadata": { "bookingId": "bk_123" }
}'| Field | What it does |
|---|---|
to, cc, bcc | Up to 100 addresses each, as { email, name? }. to needs at least one |
replyTo | Up to 5 addresses |
fromName | The display name. The address is always the mailbox |
subject | Up to 998 characters |
text, html | At least one |
attachments | Up to 20, each { filename, contentType, url } or { filename, contentType, base64 }. Add contentId to reference an inline image from html |
replyToMessageId | Threads the email under that message |
headers | Custom headers. Only names starting with X- are accepted |
metadata | String pairs echoed on the returned message |
Schedule a send
Add scheduledFor to a send or a reply, as ISO 8601 between 1 minute and 30 days ahead. Zernio answers 202 with the scheduled send and sends it within a minute of that time:
curl -X POST "https://zernio.com/api/v1/email/messages" \
-H "Authorization: Bearer $ZERNIO_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"accountId": "ACCOUNT_ID",
"to": [{ "email": "client@example.com" }],
"subject": "Following up",
"html": "<p>Any questions about the proposal?</p>",
"scheduledFor": "2026-11-12T09:00:00Z"
}'{ "data": { "id": "SCHEDULE_ID", "status": "scheduled", "scheduledFor": "2026-11-12T09:00:00.000Z", "to": [{ "email": "client@example.com" }], "subject": "Following up" } }GET /v1/email/messages/scheduled?accountId=…lists scheduled sends in send order. Filter withstatus:scheduled,sending,sent,failedorcancelled.GET /v1/email/messages/scheduled/{scheduleId}?accountId=…reads one. Once sent it carriessentMessageIdandsentThreadId.DELETE /v1/email/messages/scheduled/{scheduleId}?accountId=…cancels one that has not left yet. Later it answers409.
The account and its areas are checked when you schedule. The daily cap and cooldowns apply when the email leaves.
If it cannot leave then, it moves to failed with an error and Zernio fires email.send_failed. Nothing is retried, so schedule it again once the cause is fixed.
Hold it as a draft in the mailbox
Add "holdAsDraft": true next to scheduledFor to save the email as a draft in Gmail right away. The user can read and edit it there, and Zernio sends the draft as it stands at scheduledFor.
The scheduled send then carries holdAsDraft: true and draftId, the Gmail draft id. Cancelling it deletes the draft.
If the draft is deleted or sent from the mailbox first, the send moves to failed and Zernio fires email.send_failed. holdAsDraft without scheduledFor answers 400.
Track opens, clicks and replies
Add any of these to a send or a reply:
| Field | What it does | Webhook |
|---|---|---|
trackOpens | Adds a 1x1 image to the html | email.opened |
trackLinks | Sends every http(s) link in the html through a Zernio redirect to the original URL | email.link_clicked |
trackReplies | Watches the Gmail thread for mail from anyone other than the mailbox | email.thread_replied |
The sent message carries a trackingId, and every tracking webhook carries it with the message's messageId, threadId and your metadata. trackOpens and trackLinks need html. trackReplies works with text too. Tracking is free.
Opens are a signal, not proof of reading:
- Image proxies such as Gmail's and Apple Mail's fetch the pixel themselves, some as soon as the mail arrives.
- Clients that block images never report an open.
- Opening the message in the mailbox's own Sent folder counts.
Mail security gateways sometimes follow links on delivery, which reports a click. Auto-replies count as replies. A bounce does not: it fires email.bounced.
Reply to a message
POST /v1/email/messages/{messageId}/reply replies inside the Gmail thread, with the threading headers set for you. It goes to the original sender, or with mode: "replyAll" to every recipient too:
curl -X POST "https://zernio.com/api/v1/email/messages/MESSAGE_ID/reply" \
-H "Authorization: Bearer $ZERNIO_API_KEY" \
-H "Content-Type: application/json" \
-d '{ "accountId": "ACCOUNT_ID", "mode": "replyAll", "text": "Thanks, confirmed." }'to and subject are optional on a reply and default to the original's. Replies count against the same daily cap as sends.
Forward a message
POST /v1/email/messages/{messageId}/forward forwards the mail with its attachments. Your text or html goes above it, and the subject defaults to Fwd: plus the original's:
curl -X POST "https://zernio.com/api/v1/email/messages/MESSAGE_ID/forward" \
-H "Authorization: Bearer $ZERNIO_API_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: 3f1c9a2e-forward-1" \
-d '{ "accountId": "ACCOUNT_ID", "to": [{ "email": "sales@acme.com" }], "text": "Can you take this one?", "excludeAttachmentIds": ["ATTACHMENT_ID"] }'The forward stays in the original Gmail thread. Tracking, from and the send caps work as on a send, and the response carries forwardedFrom.
includeAttachments: false keeps only the original's inline images. excludeAttachmentIds leaves out the attachments you name, by the ids a read of the message returned. Everything together stays under 25 MB, else 413 attachment_too_large.
Work with drafts
Drafts suit an agent that writes and a person who approves. POST /v1/email/drafts saves a draft in the mailbox, where the user sees it in Gmail. Recipients and subject can wait.
inReplyTo makes a reply draft in that thread, and forwardOf a forward draft with the original's attachments:
curl -X POST "https://zernio.com/api/v1/email/drafts" \
-H "Authorization: Bearer $ZERNIO_API_KEY" \
-H "Content-Type: application/json" \
-d '{ "accountId": "ACCOUNT_ID", "inReplyTo": "MESSAGE_ID", "html": "<p>Proposed answer</p>" }'The draft comes back with its id, a kind (new, reply or forward, fixed for its life) and a version. Store the id; messageId changes on every save.
| Call | What it does |
|---|---|
GET /v1/email/drafts | Lists the mailbox's drafts, the user's own included |
GET /v1/email/drafts/{draftId} | Reads a draft as it stands now |
PATCH /v1/email/drafts/{draftId} | Changes the fields you send and keeps the rest |
DELETE /v1/email/drafts/{draftId} | Deletes it |
POST /v1/email/drafts/{draftId}/send | Sends it, with any edits the user made in Gmail |
Approve exactly one version
The version changes whenever anyone edits the draft, the user in Gmail included. Pass it as If-Match on PATCH or send.
If the draft changed since, you get 412 draft_conflict with the current draft in details.draft, so you can review what the person wrote:
curl -X POST "https://zernio.com/api/v1/email/drafts/DRAFT_ID/send" \
-H "Authorization: Bearer $ZERNIO_API_KEY" \
-H "Content-Type: application/json" \
-H "If-Match: \"VERSION\"" \
-d '{ "accountId": "ACCOUNT_ID" }'The sent message carries draftId, and email.sent fires with source: "draft". A second send while one is in flight answers 409 draft_sending, and a draft the user deleted or sent answers 404 draft_not_found.
Add sendAt to send later instead: you get 202 with a scheduled send, and the draft stays editable until then. Cancelling it keeps the draft.
Tracking set at creation applies. If an edit removed the open pixel or tracked links, Zernio puts them back before sending.
Detect bounces
When a recipient's server refuses a mail, the bounce report lands in the mailbox and Zernio fires email.bounced, once per failed recipient. Delay warnings and out-of-office replies do not fire it.
Act on bounce.recommendedAction:
recommendedAction | When | What to do |
|---|---|---|
remove | user_unknown, domain_not_found | Stop sending to this address |
retry | mailbox_full, rate_limited, any soft bounce | Try again later |
fix_configuration | auth_failure, blocklisted | Fix SPF, DKIM, DMARC or your sending reputation |
review | spam_blocked, policy_blocked, message_too_large, content_rejected, other | Look at the content or the recipient's policy |
The event also carries type (hard, soft or undetermined), the status such as 5.1.1, a numeric smtpCode, the server's diagnostic, and detection.
Bounces arrive minutes to days after the send; bouncedAt and detectedAt show both times. When the send had tracking, email.messageId, trackingId and metadata are set. Otherwise match on threadId, internetMessageId or the quoted subject.
Send from an alias with a signature
GET /v1/email/send-as?accountId=… lists the addresses the mailbox can send from: its own address and every Gmail send-as alias, each with verificationStatus and the signature it would get.
Pass one as from on a send, reply or scheduled send. Add appendSignature: true to append that address's signature to html and text:
curl -X POST "https://zernio.com/api/v1/email/messages" \
-H "Authorization: Bearer $ZERNIO_API_KEY" \
-H "Content-Type: application/json" \
-d '{ "accountId": "ACCOUNT_ID", "from": "support@acme.com", "appendSignature": true, "to": [{ "email": "ada@example.com" }], "subject": "Your order", "html": "<p>It shipped today.</p>" }'A from outside the list, or an alias Gmail has not verified, answers 400. Without from, appendSignature uses the mailbox address's own signature.
Manage signatures in Zernio
appendSignature takes the Zernio signature set as the default for the sending address first, then the Gmail one. It answers 400 when there is neither.
Store a signature once and make it the default for an address:
curl -X POST "https://zernio.com/api/v1/email/signatures" \
-H "Authorization: Bearer $ZERNIO_API_KEY" \
-H "Content-Type: application/json" \
-d '{ "name": "Sales", "html": "<b>Ada Lovelace</b><br>Acme Sales", "defaultFor": ["sales@acme.com"] }'Omit accountId to share it across every mailbox in the workspace. Pass signatureId on a send or reply to pick one explicitly.
POST /v1/email/signatures/import?accountId=… copies the Gmail signatures in, each the default for its address. The signature lands in a marked block above any quoted text.
To switch the signature on a draft, PATCH it with the new html or text and signatureId. The old signature block is replaced, never stacked; signatureId: null removes it.
Label a message
Create the label once. Nested names like Hermia/Handled show as a label group in Gmail. Creating a name that already exists returns it with 200, so the call is safe to repeat:
curl -X POST "https://zernio.com/api/v1/email/labels" \
-H "Authorization: Bearer $ZERNIO_API_KEY" \
-H "Content-Type: application/json" \
-d '{ "accountId": "ACCOUNT_ID", "name": "Hermia/Handled" }'Then add or remove it with addLabels and removeLabels, by label id or name. The message stays in the inbox:
curl -X PATCH "https://zernio.com/api/v1/email/messages/MESSAGE_ID" \
-H "Authorization: Bearer $ZERNIO_API_KEY" \
-H "Content-Type: application/json" \
-d '{ "accountId": "ACCOUNT_ID", "addLabels": ["Hermia/Handled"], "removeLabels": ["Hermia/For you"] }'PATCH /v1/email/threads/{threadId} labels every message in the thread. Each message lists its user label ids in labels. GET /v1/email/labels lists label ids and names, and DELETE /v1/email/labels/{labelId} deletes a label.
Archive or trash
The same PATCH endpoints take unread, starred and folder. Setting folder moves the mail and drops the user labels it had, so "folder": "archive" archives it. DELETE /v1/email/messages/{messageId}?accountId=… moves a message to the trash.
Download an attachment
Attachment ids come in each message's attachments. GET /v1/email/attachments/{attachmentId}?accountId=…&messageId=… streams the file with its Content-Type and filename.
How it behaves
- Daily send cap. 200 sends a day on a consumer Gmail account and 500 on Google Workspace, counted per mailbox and reset at midnight UTC. Every send answers with
X-Zernio-Send-Limit,X-Zernio-Send-RemainingandX-Zernio-Send-Reset.GET /v1/accounts/{accountId}/healthreports the same assendCap. - Bulk protection. The same body sent to more than 50 distinct recipients within an hour pauses the mailbox: 10 minutes the first time, doubling up to 24 hours, and Zernio fires
account.rate_limited. The mailbox is for one-to-one mail, not newsletters. - Attachments. Up to 25 MB in total per email. Attachments given by
urlmust download within 20 seconds. - Inbox. Mail received while the account is connected, and mail sent through the API, appears as inbox conversations, one per Gmail thread, and fires
message.receivedormessage.sent. Older mail is reachable through these endpoints, not the inbox. - Reads. Reads are live calls to Gmail, are not metered, and count against your API rate limit. When Gmail throttles the mailbox, Zernio retries once, then answers
429rate_limited.
If it fails
| Error | Cause | Fix |
|---|---|---|
402 payment_required | No payment method on the workspace (Gmail sends only) | Add a card in billing, then send again. |
429 email_send_cap_reached | The mailbox reached today's cap. details.cap has limit, used and resetsAt | Wait for Retry-After or resetsAt. |
429 rate_limited | The mailbox is in a cooldown after a recipient burst, or Gmail throttled it | Wait for Retry-After, and send fewer identical emails. |
404 resource_not_found | addLabels or removeLabels names a label the mailbox does not have | Create it with POST /v1/email/labels first. |
400 invalid_field_value | A field is invalid: a non X- header, attachments over 25 MB, scheduledFor outside 1 minute to 30 days, tracking without html | Fix the field named in param. |
400 from_not_allowed | The address is not a send-as alias of the mailbox, or Gmail has not verified it | Use an address from GET /v1/email/send-as with verificationStatus: "accepted". |
400 signature_unavailable | The sending address has neither a Zernio default nor a Gmail signature | Create one with defaultFor, or pass signatureId. |
412 account_scope_missing | The account has no email area | Connect again with email in scopes. |
401 reconnect_required | Google refused the account's access | Reconnect the account. |
Related
Organization connection
Let a Google Workspace admin grant Zernio access to the domain's mailboxes once, then add mailboxes through the API without each user signing in.
Calendar
List Google calendars and events, create and update events with Google Meet links, RSVP to invitations, and find free time across mailboxes.