Site icon Efficient Coder

Self-Hosted Email Revolution: Build Your Free Professional Inbox with Cloud Mail

Build Your Own Email System at Zero Cost: The Complete Guide to Cloud Mail

Introduction: Why You Need a Self-Hosted Email Solution

In today’s digital landscape, professional email communication is essential for credibility and privacy. Imagine using yourname@yourdomain.com instead of generic email providers – it instantly elevates your professional image. Traditional enterprise email services often cost hundreds annually, putting them out of reach for individuals and small teams.

Cloud Mail revolutionizes this space – a free, open-source email system built on Cloudflare’s infrastructure that requires zero server costs and no monthly fees. With just a domain name, you can create a fully-functional professional email service. This comprehensive guide explores its features, technical architecture, and deployment process.

Live Demo: https://skymail.ink


Core Functionality Breakdown

1.1 Truly Free Cloud Infrastructure

Cloud Mail leverages Cloudflare’s free tier:

  • Serverless Architecture: Runs on Cloudflare Workers (100k daily requests free)
  • Managed Database: Cloudflare D1 (SQLite database)
  • File Storage: Cloudflare R2 (10GB monthly free)
  • Email Delivery: Resend service (3k monthly emails free)

1.2 Enterprise-Grade Features

Feature Category Implementation User Benefit
Multi-Account Support Multiple addresses per user Unified personal/business management
Attachment Handling R2 cloud storage Large file support
Security Turnstile CAPTCHA Bot registration prevention
Admin Controls RBAC permission system Granular user permissions
Email Tracking Resend delivery callbacks Real-time delivery monitoring
Analytics ECharts integration Usage visualization

1.3 Administrative Capabilities

Admin dashboard includes:

  • User Management: Account suspension/resource allocation
  • Email Auditing: Full system email review
  • System Configuration:
    • Registration open/close
    • Email rate limiting
    • Private site mode
  • Resource Monitoring: Storage/email volume tracking

Technical Architecture Deep Dive

2.1 Frontend Stack

graph LR
A[Vue3] --> B[Element Plus]
A --> C[ECharts]
A --> D[Axios]
  • Responsive Design: Mobile/desktop optimization
  • UX Design: Gmail-like workflow
  • Data Visualization: Interactive email analytics

2.2 Backend Infrastructure

graph TB
H[Hono] --> D[Drizzle ORM]
H --> K[Cloudflare KV]
H --> R[R2]
H --> D1[D1]
  • Web Framework: Hono (edge-optimized)
  • Database: Drizzle ORM + D1
  • Caching: Cloudflare KV sessions
  • Storage: R2 for attachments

2.3 Email Processing Flow

1. Incoming → Cloudflare routing → Worker processing
2. Outgoing → Resend API → Delivery callbacks
3. Attachments → R2 upload/download API

Step-by-Step Deployment Guide

3.1 Environment Setup

# Required tools
Node.js v18.20+
Cloudflare account (with domain)
Git

# Clone repository
git clone https://github.com/LaziestRen/cloud-mail
cd cloud-mail/mail-worker
npm install

3.2 Cloudflare Configuration

Create in Cloudflare dashboard:

  1. D1 Database: Stores user/email data
  2. KV Namespace: Session caching
  3. R2 Bucket: Attachment storage
  4. Worker: Backend deployment

3.3 Configuration File Setup

Edit wrangler.toml:

[[d1_databases]]
binding = "db"
database_name = "cloudmail_db"  # Your D1 name
database_id = "your-d1-id"     # From Cloudflare

[[kv_namespaces]]
binding = "kv"
id = "your-kv-id"              # KV namespace ID

[[r2_buckets]]
binding = "r2"
bucket_name = "attachments"    # R2 bucket name

[assets]
binding = "assets"
directory = "./dist"

[vars]
domain = ["yourdomain.com"]    # Your email domain
admin = "admin@yourdomain.com" # Admin email
jwt_secret = "your-secure-key" # Encryption secret

3.4 Deployment Commands

# Deploy to Cloudflare
npm run deploy

# Initialize database
Access https://yourdomain.com/api/init/your-jwt-secret

3.5 Email Routing Setup

  1. Cloudflare dashboard → Email → Email Routing
  2. Create rule: *@yourdomain.com → Your Worker

3.6 Resend Configuration

  1. Register at Resend.com
  2. Add/verify your domain
  3. Create API key → Insert in Cloud Mail admin
  4. Configure webhook: https://yourdomain.com/api/webhooks

Advanced Usage Techniques

4.1 Multi-Domain Configuration

Support multiple domains:

[vars]
domain = ["business.com", "personal.net"]

4.2 Email Forwarding Rules

Forward urgent emails to Telegram:

// Add to email processing logic
if (mail.subject.includes("URGENT")) {
  forwardToTelegram(mail);
}

4.3 Storage Optimization

graph LR
A[New Attachment] --> B{Size Check}
B -- <5MB --> C[Store in R2]
B -- >5MB --> D[Generate Pre-Signed URL]

Local Development Guide

5.1 Launch Development Environment

npm run dev
# Access http://localhost:8787

5.2 Initialize Local Database

Access http://127.0.0.1:8787/api/init/your-jwt-secret

5.3 Development-Specific Settings

# Development mode only
R2 Domain = http://127.0.0.1:8787/api/file
Disable Turnstile verification

Project Structure Overview

cloud-mail
├── mail-worker         # Backend core
│   ├── src/api         # REST endpoints
│   ├── src/email       # Email processors
│   ├── src/entity      # Data models
│   └── src/service     # Business logic
└── mail-vue            # Frontend
    ├── src/views       # UI components
    ├── src/store       # State management
    └── src/request     # API handlers

Key files:

  • mail-worker/src/email/receiver.js – Email ingestion
  • mail-vue/src/views/mail/Compose.vue – Email composer
  • mail-worker/src/service/user.service.js – User management

Frequently Asked Questions

Q: What’s the ongoing cost?
$0! Cloudflare’s free tier covers Workers, D1, and R2. Resend’s 3k monthly emails suit personal use.

Q: How many users can it support?
Tested performance:

  • 100 active users: 500 daily emails
  • D1 database: Up to 500MB data
  • Ideal for small-medium teams

Q: What’s email deliverability rate?
Through Resend:

  • 99.5% success rate

  • Professional infrastructure
  • DKIM/SPF authentication

Q: How to backup data?
Recommended approach:

# Export D1 database
wrangler d1 export your-db --output ./backup.sql

# Automated GitHub backups
0 2 * * * /path/to/backup_script.sh

Q: Mobile experience?

Fully responsive:

  • Mobile-optimized UI
  • Touch-friendly controls
  • Attachment previews

Future Development Roadmap

  1. Auto-categorization: Content-based sorting
  2. Collaboration Spaces: Shared email threads
  3. Calendar Integration: Email-to-event conversion
  4. Multi-language Support: English/Chinese UI

Conclusion: Launch Your Professional Email Service

Cloud Mail eliminates technical and financial barriers to email self-hosting. With this guide, you’ve learned:

  • Deployment of free email infrastructure
  • Enterprise feature configuration
  • Best practices for maintenance

GitHub Repository: https://github.com/LaziestRen/cloud-mail
Community: Telegram Group

Implement your professional email solution in under 30 minutes. Share your experiences and innovations with our growing community!

Exit mobile version