✦

SAAD ELGHABA

Portfolio

Loading... 0%

AI Automation

MailMind: AI-Powered Local Email Client

MailMind: AI-Powered Local Email Client

A local-first, AI-powered email client built with React, TypeScript, and n8n. It bridges Gmail and a custom frontend using webhooks, featuring on-demand Gemini AI summarization, priority triage, and a sleek interface without relying on heavy cloud providers.

Category

AI Automation

Technologies

VS Code, React, N8N, OAuth2, Rest API, JavaScript, TypeScript

Timeline

Nov 14, 2026 - Nov 14, 2026

The Challenge

Traditional email clients are cluttered and lack native AI integration. Building a custom client usually requires setting up a dedicated backend server to handle OAuth, API rate limits, and data transformation. I wanted a lightweight, local-first solution with on-demand AI triage.

Strategic Approach

Built a React frontend connected to a self-hosted n8n workflow. I used the n8n Wait node as an indefinite listener to bridge the frontend and Gmail. When the frontend needs data or AI analysis, it pings the webhook URL, n8n fetches the email, optionally processes it with Gemini, and returns the JSON.

Measurable Outcomes

Successfully created a zero-cost, local-first email client with AI triage. Bypassed browser iFrame restrictions and n8n response wrapping issues. Achieved seamless on-demand email fetching and AI summarization without a single traditional backend server.

Overview

The Vision: A Custom, AI-Driven Inbox

Most email clients are bloated, cluttered with ads, and lack native, intelligent triage. I wanted a fast, minimalist, local-first interface that connects directly to my Gmail, with an AI assistant on standby to summarize long threads and prioritize my inbox on demand.

MailMind is the result. It's a custom React frontend powered by an advanced n8n automation layer that handles Gmail fetching, server-side HTML sanitization, and Google Gemini AI processing.


The Architecture: The n8n Wait Node as a Bridge

Instead of building a traditional backend (Node.js/Python) to handle OAuth and API routing, I used n8n as the entire backend infrastructure. The system works in a loop:

  1. The n8n workflow fetches the 10 most recent emails and triggers a browser tab via OpenThatLink.
  2. The React app loads the list of emails.
  3. When a user clicks an email to read it, the React app sends a GET request to the n8n Wait node's resume URL.
  4. The n8n workflow resumes, fetches the full email body from Gmail, optionally runs it through Gemini for AI analysis, and returns the JSON payload to the frontend.


Key Features

  • Dual-Mode Rendering: Safely renders HTML emails using DOMPurify, with a fallback to a custom markdown parser for plain-text emails.
  • On-Demand AI Triage: Click the \"AI Powered\" button on any email to trigger the Gemini node, which returns a priority label and a 2-line summary.
  • Lazy Loading: The initial payload only contains email metadata. Bodies are fetched strictly on demand, keeping the UI lightning fast.
  • Client-Side State: No database needed. State is managed purely in React, ensuring a stateless, secure architecture.

Technical Challenges Solved

  • Bypassing iFrame Restrictions: n8n wraps HTML responses in sandboxed iframes, blocking window.open(). I bypassed this by using OpenThatLink to open the React app directly, passing the n8n payload via URL parameters.
  • Opaque n8n Response Shapes: n8n returns data wrapped in complex objects ({ result: [{ json }] }). I wrote a custom unwrapEmailList() mapper in TypeScript that handles every variation n8n throws at it.
  • Gmail API Limitations: The Gmail node defaults to simple: true, which only returns snippets. I had to explicitly set simple: false on the get-one node to fetch the full HTML body.
  • Flexbox Scrolling Bug: The reading pane wouldn't scroll because the flexbox height chain broke overflow-y-auto. Fixed by adding min-h-0 to every flex ancestor.

The Result

MailMind is a fully functional, completely self-hosted personal email client. It proves that with the right orchestration, you can build highly interactive, stateful applications entirely on top of n8n, bypassing the need for traditional backend infrastructure while keeping costs at zero.

"

Related Services

Business Automation

Let's Create Something Extraordinary

Have a project in mind? Let's discuss how we can bring your vision to life.

Start a Project
MailMind: AI-Powered Local Email Client