get_email from yesterday fetches one message by ID. But you don't always know the ID — sometimes you want all unread emails from your advisor. How do you search Gmail programmatically?
GMAIL_FETCH_EMAILS already retrieves messages. Does it accept a query the same way the Gmail search bar does?
Exactly the same syntax. GMAIL_FETCH_EMAILS accepts a query parameter — "from:advisor@university.edu", "is:unread", "subject:thesis". Same query strings you'd type in the Gmail search bar, now as a Python argument:
result = toolset.execute_action(
Action.GMAIL_FETCH_EMAILS,
{"query": "from:advisor@university.edu is:unread", "max_results": 10}
)
messages = result.get("messages", [])
print(f"Found {len(messages)} unread advisor emails")Wait — count_emails used GMAIL_FETCH_EMAILS with max_results. search_emails uses the same action but adds a query param? So the action is the same, just the params dict changes?
Exactly the insight. The action is the verb; the params dict is the instruction. GMAIL_FETCH_EMAILS with no query returns everything. Add query and it filters. That's why learning one action unlocks many use cases:
def search_emails(query: str) -> list:
result = toolset.execute_action(
Action.GMAIL_FETCH_EMAILS,
{"query": query, "max_results": 20}
)
messages = result.get("messages", [])
print(f"Found {len(messages)} emails matching '{query}'")
return messagessearch_emails("from:advisor@university.edu is:unread") — that's my entire Monday advisor check in one call.
Your Monday routine just became a string argument.
I compared the filtered count with count_emails total in the print statement — that shows how many of my inbox messages are from my advisor.
Gmail's query syntax is powerful but case-sensitive for operators. FROM: won't work — use lowercase from:. Invalid queries return an empty messages list, not an error — always verify your query against a manual Gmail search first.
Pass a query string to GMAIL_FETCH_EMAILS — same syntax as the Gmail search bar:
| Query | Meaning |
|---|---|
from:advisor@uni.edu | From a specific sender |
is:unread | Unread only |
subject:thesis | Subject contains "thesis" |
from:X is:unread | Combine with spaces |
Composio actions are flexible. The same GMAIL_FETCH_EMAILS action works for counting, listing, and filtering — just change what you put in the params dict.
get_email from yesterday fetches one message by ID. But you don't always know the ID — sometimes you want all unread emails from your advisor. How do you search Gmail programmatically?
GMAIL_FETCH_EMAILS already retrieves messages. Does it accept a query the same way the Gmail search bar does?
Exactly the same syntax. GMAIL_FETCH_EMAILS accepts a query parameter — "from:advisor@university.edu", "is:unread", "subject:thesis". Same query strings you'd type in the Gmail search bar, now as a Python argument:
result = toolset.execute_action(
Action.GMAIL_FETCH_EMAILS,
{"query": "from:advisor@university.edu is:unread", "max_results": 10}
)
messages = result.get("messages", [])
print(f"Found {len(messages)} unread advisor emails")Wait — count_emails used GMAIL_FETCH_EMAILS with max_results. search_emails uses the same action but adds a query param? So the action is the same, just the params dict changes?
Exactly the insight. The action is the verb; the params dict is the instruction. GMAIL_FETCH_EMAILS with no query returns everything. Add query and it filters. That's why learning one action unlocks many use cases:
def search_emails(query: str) -> list:
result = toolset.execute_action(
Action.GMAIL_FETCH_EMAILS,
{"query": query, "max_results": 20}
)
messages = result.get("messages", [])
print(f"Found {len(messages)} emails matching '{query}'")
return messagessearch_emails("from:advisor@university.edu is:unread") — that's my entire Monday advisor check in one call.
Your Monday routine just became a string argument.
I compared the filtered count with count_emails total in the print statement — that shows how many of my inbox messages are from my advisor.
Gmail's query syntax is powerful but case-sensitive for operators. FROM: won't work — use lowercase from:. Invalid queries return an empty messages list, not an error — always verify your query against a manual Gmail search first.
Pass a query string to GMAIL_FETCH_EMAILS — same syntax as the Gmail search bar:
| Query | Meaning |
|---|---|
from:advisor@uni.edu | From a specific sender |
is:unread | Unread only |
subject:thesis | Subject contains "thesis" |
from:X is:unread | Combine with spaces |
Composio actions are flexible. The same GMAIL_FETCH_EMAILS action works for counting, listing, and filtering — just change what you put in the params dict.
Create a free account to get started. Paid plans unlock all tracks.