# Gmail AI Email Prioritization & Summary Agent (Free Version) ## Project Name Gmail AI Email Prioritization Agent ## Project Overview Build a web application that automatically connects to a single Gmail account, scans all unread emails, uses a free AI model to prioritize and categorize emails, and sends a summary email back to the same Gmail account. This MVP version is designed for a single user and should hardcode access to one Gmail account. No multi-user support is required. The application should use only free tools, free APIs, and open-source AI models. --- # Purpose Professionals receive large numbers of emails and often struggle to identify what requires immediate attention. This application will: 1. Connect to Gmail. 2. Retrieve all unread emails. 3. Analyze each unread email. 4. Assign a priority level. 5. Categorize the email. 6. Generate concise summaries. 7. Create a daily summary report. 8. Email the report to the user. The goal is to reduce email overload and help users focus on the most important messages first. --- # Core User Story As a user, I want the application to automatically scan my unread Gmail messages, so that AI can prioritize, categorize, summarize, and email me a digest of what requires my attention. --- # Application Type * Web Application * Single User MVP * Responsive Design * Desktop and Mobile Friendly --- # Authentication ## Gmail Authentication For MVP: Hardcode access to a single Gmail account using OAuth credentials stored in environment variables. No user login page required. The application should automatically authenticate using stored Gmail OAuth credentials. Required credentials: * GOOGLE_CLIENT_ID * GOOGLE_CLIENT_SECRET * GOOGLE_REFRESH_TOKEN Store securely in environment variables. --- # Main Features ## Feature 1: Scan Gmail Inbox ### Description Connect to Gmail using the Gmail API. Retrieve: * All unread emails * Inbox emails only * Exclude spam * Exclude trash ### Email Data Collected For each email: * Sender Name * Sender Email * Subject * Date Received * Message Body * Gmail Thread ID * Gmail Message ID --- ## Feature 2: AI Prioritization ### Description Use a free AI model to determine urgency and importance. ### Priority Levels #### Priority 1 - Critical Examples: * Executive requests * Customer escalations * Contract issues * Meeting today * Urgent deadlines #### Priority 2 - Important Examples: * Project updates * Client communications * Action required #### Priority 3 - Normal Examples: * Informational messages * Internal updates #### Priority 4 - Low Priority Examples: * Newsletters * Marketing emails * Promotions ### AI Output Return: ```json { "priority": "Critical", "reason": "Customer escalation requiring response within 24 hours" } ``` --- ## Feature 3: AI Categorization ### Categories Automatically assign one category. Categories: * Action Required * Customer * Leadership * Meeting * Finance * Project * Sales * Marketing * HR * Personal * Newsletter * System Notification * Other ### AI Output ```json { "category": "Action Required" } ``` --- ## Feature 4: Email Summarization ### Description Generate a concise summary. Maximum: * 2-3 sentences * 75 words Example: "This email requests approval for the Q3 budget proposal. Finance requires feedback by Friday to maintain project timelines." --- ## Feature 5: Action Extraction Extract: * Deadlines * Meeting dates * Requested actions Example: ```json { "actions": [ "Review proposal", "Provide approval" ], "deadline": "Friday" } ``` --- ## Feature 6: Summary Dashboard Create a simple dashboard displaying: ### Summary Metrics * Total unread emails * Critical emails * Important emails * Normal emails * Low-priority emails ### Category Breakdown Show counts for: * Customer * Leadership * Finance * Project * Meetings * Newsletters * Other ### Email Table Columns: * Priority * Category * Sender * Subject * Date * Summary Sorting: * Highest Priority First --- ## Feature 7: Daily Summary Email ### Description Generate a digest email. Send from Gmail to the same Gmail account. ### Subject Daily AI Email Summary ### Email Format # AI Email Summary ## Critical Emails ### Email 1 Sender: Subject: Summary: Action Required: --- ## Important Emails ### Email 2 Sender: Subject: Summary: Action Required: --- ## Category Breakdown Customer: 5 Meetings: 3 Finance: 2 Newsletters: 12 --- ## Recommended Focus Provide a short AI recommendation on the top items that should be addressed first. --- # AI Requirements ## AI Model Use a completely free AI model. Preferred options: 1. Ollama + Llama 3 2. Ollama + Gemma 3. Ollama + Mistral Default: Llama 3 via Ollama ### Reason * Free * Open source * Runs locally * No token costs * No API costs --- # Processing Workflow ## Step 1 Connect to Gmail API ## Step 2 Retrieve unread emails ## Step 3 For each email: * Extract content * Clean HTML * Remove signatures where possible ## Step 4 Send content to AI model AI returns: * Priority * Category * Summary * Actions * Deadlines ## Step 5 Store results ## Step 6 Display dashboard ## Step 7 Generate summary report ## Step 8 Email report to Gmail account --- # Database Use free database: SQLite Tables: ## Emails Fields: * id * gmail_message_id * gmail_thread_id * sender * sender_email * subject * body * summary * priority * category * actions * deadline * received_date * processed_date --- # Scheduling Run automatically. Default Schedule: Every hour Alternative: Manual "Scan Now" button Implementation: * Node Cron * Free open-source scheduler --- # Tech Stack ## Frontend * React * TypeScript * Tailwind CSS ## Backend * Node.js * Express ## Database * SQLite ## AI * Ollama * Llama 3 ## Gmail Integration * Gmail API * Google OAuth ## Deployment Free options: * Render * Railway * Netlify (frontend) * Local Machine --- # Environment Variables ```env GOOGLE_CLIENT_ID= GOOGLE_CLIENT_SECRET= GOOGLE_REFRESH_TOKEN= GMAIL_EMAIL_ADDRESS= OLLAMA_BASE_URL=http://localhost:11434 DATABASE_URL=sqlite.db ``` --- # Error Handling Handle: * Gmail authentication failures * API rate limits * Empty inbox * AI model unavailable * Invalid email content * Duplicate processing Log all failures. --- # Security Requirements * Credentials stored in environment variables * Never expose Gmail credentials in UI * HTTPS required * No credential storage in browser * Sanitize all email content before display --- # Success Criteria The application is considered successful when: 1. Connects to Gmail automatically. 2. Retrieves unread emails successfully. 3. Categorizes emails correctly. 4. Prioritizes emails accurately. 5. Generates meaningful summaries. 6. Sends summary email successfully. 7. Processes emails in under 2 minutes for 100 unread emails. 8. Runs without paid services. 9. Requires no manual email sorting by the user. 10. Achieves at least 90% categorization accuracy on common business emails. --- # Future Enhancements * Multi-user support * Outlook integration * Microsoft 365 integration * Slack notifications * Teams notifications * SMS alerts * Voice summaries * AI response drafting * Auto-archive low-priority emails * Learning from user feedback * Vector search for email history * RAG-powered email assistant