Your count_emails tells you how many messages you have. But a count is just a number. When was the last time a count alone told you what to do?
After count_emails I know there are 12 messages. But I need the subject and sender of each one to know which are investor threads. That requires reading each message.
Each message in the count_emails response has an id field. GMAIL_FETCH_MESSAGE_BY_MESSAGE_ID takes that ID and returns the full message dict — subject, from address, body snippet, labels:
result = toolset.execute_action(
Action.GMAIL_FETCH_MESSAGE_BY_MESSAGE_ID,
{"message_id": msg_id}
)
print(result.get("subject", "no subject"))What does the full dict look like? How do I know which keys to use?
The dict has subject, from, snippet, labelIds, and id keys — all the fields you'd see in Gmail's API. .get("subject", "no subject") is your default. If the key is absent, you get a fallback instead of a crash. Here's the full function:
def get_email(msg_id: str) -> dict:
result = toolset.execute_action(
Action.GMAIL_FETCH_MESSAGE_BY_MESSAGE_ID,
{"message_id": msg_id}
)
print(f"Subject: {result.get('subject', 'no subject')}")
return resultSo I call count_emails, iterate the message IDs, call get_email on each — and I have a full inbox scan in a loop. That's my Monday Gmail audit automated.
Your Monday Gmail tab is now a Python loop. And it runs while you drink your coffee.
From counting to reading in one step. The pattern is the same — one action, one dict — just a different action and a different key.
Always test with a real message ID from your inbox before writing loops. A single get_email(real_id) confirms the key names before you process 40 messages.
Gmail messages are accessed in two steps:
GMAIL_FETCH_EMAILS → list of {"id": "..."} objectsGMAIL_FETCH_MESSAGE_BY_MESSAGE_ID → full message dict for one ID| Key | Value |
|---|---|
subject | Email subject line |
from | Sender address |
snippet | First 100 chars of body |
id | Message ID |
Message IDs are strings, not integers. Pass them as {"message_id": msg_id} exactly.
Your count_emails tells you how many messages you have. But a count is just a number. When was the last time a count alone told you what to do?
After count_emails I know there are 12 messages. But I need the subject and sender of each one to know which are investor threads. That requires reading each message.
Each message in the count_emails response has an id field. GMAIL_FETCH_MESSAGE_BY_MESSAGE_ID takes that ID and returns the full message dict — subject, from address, body snippet, labels:
result = toolset.execute_action(
Action.GMAIL_FETCH_MESSAGE_BY_MESSAGE_ID,
{"message_id": msg_id}
)
print(result.get("subject", "no subject"))What does the full dict look like? How do I know which keys to use?
The dict has subject, from, snippet, labelIds, and id keys — all the fields you'd see in Gmail's API. .get("subject", "no subject") is your default. If the key is absent, you get a fallback instead of a crash. Here's the full function:
def get_email(msg_id: str) -> dict:
result = toolset.execute_action(
Action.GMAIL_FETCH_MESSAGE_BY_MESSAGE_ID,
{"message_id": msg_id}
)
print(f"Subject: {result.get('subject', 'no subject')}")
return resultSo I call count_emails, iterate the message IDs, call get_email on each — and I have a full inbox scan in a loop. That's my Monday Gmail audit automated.
Your Monday Gmail tab is now a Python loop. And it runs while you drink your coffee.
From counting to reading in one step. The pattern is the same — one action, one dict — just a different action and a different key.
Always test with a real message ID from your inbox before writing loops. A single get_email(real_id) confirms the key names before you process 40 messages.
Gmail messages are accessed in two steps:
GMAIL_FETCH_EMAILS → list of {"id": "..."} objectsGMAIL_FETCH_MESSAGE_BY_MESSAGE_ID → full message dict for one ID| Key | Value |
|---|---|
subject | Email subject line |
from | Sender address |
snippet | First 100 chars of body |
id | Message ID |
Message IDs are strings, not integers. Pass them as {"message_id": msg_id} exactly.
Create a free account to get started. Paid plans unlock all tracks.