Skip to content

Gmail API Search Queries

Comprehensive guide to Gmail search query syntax for filtering and finding emails.

Overview

Gmail search queries allow you to filter emails using powerful search operators. These queries can be used in the Fetch Mail (Gmail) field type to retrieve specific emails based on various criteria.

📬 Common Gmail Query Examples

QueryMeaning
is:unreadShows only unread emails
is:readShows only read emails
in:inboxEmails in Inbox
in:sentSent emails
in:trashEmails in Trash
in:spamSpam emails
has:attachmentEmails with attachments
larger:5mEmails larger than 5 MB
smaller:1mEmails smaller than 1 MB

📧 Sender / Receiver Filters

QueryMeaning
from:[email protected]Emails from specific sender
to:meEmails sent directly to you
cc:meEmails where you're in CC
bcc:meEmails where you're in BCC

🏷️ Label & Category Filters

QueryMeaning
label:inboxInbox label
label:unreadSame as is:unread
label:importantMarked important
category:primaryPrimary tab
category:socialSocial tab
category:promotionsPromotions tab
category:updatesUpdates tab
category:forumsForums tab

⏱️ Date / Time Filters

QueryMeaning
newer_than:1dEmails newer than 1 day
older_than:7dEmails older than 7 days
after:2025/01/01Emails after a specific date
before:2025/01/31Emails before a specific date

Time Units:

  • d - days
  • m - months
  • y - years

Examples:

newer_than:2d    (Last 2 days)
older_than:1m    (Older than 1 month)
newer_than:1y    (Last year)

🧵 Thread / Conversation Filters

QueryMeaning
is:unread is:importantUnread & important
is:unread in:inboxUnread in Inbox
is:unread from:[email protected]Unread OTP mails from sender
is:unread subject:"OTP"Unread mails with "OTP" in subject
Use CaseQuery
Latest unread OTPis:unread from:[email protected]
OTP in inbox onlyis:unread from:[email protected] in:inbox
OTP with keywordis:unread "verification code"

Advanced Query Combinations

Combining Multiple Conditions

Use AND logic by separating conditions with spaces:

is:unread from:[email protected] subject:verification

Use OR logic with curly braces:

from:{[email protected] [email protected]}
subject:{OTP verification code}

Negation (NOT)

Use - (minus) to exclude results:

-from:[email protected]          (Exclude sender)
-subject:newsletter             (Exclude subject)
-has:attachment                 (Exclude attachments)

Exact Phrase Matching

Use quotes for exact phrase matching:

subject:"Your verification code"
"password reset"

Practical Examples

Example 1: Fetch Verification Emails

is:unread from:[email protected] subject:"verification code"

Example 2: Recent Unread Emails with Attachments

is:unread has:attachment newer_than:1d

Example 3: Important Emails from Specific Sender

from:[email protected] is:important

Example 4: Emails in Date Range

after:2024/01/01 before:2024/12/31

Example 5: Large Attachments from Last Week

has:attachment larger:10m newer_than:7d

Example 6: Unread Promotional Emails

is:unread category:promotions

Example 7: Exclude Spam and Get Unread

is:unread -in:spam -in:trash

Best Practices

✅ Do's

  • Be specific - Use multiple filters to narrow down results
  • Use date filters - Limit search scope for better performance
  • Test queries - Verify queries in Gmail search before using in automation
  • Use exact phrases - Quote phrases for precise matching
  • Combine conditions - Use multiple operators for accurate results

❌ Don'ts

  • Don't use overly broad queries - Avoid fetching too many emails
  • Don't forget quotes - Use quotes for multi-word phrases
  • Don't ignore case sensitivity - Gmail search is case-insensitive, but be consistent
  • Don't overcomplicate - Keep queries simple and readable

Common Use Cases

1. Fetch OTP Codes

is:unread from:[email protected] subject:OTP

2. Monitor Order Confirmations

is:unread subject:"order confirmation" newer_than:1d

3. Get Password Reset Emails

is:unread subject:"reset password" newer_than:1h

4. Fetch Invoices

has:attachment subject:invoice from:[email protected]

5. Get Unread Important Emails

is:unread is:important in:inbox

Troubleshooting

No Results Found

Solution: Simplify your query and test each condition separately.

Too Many Results

Solution: Add more specific filters like date range or sender.

Query Not Working

Solution: Check for typos and ensure proper syntax (spaces, quotes, operators).

Special Characters Issues

Solution: Use quotes around phrases containing special characters.

Released under the MIT License.