Building an AI Email Intelligence Pipeline
How I connected Gmail, n8n, OpenRouter AI, and PostgreSQL to turn incoming email into searchable intelligence in a secure Next.js dashboard.
The Problem
Important Gmail messages required manual review and triage.
The goal was to create a structured intelligence layer around the inbox so urgency, sentiment, category, and reply requirements could be reviewed in one dashboard.
The Architecture
- Gmail provides the incoming email input.
- n8n orchestrates receipt, content preparation, AI processing, and routing.
- OpenRouter AI produces structured email intelligence.
- PostgreSQL stores the structured result.
- Next.js renders a secure dashboard.
The Query Layer
The dashboard database access lives in a server-only module.
It supports sender-or-subject search, priority, category, sentiment, and reply-required filters.
Implementation Decisions
The PostgreSQL client stays on the server and uses SSL by default.
The browser never receives database credentials or talks directly to PostgreSQL.
The admin area uses a signed session and a scrypt password hash with a timing-safe comparison.
Challenges
The main challenge was keeping an external automation workflow and a read-only dashboard loosely coupled.
The dashboard can evolve around the structured result without becoming part of ingestion.
Lessons Learned
AI output becomes more useful when it is stored as predictable fields rather than left as raw text.
Summary, category, priority, sentiment, reply status, suggested action, and confidence give the interface concrete values to query.
/ KEEP READING
Related Articles
Building TERRA·SCAN: AI Land Inspection Tool
How I built an AI-powered land inspection platform with Next.js, OpenRouter vision API, and Leaflet maps.
Building BuildAI: Construction Project Management SaaS
How I turned a Bolt.new export into a production-ready AI construction SaaS with Supabase, OpenRouter, and Vercel.
Building ProposalIQ: AI Proposals for African Freelancers
How I built a full-stack AI proposal generator with Paystack, Resend, and public share links — deployed and live.
Full Stack SaaS in a Weekend
Next article →How I Built an AI Interview Coaching Platform
KEEP EXPLORING
Interested in the projects behind these articles?
Explore the systems, AI products, and full-stack applications I'm building.
View Projects →