Skip to content

Gmail API Search Queries

Comprehensive reference guide to Gmail search operators and syntax for filtering messages in automated workflows.


Overview

Gmail queries allow you to isolate exact messages based on sender, subject, date, read status, and attachment attributes. These query expressions are configured in the Search Query parameter of Fetch Mail (Gmail) and Fetch Single Mail (Gmail).


Common Gmail Query Operators

QueryFunctionExample
is:unreadMatches only unread messages.is:unread from:[email protected]
is:readMatches read messages.is:read subject:statement
in:inboxScopes search to the Inbox.in:inbox is:unread
in:sentScopes search to Sent mail.in:sent to:[email protected]
in:trashSearches deleted items in Trash.in:trash
in:spamSearches messages in Spam.in:spam
has:attachmentMatches messages containing files.has:attachment filename:pdf
larger:5mMessages with total size over 5 megabytes.larger:5m
smaller:1mMessages with total size under 1 megabyte.smaller:1m

Sender & Recipient Filters

OperatorSyntaxDescription
from:from:[email protected]Matches emails from a specific sender address or domain.
to:to:[email protected]Matches emails sent directly to the specified recipient.
cc:cc:[email protected]Matches emails where the address is CC'd.
bcc:bcc:[email protected]Matches emails where the address is BCC'd.

Label & Category Filters

OperatorTargetDescription
label:label:important, label:financeScopes query to a specific system or user label.
category:primaryPrimary Inbox tabFilters emails categorized as Primary by Gmail.
category:socialSocial tabNotifications from social networks.
category:promotionsPromotions tabMarketing and commercial emails.
category:updatesUpdates tabReceipts, statements, and bills.
category:forumsForums tabDiscussion boards and mailing lists.

Date & Time Filters

OperatorFormatDescription
newer_than:newer_than:1d, newer_than:2hMatches emails received within the last relative time window (d = days, h = hours, m = months).
older_than:older_than:7dMatches emails older than the specified relative duration.
after:after:2025/01/01Absolute date lower bound (YYYY/MM/DD).
before:before:2025/12/31Absolute date upper bound (YYYY/MM/DD).

Attachment Filters

OperatorSyntaxDescription
has:attachmenthas:attachmentRequires at least one attachment present.
filename:filename:pdf, filename:invoice.pdfMatches specific file extensions or file names.

OperatorSyntaxDescription
subject:subject:"Verification Code"Matches exact subject line text when quoted.
Exact phrase"account created"Matches the exact phrase anywhere in subject or body.
Negation-from:spam.comExcludes matching messages using the - prefix.

Combining Operators

Multiple operators can be chained with spaces (equivalent to logical AND) or grouped with OR:

Compound AND

text
from:[email protected] is:unread newer_than:1h

Matches unread messages from [email protected] received within the last hour.

Compound OR

text
from:([email protected] OR [email protected]) subject:OTP

Matches messages from either sender containing "OTP" in the subject.


Automation Best Practices

  1. Always Use newer_than for OTPs: Add newer_than:1h or newer_than:1d to ensure past authentication emails are not returned.
  2. Combine is:unread with Read Flagging: Use is:unread alongside the Remove UNREAD Label setting in the field configuration to guarantee one-time processing.
  3. Quote Multi-Word Phrases: Wrap phrases in double quotes (subject:"Your Security Code").