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.
- 🤖 AI Analysis: Incoming emails are automatically summarized by
Meta Llama-3-8bto 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.
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)
├── 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
- Node.js (v20+ recommended)
- Cloudflare Account
- Wrangler CLI installed globally:
npm install -g wrangler
- Clone the repository:
git clone https://github.com/ravarch/AI-Mail
cd AI-Mail
- Install dependencies:
npm install
- 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
- Configure Variables:
Update
wrangler.jsoncwith your domain:
"vars": {
"DOMAIN": "yourdomain.com",
"JWT_SECRET": "your-secret-key"
}
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*
- Build the Frontend:
npm run build
This generates the dist folder which wrangler will serve as assets.
2. Deploy to Cloudflare:
npm run deploy
- 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-spaworker.
- Open the deployed URL.
- Click "Generate Identity" to create a fresh inbox.
- Send an email to the generated address (e.g.,
user123@yourdomain.com). - Watch it appear instantly in the inbox with an AI-generated summary!
Join the discussion and get support:
This project is open source.
Based on the files provided, here are a few critical things you need to do to make this work 100%:
- 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 theINSERTandSELECTstatements insrc/index.ts. You must run that SQL against your D1 database. - 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. - Workers AI: Ensure your Cloudflare plan supports Workers AI (Llama-3) or that you have enabled the beta features if required.