Skip to content

ravarch/AI-Mail

Repository files navigation

AI Secure Mail 🛡️

A modern, serverless, AI-powered email service built on Cloudflare Workers, React 19, and Hono. This application allows users to generate secure email identities, receive emails in real-time via WebSockets, and get instant content summaries via Llama-3.

License React Cloudflare Tailwind

🚀 Features

  • 🤖 AI Analysis: Incoming emails are automatically summarized by Meta Llama-3-8b to provide quick context and safety checks.
  • ⚡ Real-time Inbox: Uses Durable Objects and WebSockets to push new emails to the client instantly (no page refreshes).
  • 🔒 Secure Identities: Generate random, persistent credentials or log in with existing ones.
  • ☁️ Serverless Architecture: Hosted entirely on the Edge. No traditional servers.
    • Storage: Raw email content in R2, Metadata in D1.
    • Backend: Hono API running on Cloudflare Workers.
  • 📱 Modern UI: Fully responsive design with Dark/Light glassmorphism aesthetics, built with Tailwind v4 and Framer Motion.
  • reply Functionality: Send replies directly from the interface.

🛠️ Tech Stack

Frontend:

  • React 19
  • Vite 7
  • Tailwind CSS v4
  • Framer Motion (Animations)
  • Lucide React (Icons)

Backend (Edge):

  • Cloudflare Workers
  • Hono (Web Framework)
  • Durable Objects (WebSockets)
  • Cloudflare D1 (SQLite Database)
  • Cloudflare R2 (Object Storage)
  • Workers AI (Llama-3 Inference)
  • PostalMime (Email Parsing)

📂 Project Structure

├── public/              # Static assets
├── src/
│   ├── components/      # React components (TelegramBanner, etc.)
│   ├── App.tsx          # Main React Application Logic
│   ├── index.css        # Tailwind V4 Imports
│   └── index.ts         # Backend Logic (Hono API + Email Worker)
├── wrangler.jsonc       # Cloudflare Infrastructure Config
├── package.json         # Dependencies
└── vite.config.ts       # Build configuration

⚙️ Prerequisites

  1. Node.js (v20+ recommended)
  2. Cloudflare Account
  3. Wrangler CLI installed globally: npm install -g wrangler

📦 Installation & Setup

  1. Clone the repository:
git clone https://github.com/ravarch/AI-Mail
cd AI-Mail
  1. Install dependencies:
npm install
  1. Setup Cloudflare Infrastructure: You need to create the specific resources defined in wrangler.jsonc.
  • Create D1 Database:
npx wrangler d1 create saas-db-prod

Update the database_id in wrangler.jsonc with the ID output from this command.

  • Create R2 Bucket:
npx wrangler r2 bucket create mail-storage
  • Initialize Database Schema: Create a file named schema.sql (if not present) with the following content, then execute it:
CREATE TABLE IF NOT EXISTS users (
    username TEXT PRIMARY KEY,
    password TEXT
);
CREATE TABLE IF NOT EXISTS emails (
    id TEXT PRIMARY KEY,
    username TEXT,
    sender TEXT,
    subject TEXT,
    snippet TEXT,
    raw_r2_key TEXT,
    has_attachments INTEGER DEFAULT 0,
    is_read INTEGER DEFAULT 0,
    ai_summary TEXT,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
CREATE INDEX IF NOT EXISTS idx_emails_user ON emails(username);

Apply Schema:

npx wrangler d1 execute saas-db-prod --local --file=./schema.sql
  1. Configure Variables: Update wrangler.jsonc with your domain:
"vars": {
    "DOMAIN": "yourdomain.com",
    "JWT_SECRET": "your-secret-key"
}

🏃‍♂️ Development

Run the frontend and backend locally. Since this uses Hono + Vite + Cloudflare, we use Wrangler to emulate the environment.

npm run dev

*Access the app at http://localhost:8787*

🚀 Deployment

  1. Build the Frontend:
npm run build

This generates the dist folder which wrangler will serve as assets. 2. Deploy to Cloudflare:

npm run deploy
  1. Connect Email Routing: In your Cloudflare Dashboard > Email > Email Routing:
  • Enable Email Routing for your domain.
  • Go to Routes.
  • Create a "Catch-all" rule or specific address rule.
  • Action: "Send to a Worker".
  • Destination: Select your deployed react-spa worker.

📧 Usage

  1. Open the deployed URL.
  2. Click "Generate Identity" to create a fresh inbox.
  3. Send an email to the generated address (e.g., user123@yourdomain.com).
  4. Watch it appear instantly in the inbox with an AI-generated summary!

🤝 Community

Join the discussion and get support: Telegram

📄 License

This project is open source.

Notes for the User (Implementation Details)

Based on the files provided, here are a few critical things you need to do to make this work 100%:

  1. Missing Schema: The code references tables (users, emails) but no SQL file was included. I have inferred the schema in the "Installation" section above based on the INSERT and SELECT statements in src/index.ts. You must run that SQL against your D1 database.
  2. Email Routing Binding: In wrangler.jsonc, you have "send_email". Ensure you have verified the destination address (admin@drkingbd.cc) in your Cloudflare dashboard under Email Routing > Settings, or you won't be able to reply to emails.
  3. Workers AI: Ensure your Cloudflare plan supports Workers AI (Llama-3) or that you have enabled the beta features if required.

Packages

 
 
 

Contributors