A full-stack web application that uses the Gmail API to search, export, and analyze email conversations. Built with TypeScript, Express, React, and Material UI, this application provides a seamless workflow for discovering email insights and generating reports.
- Email Search: Filter emails by sender, recipient, date range, subject, or custom query
- Project Management: Organize exports into projects for better workflow management
- Export Creation: Save selected emails as JSON exports with proper thread organization
- Thread Analysis: Analyze email threads with simple statistics or optional OpenAI-powered insights
- Report Generation: Create downloadable PDF reports from analysis results
- Modern UI: Clean, responsive interface built with React and Material UI
- OAuth 2.0 Authentication: Secure access to Gmail API with token refresh support
- TypeScript: End-to-end type safety across frontend and backend
- Node.js (v14 or later)
- npm
- Google Cloud Platform account with Gmail API enabled
- Gmail account with emails you want to export
-
Clone this repository
-
Install dependencies:
npm install
-
Set up Google Cloud Project and Gmail API:
- Go to Google Cloud Console
- Create a new project
- Enable the Gmail API for your project
- Configure the OAuth consent screen
- Create OAuth 2.0 Client ID credentials
- Download the credentials
-
Configure environment variables:
-
Copy
.env.exampleto.env -
Add your Google API credentials to the
.envfile:CLIENT_ID=your_client_id CLIENT_SECRET=your_client_secret REDIRECT_URI=http://localhost:3000/oauth2callback
-
If you plan to use the thread analysis feature, add your OpenAI API key:
OPENAI_API_KEY=your_openai_api_key
-
-
Start the application:
./start.sh
-
Access the web interface at http://localhost:3000
-
The first time you run the application, it will provide a URL for authorization. Open the URL in your browser, grant permission to access your Gmail account, and copy the authorization code back to the terminal if prompted.
-
Project Management
- Create and manage projects to organize your email exports
- Select an existing project or create a new one before starting an export
-
Email Search
- Search emails using filters (date range, sender, recipient, subject, etc.)
- Review search results in a sortable, filterable table
- Select emails to include in your export
-
Export Creation
- Name your export and associate it with a project
- The system will organize selected emails into threads
- JSON export files are stored in the exports directory
-
Analysis
- View thread statistics including word frequency, sender distribution, timeline
- Get simple insights about communication patterns
- Optionally use OpenAI-powered analysis for deeper insights (requires API key)
-
Report Generation
- Generate PDF reports from analysis results
- Download reports for offline use or sharing
FILTER_SENDER=newsletter@example.com- Filter emails from a specific senderFILTER_FROM_DATE=2023/01/01- Filter emails after this dateFILTER_TO_DATE=2023/12/31- Filter emails before this dateFILTER_SUBJECT=Invoice- Filter emails with "Invoice" in the subjectFILTER_QUERY=has:attachment- Filter emails with attachments
You can combine multiple filters to narrow your search. See Gmail search operators for more query options.
- JSON: Exports all email data in a structured JSON format
- CSV: Exports email metadata in a tabular format
- EML: Exports each email as an individual .eml file (can be opened in email clients)
The application connects to the Gmail API using OAuth 2.0 authentication. Here are important details about this integration:
-
Authentication Flow
- The first time you run the application, it will prompt you to authorize access to your Gmail account
- Default authorization uses a local HTTP server for the OAuth callback
- You can set
MANUAL_AUTH=truein.envto use a manual authorization flow if needed - Once authenticated, tokens are stored in a local
token.jsonfile for future use
-
Configuration Options
MOCK_GMAIL_API=true: Use mock data instead of real Gmail API (useful for development)MANUAL_AUTH=true: Use manual authorization flow instead of local HTTP serverPORT=3001: Change the server port (default: 3001)
-
API Usage
- The application uses batch processing to avoid Gmail API rate limits
- Search queries use Gmail's query language for efficient server-side filtering
- Email data is cached locally after retrieval to minimize API calls
-
Permissions Required
- The application requests
https://www.googleapis.com/auth/gmail.readonlyscope - This allows read-only access to Gmail messages - it cannot modify or send emails
- The application requests
-
Rate Limits
- Gmail API has usage quotas (see Google API Quotas)
- The application implements batch processing and exponential backoff for retries
After exporting emails, you can analyze conversation threads to extract insights on specific topics:
-
Make sure you have set your OpenAI API key in the
.envfile -
Run the analysis command with your query:
npm run analyze -- --input ./exports/emails-xxxx-xx-xx.json --query "in network therapy" -
Additional analysis options:
# Minimum number of messages in a thread --min-messages 2 # Filter by date range --from-date 2023-01-01 --to-date 2023-12-31 # Filter by participants --participants user@example.com provider@healthcare.com # Specify output file --output ./analysis-results.json # Change OpenAI model --model gpt-4-turbo
-
The analysis results will include:
- Thread summaries
- Topic identification
- Relevance scores to your query
- Key insights extracted from conversations
- Insurance Coverage Analysis: Find all threads discussing in-network vs. private therapy options
- Customer Support Tracking: Identify recurring issues mentioned in support emails
- Project Management: Extract action items and decisions from email discussions
- Research: Analyze conversations on specific topics across multiple threads
-
Build the project:
npm run build
-
Run in development mode with auto-reload:
npm run dev
ISC