Email Metadata Queries

Content: Email Metadata Queries

User Intent

"How do I query emails by sender, subject, labels, etc.?"

Operation

  • SDK Method: queryContents() with email-specific patterns

  • GraphQL: queryContents query

  • Entity Type: Content (type: EMAIL)

  • Common Use Cases: Find emails by sender, filter by labels, search by subject, date range queries

Email Metadata Structure

Emails have rich metadata captured in the email field:

interface EmailMetadata {
  identifier: string;              // Message-ID
  threadIdentifier: string;        // Thread ID
  subject: string;
  from: PersonReference[];
  to: PersonReference[];
  cc: PersonReference[];
  bcc: PersonReference[];
  labels: string[];                // Gmail labels
  sensitivity: MailSensitivity;
  priority: MailPriority;
  importance: MailImportance;
  attachmentCount: number;
  unsubscribeUrl: string;
  publicationName: string;
  publicationUrl: string;
}

TypeScript (Canonical)

Query Patterns

1. Find by Sender

2. Find by Subject

3. Find by Recipient

4. Filter by Labels (Gmail)

5. Date Range Queries

6. Thread Queries

7. With Attachments

8. Newsletter Detection

Sample Reference

  • Graphlit_2024_09_07_Locate_Google_Emails_by_Person.ipynb

  • Graphlit_2024_12_09_Locate_Microsoft_Emails_by_Organization.ipynb

Query emails

emails = await graphlit.queryContents( filter=ContentFilterInput( types=[ContentTypes.Email] ) )

By sender

from_kirk = await graphlit.queryContents( search="[email protected]", search_type=SearchTypes.Keyword, filter=ContentFilterInput( types=[ContentTypes.Email] ) )

Recent emails

recent = await graphlit.queryContents( filter=ContentFilterInput( types=[ContentTypes.Email], created_in_last='P7D' ) )

Access metadata

for email in emails.contents.results: if email.email: print(f"From: {email.email.from_[0].email}") print(f"Subject: {email.email.subject}")

Developer Hints

Email Addresses are Searchable

Labels are Gmail-Specific

Thread Detection

Common Issues & Solutions

Issue: Can't filter by specific label Solution: Query all emails, filter client-side

Issue: Want emails TO a specific person Solution: Search by email or filter client-side

Issue: Need to count emails by sender Solution: Query and aggregate client-side

Production Example

Last updated

Was this helpful?