# How to Vibe Code Your Own SaneBox (and Stop Paying for It)

> Email Management for Any Inbox

- Site: https://sanebox.com
- Category: Email Management
- Verdict: **Solid side project** (68/100 vibecodeable)
- Estimated effort: 2-3 weeks part-time

## Verdict

Build a personal subset for your own mail accounts, but expect tedious IMAP connection debugging and token refresh edge cases.

Creating a personal SaneBox clone for your own Gmail or Microsoft 365 account is an achievable side project if you scope it down to IMAP folder syncing and a simple header classification script. However, you will inevitably hit friction dealing with OAuth token expirations, IMAP IDLE drops, and rate limits from email providers. Because there is no frontend mail client to code—it all runs via server-side folder trees—you save immense UI effort, but the backend plumbing requires rigorous asynchronous worker management.

### What you can't replicate

- Google's Restricted Scopes annual security verification pedigree
- Years of historical sender interaction datasets
- Enterprise-grade multi-tenant IMAP reliability infrastructure

## What it does

AI-powered email management and inbox organization service that analyzes message headers to filter clutter into smart folders without requiring a custom mail client.

### Core features

- OAuth2 authentication with Gmail and Microsoft 365
- Persistent IMAP IDLE connection and mailbox folder synchronization
- Header-based importance classification engine
- Automated moving of unimportant mail to @SaneLater folders
- SaneBlackHole folder for blocking senders
- SaneReminders follow-up tracking assistant
- Daily Digest email summary generation
- Snooze functionality via scheduled folder shifts

## The business

### Pricing

- Snack: $7/mo — Supports 1 email account and 1 optional folder with limited monthly feature allocations.
- Lunch: $12/mo — Supports up to 2 email accounts with expanded feature bundles.
- Dinner: $36/mo — Supports up to 4 email accounts with unlimited features and custom folders.

### Funding

$0 raised.

Founded 2010.
Team size: 12.

## The hard parts

- Maintaining stable, long-running IMAP IDLE connection pools across diverse mail server implementations (Google, Microsoft, Fastmail)
- Navigating stringent OAuth2 security constraints and restricted scope compliance audits
- Implementing an asynchronous background worker pipeline for zero-latency email header ingestion
- Handling edge cases in IMAP flag synchronization and folder creation across varied email clients

## How to vibe code SaneBox

### Prerequisites

- Node.js (free): Runtime environment for the backend worker and automation scripts
- GitHub (free): Source control and deployment pipeline integration
- Google Cloud / Azure Developer Account (free): Required to configure OAuth2 credentials and API scopes for mailbox access

### Recommended AI tools

- Claude Code: Agentic terminal coding tool best suited for orchestrating backend IMAP workers and database schemas
- Cursor: AI code editor for refining classification algorithms and webhook routing logic

### Stack

- Frontend: Next.js
- Backend: Node.js with Express & IMAP library
- Database: Turso
- Auth: better-auth
- Payments: none
- Other: Resend, Inngest

### Hosting

- Fly.io (Hosting persistent background worker containers required for IMAP IDLE connections): $3-5/mo
- Vercel (Hosting the lightweight Next.js dashboard for account configuration and digests): $0/mo

### Build guide

1. **Project Scaffolding & Database Schema** — Initialize the Next.js project with Turso database connectivity, user models, and encrypted OAuth token storage tables.

```
Initialize a new Next.js project using TypeScript and Tailwind CSS. Set up Turso for database access using Drizzle ORM. Create the database schema tables: users (id, email, created_at), accounts (id, user_id, provider, access_token_encrypted, refresh_token_encrypted, token_expires_at), and email_logs (id, user_id, message_id, sender, subject, date, action_taken). Ensure all environment variables for Turso and encryption keys are correctly typed and validated using Zod. Write comprehensive unit tests for the database connection and model operations.
```

2. **OAuth2 Authentication Integration** — Implement OAuth2 authorization flows for Gmail and Microsoft 365 with secure credential encryption.

```
Implement OAuth2 authentication routes for Google and Microsoft 365 using standard Node.js authentication libraries. Store the resulting refresh and access tokens securely in the Turso database using AES-256 encryption. Build a robust token refresh mechanism that automatically exchanges expired access tokens using stored refresh tokens before any IMAP connection attempt. Include error handling for revoked grants and clear user re-authentication prompts in the Next.js dashboard.
```

3. **IMAP Connection & Folder Sync Engine** — Build the core backend worker capable of connecting to mail servers via IMAP, creating custom folders, and monitoring messages.

```
Build a background worker service in Node.js utilizing an IMAP client library (such as node-imap) to connect securely to mail servers using XOAUTH2 credentials. Implement routines that automatically verify and create target folders ('@SaneLater', '@SaneBlackHole') upon initial sync. Set up IMAP IDLE listeners or polling mechanisms to detect incoming messages in the Inbox folder in real time without blocking the main event loop. Handle connection drops and automatic reconnections gracefully.
```

4. **Header Classification & Routing Logic** — Develop the heuristic engine that parses email headers (sender, subject, interaction history) to decide whether to move messages.

```
Develop an email classification module that evaluates incoming email headers (sender address, subject keywords, date, and historical interaction frequency stored in Turso). If an email is determined to be low-value or from an unknown sender, program the IMAP engine to move the message from the 'INBOX' folder to the '@SaneLater' folder. Implement a training endpoint so that when a user manually moves an email back to the inbox from '@SaneLater', the system updates sender heuristics and updates the database state accordingly.
```

5. **BlackHole & Snooze Features** — Add support for permanently blocking senders via SaneBlackHole and postponing messages via SaneSnooze.

```
Implement the SaneBlackHole feature: when an email is dragged into the '@SaneBlackHole' folder, parse the sender address, store it in a blocked_senders table, and automatically delete or archive future messages from that sender. Implement the SaneSnooze feature using background cron jobs (via Inngest) to move selected emails out of the inbox into a temporary folder and return them to the primary inbox at a scheduled timestamp.
```

6. **Daily Digest & Dashboard UI** — Create the user dashboard and automated email digest summarizing filtered messages.

```
Build a Next.js dashboard displaying connected email accounts, recent filter activity logs, and manual training controls. Implement an automated daily cron job that compiles a summary of emails moved to '@SaneLater' over the past 24 hours and dispatches a Daily Digest email to the user using Resend. Ensure the dashboard UI is clean, responsive, and styled with Tailwind CSS.
```

### Cost vs paying

**Starting costs (one-time):**

- AI Coding Assistant Subscriptions: $20.00
- Total: ~$20.00 one-time

**Ongoing costs (monthly):**

- Fly.io Persistent Worker Hosting: $4.00/mo
- Resend Email API (Free Tier): $0.00/mo
- Turso Database (Free Tier): $0.00/mo
- Total: ~$4.00/mo

- Paying for the SaaS instead: $7.00 - $36.00/mo
- Build time: 35-50 hours
- AI tool credits: $20.00 (Claude Code / Cursor Pro)
- Break-even: 1 month vs Lunch Plan

## Sources

- [SaneBox Official Website](https://sanebox.com)
- [SaneBox Security Documentation](https://sanebox.com/_security.md)
- [Agentys SaneBox Pricing & Feature Breakdowns](https://agentys.io)