Skip to main content

Getting Started

This guide will help you set up the Email Assistant on your machine.

Prerequisitesโ€‹

RequirementVersion
Python3.11+
Gmail AccountPersonal or Google Workspace
Google Cloud ProjectFor Gmail API
Gemini API KeyFor AI categorization

Installationโ€‹

1. Clone Repositoryโ€‹

git clone https://github.com/YOUR_USERNAME/emailAssistant.git
cd emailAssistant

2. Create Virtual Environmentโ€‹

python3 -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate

3. Install Dependenciesโ€‹

# Core dependencies
pip install -r requirements.txt

# For development and testing
pip install -r requirements-dev.txt

4. Configure Gmail APIโ€‹

Create Google Cloud Projectโ€‹

  1. Go to Google Cloud Console
  2. Create a new project
  3. Enable Gmail API
  4. Enable Google Calendar API (optional)
  5. Enable Google Tasks API (optional)

Create OAuth Credentialsโ€‹

  1. Go to APIs & Services > Credentials
  2. Click Create Credentials > OAuth client ID
  3. Select Desktop app
  4. Download credentials.json
  5. Place in project root

5. Set Gemini API Keyโ€‹

Get your key from Google AI Studio

export GOOGLE_API_KEY='your_api_key_here'

# Add to shell profile for persistence
echo 'export GOOGLE_API_KEY="your_api_key_here"' >> ~/.bashrc
source ~/.bashrc

6. Create Directoriesโ€‹

mkdir -p data/cache data/digest data/metrics data/test_results logs config

7. Configure Applicationโ€‹

cp config/config.example.json config/config.json

Edit config/config.json:

{
"api_settings": {
"gemini_model": "gemini-2.5-flash-lite",
"requests_per_minute": 30,
"max_retries": 3,
"timeout_seconds": 30
},
"gmail_settings": {
"max_emails_to_fetch": 10,
"search_query": "is:unread newer_than:1d"
},
"cache_settings": {
"enabled": true,
"max_cached_emails": 30,
"cache_expiry_hours": 24
}
}

Running the Applicationโ€‹

First Run (CLI)โ€‹

python src/main.py

On first run, you'll be prompted to authenticate:

  1. Browser opens automatically
  2. Sign in with your Google account
  3. Grant permissions
  4. Token saved to token.json

Web Interfaceโ€‹

# Start the server
./scripts/start_server.sh
# or
python src/web/server.py

Open: http://localhost:8001

Project Structureโ€‹

emailAssistant/
โ”œโ”€โ”€ src/
โ”‚ โ”œโ”€โ”€ main.py # CLI entry point
โ”‚ โ”œโ”€โ”€ utils/ # Utility modules
โ”‚ โ”‚ โ”œโ”€โ”€ email_utils.py # Gmail API operations
โ”‚ โ”‚ โ”œโ”€โ”€ gemini_utils.py # Gemini AI operations
โ”‚ โ”‚ โ”œโ”€โ”€ display_utils.py # Digest generation
โ”‚ โ”‚ โ”œโ”€โ”€ logger_utils.py # Logging configuration
โ”‚ โ”‚ โ””โ”€โ”€ metrics_utils.py # Metrics tracking (SQLite)
โ”‚ โ”œโ”€โ”€ core/ # Core modules
โ”‚ โ”‚ โ”œโ”€โ”€ config_manager.py
โ”‚ โ”‚ โ””โ”€โ”€ cache_manager.py
โ”‚ โ””โ”€โ”€ web/ # Web interface
โ”‚ โ”œโ”€โ”€ server.py # Flask server
โ”‚ โ”œโ”€โ”€ templates/ # HTML templates
โ”‚ โ””โ”€โ”€ static/ # CSS and JavaScript
โ”œโ”€โ”€ config/
โ”‚ โ””โ”€โ”€ config.json # Configuration
โ”œโ”€โ”€ data/
โ”‚ โ”œโ”€โ”€ cache/ # Email cache
โ”‚ โ”œโ”€โ”€ digest/ # Digest data
โ”‚ โ””โ”€โ”€ metrics/ # SQLite database
โ”œโ”€โ”€ logs/
โ”‚ โ””โ”€โ”€ email_assistant.log
โ”œโ”€โ”€ tests/ # Test suite
โ””โ”€โ”€ requirements.txt

Troubleshootingโ€‹

"No digest data available"โ€‹

Run the main script first:

python src/main.py

"Lock file stuck"โ€‹

If the "Refreshing..." button won't reset:

rm script.lock

"credentials.json not found"โ€‹

Download from Google Cloud Console and place in project root.

"GOOGLE_API_KEY not set"โ€‹

Export the environment variable:

export GOOGLE_API_KEY='your_key_here'

Port Conflictโ€‹

lsof -i :8001
kill -9 <PID>

Import Errorsโ€‹

cd /path/to/emailAssistant
source .venv/bin/activate
pip install -r requirements.txt

Security Notesโ€‹

NEVER commit these files:

  • credentials.json - OAuth credentials
  • token.json - Access token
  • config/config.json - May contain sensitive data
  • data/ - Contains personal email data
  • .env - Environment variables

These are protected by .gitignore.

Next Stepsโ€‹