This guide explains how to configure the environment variables for the Intelligent Inbox Email Classification system.
-
Copy the environment templates:
cp .env.example .env cp .env.secrets.template .env.secrets
-
Add secrets to .gitignore (if not already present):
echo ".env" >> .gitignore echo ".env.secrets" >> .gitignore echo "*.key" >> .gitignore echo "credentials/" >> .gitignore
-
Edit the configuration files:
.env- Non-sensitive configuration (ports, hosts, feature flags).env.secrets- Sensitive credentials (passwords, API keys)
Contains all non-sensitive environment variables with reasonable defaults. This file is tracked in version control.
Key sections:
- Database connection settings
- Service ports and hosts
- Feature flags
- Performance tuning
- Logging configuration
Contains sensitive information that should never be committed. This template provides the structure but you must fill in actual values.
Key sections:
- Encryption keys
- Passwords and credentials
- API keys
- SSL certificates
- Backup encryption
# Database
DB_URL=postgresql://classifier:password@localhost:5432/email_classifier
# LLM (Ollama)
OLLAMA_HOST=http://localhost:11434
QWEN_MODEL_NAME=qwen3:8b
# Vector Database
QDRANT_HOST=localhost
QDRANT_PORT=6333
# Email IMAP
IMAP_SERVER=imap.gmail.com
IMAP_USERNAME=your-email@gmail.com
IMAP_PASSWORD=app-password# Encryption (required for sensitive data)
ENCRYPTION_KEY=your-32-byte-encryption-key-here
# Dashboard authentication
DASHBOARD_USERNAME=admin
DASHBOARD_PASSWORD=secure-password# Core features
RAG_ENABLED=true
STORE_RAW_EMAILS=false
RETENTION_DAYS=90
# Performance
EMAIL_POLL_INTERVAL=30
CLASSIFY_CONCURRENCY=2# Generate Fernet key for data encryption
python -c "from cryptography.fernet import Fernet; print(Fernet.generate_key())"
# Generate random password
openssl rand -base64 32For Gmail, always use app-specific passwords:
- Go to Google Account settings
- Enable 2-factor authentication
- Generate app-specific password
- Use it in
IMAP_PASSWORD
Create different configurations for different environments:
Development (.env.dev):
DEBUG=true
LOG_LEVEL=DEBUG
EMAIL_POLL_INTERVAL=60 # Less frequent in devProduction (.env.prod):
DEBUG=false
LOG_LEVEL=INFO
EMAIL_POLL_INTERVAL=30
STORE_RAW_EMAILS=falseUse environment files with Docker Compose:
docker compose --env-file .env --env-file .env.secrets up -dThe system validates required environment variables at startup:
# Test configuration
python -c "
from src.config import Settings
settings = Settings()
print('✅ Configuration valid')
"Common validation errors:
- Missing
ENCRYPTION_KEY - Invalid database URL
- Missing IMAP credentials
- Invalid port numbers
DB_URL- PostgreSQL connection stringDB_HOST,DB_PORT,DB_NAME,DB_USER,DB_PASSWORD- Alternative to DB_URL
OLLAMA_HOST- Ollama server endpointQWEN_MODEL_NAME- Model name (e.g., qwen3:8b)LLM_TEMPERATURE- Sampling temperature (0.0-1.0)LLM_MAX_TOKENS- Maximum response tokens
QDRANT_HOST,QDRANT_PORT- Qdrant connectionSUPABASE_URL,SUPABASE_KEY- Alternative Supabase setup
IMAP_SERVER- IMAP server hostnameIMAP_USERNAME,IMAP_PASSWORD- Email credentialsIMAP_FOLDER- Mailbox to monitor (default: INBOX)EMAIL_POLL_INTERVAL- Seconds between polls
DASHBOARD_PORT- FastAPI server portDASHBOARD_USERNAME,DASHBOARD_PASSWORD- Admin credentials
GRAFANA_PASSWORD- Grafana admin passwordPROMETHEUS_PORT- Prometheus portMETRICS_ENABLED- Enable metrics collection
RAG_ENABLED- Enable retrieval-augmented generationSTORE_RAW_EMAILS- Store encrypted email bodiesRETENTION_DAYS- Data retention period
CLASSIFY_CONCURRENCY- Parallel classification jobsRAG_TOP_K- RAG context chunks to retrieveRAG_SIMILARITY_THRESHOLD- Minimum similarity score
ENCRYPTION_KEY- 32-byte Fernet keyDEBUG- Enable debug mode (production: false)LOG_LEVEL- Logging level (DEBUG, INFO, WARNING, ERROR)
-
Database Connection Failed
- Verify PostgreSQL is running
- Check DB_URL format and credentials
- Ensure database exists
-
Ollama Connection Failed
- Verify Ollama service is running
- Check OLLAMA_HOST URL
- Ensure model is downloaded
-
IMAP Authentication Failed
- Use app-specific password for Gmail
- Verify IMAP server settings
- Check username/password
-
Encryption Key Error
- Generate new Fernet key
- Ensure key is 32 bytes URL-safe base64 encoded
- Check key is not truncated
Enable debug mode for detailed logging:
DEBUG=true LOG_LEVEL=DEBUGChange default ports if conflicts occur:
DASHBOARD_PORT=8081
QDRANT_PORT=6334For production deployment:
- Use environment-specific .env files
- Set strong passwords and encryption keys
- Disable debug mode
- Configure proper logging
- Set up SSL certificates
- Configure backup encryption
- Monitor environment variable usage
Example production .env:
DEBUG=false
LOG_LEVEL=INFO
STORE_RAW_EMAILS=false
RETENTION_DAYS=365
EMAIL_POLL_INTERVAL=30
CLASSIFY_CONCURRENCY=4