Skip to content

Gmail — Get emails

Type: gmail-get-emails  ·  Package: Gmail v1.0.4  ·  Output: List<Dictionary<string,object>>

Searches the mailbox using Gmail’s search syntax and returns the list of matching messages. It is usually the activity a process starts with: find the emails to process, then loop over them.

It works on the session created with Gmail — Connect. Pass it in the session parameter, or place this activity inside the body of Gmail — Connect to inherit it automatically.

  • query accepts the same syntax as Gmail’s search box: is:unread, from:, to:, subject:, has:attachment, filename:pdf, label:, in:inbox, after:2026/10/01, before:, newer_than:7d, older_than:1y… Empty = all mail.
  • labelIds restricts to emails that have all the given labels, by ID (INBOX, UNREAD, STARRED, Label_123…). To use label names, put them in the query (label:Suppliers) or look up the IDs with Get labels.
  • As in Gmail, Trash and Spam are not included unless you ask for them in the query (in:trash, in:spam, in:anywhere).
  • Results come in Gmail’s order: newest first.

The activity runs a single query, and Gmail returns at most 500 emails per query; it does not request further pages. For large volumes, work in batches: label, archive or mark as read what you processed and query again. Each email is fetched with its own request, so a high maxResults and includeBody make the activity slower.

None.

ParameterTypeDefaultDescription
sessionZoanGmailSession—Gmail — Connect session (inherited inside body).
querystring—Gmail search (same syntax as the mailbox search box). Empty = all mail. E.g.: is:unread from:supplier@example.com.
maxResultsint25Maximum number of emails to return (Gmail accepts up to 500). An empty, non-numeric or less-than-1 value uses 25.
includeBodyboolfalseIf true, includes each email’s body and attachment info (body, bodyHtml, attachments keys).
labelIdsstring | List—Label ID(s) the emails must have (e.g. INBOX, UNREAD). Text separated by commas or semicolons, or a list.

Returns a List<Dictionary<string,object>>: a list where each item is an email with these keys.

KeyTypeContent
idstringMessage ID. It is the input of the other activities and does not change when you label or archive.
threadIdstringID of the conversation it belongs to.
fromstringFrom header as is, with name and address: Ana Perez <ana@example.com>. The bare address is what’s between < and >.
tostringTo header as is (several addresses separated by commas).
ccstringCc header as is, or null if none.
subjectstringSubject.
datestringDate header as is, in email format (Wed, 15 Oct 2026 09:03:22 -0500).
snippetstringExcerpt from the beginning of the message, as plain text.
labelsList<string>IDs of the email’s labels (INBOX, UNREAD, IMPORTANT, Label_…).
unreadbooltrue if the email is unread.
bodystringOnly with includeBody. Plain-text body; if the email only has HTML, that HTML with the tags stripped; "" if there is no body.
bodyHtmlstringOnly with includeBody. HTML body, or null if the email has none.
attachmentsList<Dictionary>Only with includeBody. One item per attachment with filename, mimeType, size (bytes) and attachmentId.

Without includeBody, the body, bodyHtml and attachments keys do not exist in the dictionary. If nothing matches, it returns an empty list (it does not fail).

MessageCause and fix
No Gmail session available. …You didn’t pass session and the activity is not inside Connect’s body.
Gmail 400 error, or an empty list when you expected emailslabelIds contains label names instead of IDs. Use the IDs from Get labels, or label:Name in query.
Request had insufficient authentication scopes.The connection lacks Gmail read permission. Check its scopes in Zoan Cloud.
Gmail — Connect credential = credential("gmail-support")
└─ body:
Gmail — Get emails query = "is:unread has:attachment subject:invoice" maxResults = 50 → output: pending
For each email in pending
└─ Gmail — Download attachments id = email["id"] folder = "C:\invoices\inbox" → output: files
Log message = str(email["subject"]) + ": " + count(files) + " attachment(s)"
Gmail — Mark read/unread id = email["id"]