← Back to Blog
AI AutomationAugust 22, 2026•9 min read

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.

AOAbere Oluwatomide•AI Engineer & Full-Stack Developer

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

KEEP EXPLORING

Interested in the projects behind these articles?

Explore the systems, AI products, and full-stack applications I'm building.

View Projects →