The Vision: Inbox Zero via Intelligence
Email fatigue is real. I developed this advanced automation workflow using **n8n** and **OpenAI (GPT-4o)** to transform a cluttered inbox into an organized, self-sorting system. The goal was to build a personal assistant that doesn't just filter, but understands context and prepares responses.
The Automation Pipeline
Built as a modular high-performance pipeline, the workflow processes incoming mail every minute through four intelligent stages:
- **Intelligent Triage**: A LangChain-powered Text Classifier categorizes emails into 7 distinct types (Social, Personal, Recruitments, etc.).
- **Contextual Routing**: Automated logic routes "Social" updates to Google Sheets while prepping "Sales" and "Recruitment" for drafts.
- **Smart Auto-Drafting**: Uses GPT-4o to generate polite, context-aware reply drafts in Gmail—ready for human review.
- **Structured Logging**: Maintains a chronological record of all social summaries in Google Sheets for clutter-free reading.
Mistakes & Roadblocks (The Hard Way)
Integrating AI models with live API triggers revealed several technical challenges in prompt engineering and state management.
Markdown Pollution: The LLM initially returned drafts wrapped in markdown code blocks (```json), which broke the Gmail node.
The Fix: Refined the System Prompt to enforce a "Pure JSON" output and added a JavaScript function node to clean the string.
Looping & Duplicates: The "Every Minute" trigger was re-processing the same emails multiple times.
The Fix: Implemented a "Mark as Read" action immediately after classification to act as a state-check flag.
Hallucinated Signatures: The AI was signing off as a generic "Assistant" instead of my personal name.
The Fix: Hardcoded my identity into the System Prompt for each category-specific OpenAI node.
Key Takeaways
- **Safety First Architecture**: By using "Draft" mode instead of "Send," I created a human-in-the-loop system for AI safety.
- **API Orchestration**: Successfully balanced OpenAI token usage by using gpt-4o-mini for triage and gpt-4o for complex drafting.
- **Modular Scaling**: The n8n structure allows for easy addition of new categories (e.g., "Urgent" or "Family") without breaking the flow.
The Final Result
A fully autonomous Gmail assistant that summarizes social clutter into Sheets and has draft replies waiting for me before I even open my laptop. A true time-multiplier built on 24/7 cloud automation.