Send, search, and organize Gmail messages, drafts, and labels. Use when asked to compose an email, reply to mail, forward a message, search inbox, manage attachments, or organize Gmail.
94
Quality
94%
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Gmail's search syntax is powerful and allows you to find exactly what you need. This reference covers the search operators you can use with gmail.py messages list --query.
| Operator | Description | Example |
|---|---|---|
from: | Messages from specific sender | from:alice@example.com |
to: | Messages sent to recipient | to:bob@example.com |
cc: | Messages CC'd to recipient | cc:team@example.com |
bcc: | Messages BCC'd to recipient | bcc:boss@example.com |
Examples:
# All emails from Alice
python scripts/gmail.py messages list --query "from:alice@example.com"
# Emails I sent to Bob
python scripts/gmail.py messages list --query "to:bob@example.com"
# Emails where team was CC'd
python scripts/gmail.py messages list --query "cc:team@example.com"| Operator | Description | Example |
|---|---|---|
subject: | Subject contains text | subject:meeting |
| (no operator) | Body or subject contains | project alpha |
"exact phrase" | Exact phrase match | "quarterly review" |
Examples:
# Emails with "meeting" in subject
python scripts/gmail.py messages list --query "subject:meeting"
# Emails containing "project alpha" anywhere
python scripts/gmail.py messages list --query "project alpha"
# Exact phrase in subject or body
python scripts/gmail.py messages list --query '"quarterly review"'| Operator | Description |
|---|---|
is:unread | Unread messages |
is:read | Read messages |
Examples:
# All unread emails
python scripts/gmail.py messages list --query "is:unread"
# Read emails from last week
python scripts/gmail.py messages list --query "is:read newer_than:7d"| Operator | Description |
|---|---|
is:starred | Starred messages |
is:important | Important messages (Gmail priority) |
Examples:
# Starred emails
python scripts/gmail.py messages list --query "is:starred"
# Important unread emails
python scripts/gmail.py messages list --query "is:important is:unread"| Operator | Description | Example |
|---|---|---|
label: | Has specific label | label:work |
has:userlabels | Has any user label | has:userlabels |
has:nouserlabels | Has no user labels | has:nouserlabels |
Examples:
# Emails with "work" label
python scripts/gmail.py messages list --query "label:work"
# Emails with any custom label
python scripts/gmail.py messages list --query "has:userlabels"
# Emails without custom labels
python scripts/gmail.py messages list --query "has:nouserlabels"| Operator | Description |
|---|---|
category:primary | Primary inbox |
category:social | Social tab |
category:promotions | Promotions tab |
category:updates | Updates tab |
category:forums | Forums tab |
Examples:
# Unread emails in primary inbox
python scripts/gmail.py messages list --query "category:primary is:unread"
# Social emails from last day
python scripts/gmail.py messages list --query "category:social newer_than:1d"| Operator | Description | Example |
|---|---|---|
has:attachment | Has any attachment | has:attachment |
filename: | Attachment filename | filename:pdf |
filename: (exact) | Exact filename | filename:report.pdf |
Examples:
# Emails with attachments
python scripts/gmail.py messages list --query "has:attachment"
# Emails with PDF attachments
python scripts/gmail.py messages list --query "filename:pdf"
# Specific file
python scripts/gmail.py messages list --query "filename:report.pdf"
# Attachments from specific sender
python scripts/gmail.py messages list --query "from:alice@example.com has:attachment"| Operator | Description | Example |
|---|---|---|
newer_than: | Newer than time period | newer_than:7d |
older_than: | Older than time period | older_than:30d |
Time units:
d = days (e.g., 7d = 7 days)m = months (e.g., 2m = 2 months)y = years (e.g., 1y = 1 year)Examples:
# Emails from last 7 days
python scripts/gmail.py messages list --query "newer_than:7d"
# Emails older than 30 days
python scripts/gmail.py messages list --query "older_than:30d"
# Last 2 months from specific sender
python scripts/gmail.py messages list --query "from:boss@example.com newer_than:2m"| Operator | Description | Example |
|---|---|---|
after: | After specific date | after:2024/01/01 |
before: | Before specific date | before:2024/12/31 |
Date formats:
YYYY/MM/DD (e.g., 2024/01/15)YYYY-MM-DD (e.g., 2024-01-15)Examples:
# Emails after January 1, 2024
python scripts/gmail.py messages list --query "after:2024/01/01"
# Emails before end of year
python scripts/gmail.py messages list --query "before:2024/12/31"
# Emails in specific date range
python scripts/gmail.py messages list --query "after:2024/01/01 before:2024/01/31"| Operator | Description |
|---|---|
newer_than:1d | Last 24 hours |
newer_than:7d | Last week |
newer_than:1m | Last month |
older_than:1y | Older than 1 year |
| Operator | Description | Example |
|---|---|---|
size: | Exact size in bytes | size:1000000 |
larger: | Larger than size | larger:10M |
smaller: | Smaller than size | smaller:1M |
Size units:
K = kilobytesM = megabytesExamples:
# Emails larger than 10 MB
python scripts/gmail.py messages list --query "larger:10M"
# Small emails (less than 100 KB)
python scripts/gmail.py messages list --query "smaller:100K"
# Large attachments from last week
python scripts/gmail.py messages list --query "has:attachment larger:5M newer_than:7d"| Operator | Description |
|---|---|
is:chat | Chat messages |
is:snoozed | Snoozed messages |
list: | Messages from mailing list |
Examples:
# Chat messages
python scripts/gmail.py messages list --query "is:chat"
# Snoozed messages
python scripts/gmail.py messages list --query "is:snoozed"
# Messages from specific mailing list
python scripts/gmail.py messages list --query "list:dev-team@example.com"| Operator | Description |
|---|---|
in:trash | In trash |
in:spam | In spam |
in:inbox | In inbox |
in:sent | In sent mail |
in:drafts | In drafts |
in:anywhere | Anywhere (including trash/spam) |
Examples:
# Trash items
python scripts/gmail.py messages list --query "in:trash"
# Sent emails to specific person
python scripts/gmail.py messages list --query "in:sent to:alice@example.com"
# Search everywhere including trash
python scripts/gmail.py messages list --query "in:anywhere subject:important"| Operator | Description | Example |
|---|---|---|
AND (implicit) | Both conditions | from:alice subject:meeting |
OR | Either condition | from:alice OR from:bob |
NOT or - | Exclude condition | -from:spam@example.com |
( ) | Grouping | (from:alice OR from:bob) subject:meeting |
Examples:
# From Alice AND about meetings (implicit AND)
python scripts/gmail.py messages list --query "from:alice@example.com subject:meeting"
# From Alice OR Bob
python scripts/gmail.py messages list --query "from:alice@example.com OR from:bob@example.com"
# NOT from spam sender
python scripts/gmail.py messages list --query "-from:spam@example.com"
# Complex: (Alice OR Bob) AND meeting AND unread
python scripts/gmail.py messages list --query "(from:alice@example.com OR from:bob@example.com) subject:meeting is:unread"# Unread emails NOT from Alice
python scripts/gmail.py messages list --query "is:unread -from:alice@example.com"
# Emails without attachments
python scripts/gmail.py messages list --query "-has:attachment"
# Not labeled
python scripts/gmail.py messages list --query "-has:userlabels"
# Not in trash or spam
python scripts/gmail.py messages list --query "-in:trash -in:spam"# Today's unread emails
python scripts/gmail.py messages list --query "is:unread newer_than:1d"
# Important unread from last 3 days
python scripts/gmail.py messages list --query "is:important is:unread newer_than:3d" --max-results 20
# Starred emails I haven't read
python scripts/gmail.py messages list --query "is:starred is:unread"# All project-related emails
python scripts/gmail.py messages list --query "subject:project-alpha"
# Project emails with attachments
python scripts/gmail.py messages list --query "subject:project-alpha has:attachment"
# Team emails from last sprint (2 weeks)
python scripts/gmail.py messages list --query "from:team@example.com newer_than:14d"
# Unread project emails
python scripts/gmail.py messages list --query "label:project-alpha is:unread"# Invoice emails
python scripts/gmail.py messages list --query "subject:invoice has:attachment"
# Password reset emails
python scripts/gmail.py messages list --query "subject:password subject:reset"
# Meeting invites from this month
python scripts/gmail.py messages list --query "subject:meeting subject:invite newer_than:1m"
# Receipts with PDFs
python scripts/gmail.py messages list --query "subject:receipt filename:pdf"# Large old emails
python scripts/gmail.py messages list --query "larger:10M older_than:1y"
# Old read emails
python scripts/gmail.py messages list --query "is:read older_than:6m"
# Promotional emails
python scripts/gmail.py messages list --query "category:promotions older_than:30d"
# Social emails older than 3 months
python scripts/gmail.py messages list --query "category:social older_than:3m"# All emails from domain
python scripts/gmail.py messages list --query "from:@example.com"
# Emails TO a specific domain
python scripts/gmail.py messages list --query "to:@clients.com"
# Emails from boss with attachments
python scripts/gmail.py messages list --query "from:boss@example.com has:attachment"
# Team emails I sent
python scripts/gmail.py messages list --query "to:team@example.com in:sent"# Q1 2024 emails
python scripts/gmail.py messages list --query "after:2024/01/01 before:2024/04/01"
# Last year's December
python scripts/gmail.py messages list --query "after:2023/12/01 before:2024/01/01"
# Specific week
python scripts/gmail.py messages list --query "after:2024/01/15 before:2024/01/22"# Unread, important, with attachments from this week
python scripts/gmail.py messages list \
--query "is:unread is:important has:attachment newer_than:7d"
# Large PDFs from specific sender in last month
python scripts/gmail.py messages list \
--query "from:reports@example.com filename:pdf larger:5M newer_than:1m"
# Meeting invites not yet read
python scripts/gmail.py messages list \
--query "subject:meeting subject:invite is:unread"# Inbox emails excluding newsletters
python scripts/gmail.py messages list \
--query "in:inbox -category:promotions -category:social -category:updates"
# Emails from domain EXCEPT automated@
python scripts/gmail.py messages list \
--query "from:@example.com -from:automated@example.com"
# Important emails without certain labels
python scripts/gmail.py messages list \
--query "is:important -label:archived -label:reviewed"from: is faster than searching body text--max-results to avoid fetching too many"quarterly review"python scripts/gmail.py messages list --query "from:alice subject:meeting"YYYY/MM/DD not MM/DD/YYYY7d not 7days, 2m not 2monthsfrom:alice subject:meeting (implicit AND) not from:alice AND subject:meetingBefore using in automation:
--max-results 5 to spot-checkInstall with Tessl CLI
npx tessl i odyssey4me/gmail