Skip to content

sumansingh20/BharatMail

Repository files navigation

BhaMail - Self-Hosted Email Solution

BhaMail Logo

BhaMail is a production-ready, self-hosted email solution that provides Gmail-like functionality for individuals, teams, and organizations. Built with modern technologies and designed for easy deployment and maintenance.

🌟 Features

Core Email Features

  • Modern Web Interface - Gmail-like UI with responsive design
  • Mobile Apps - Native Flutter apps for iOS and Android
  • Email Protocols - Full SMTP, IMAP, and POP3 support
  • Conversation Threading - Smart email grouping and organization
  • Advanced Search - Powered by OpenSearch with full-text indexing
  • Attachment Support - File uploads with virus scanning
  • Rich Text Editor - HTML email composition with formatting
  • Labels and Filters - Customizable email organization
  • Multiple Accounts - Support for multiple email domains

Security & Authentication

  • Two-Factor Authentication (2FA) - TOTP support
  • DKIM Signing - Domain-based email authentication
  • JWT Tokens - Secure API authentication
  • Rate Limiting - Protection against abuse
  • Virus Scanning - ClamAV integration for attachments
  • Encrypted Storage - Secure password hashing

Administration

  • Admin Panel - Web-based administration interface
  • User Management - Create, edit, and manage user accounts
  • Domain Configuration - Multi-domain email hosting
  • Monitoring - Health checks and system metrics
  • Backup/Restore - Automated backup and recovery tools
  • API Access - RESTful API with OpenAPI documentation

Infrastructure

  • Docker Compose - Local development and testing
  • Kubernetes - Production-ready container orchestration
  • MinIO Storage - S3-compatible object storage for attachments
  • Redis Cache - Performance optimization and session management
  • PostgreSQL - Robust database with full ACID compliance
  • MailHog - Email testing and development tools

πŸš€ Quick Start

Prerequisites

  • Docker and Docker Compose
  • Node.js 18+ (for development)
  • Git

Local Development

  1. Clone the repository

    git clone https://github.com/your-org/bhamail.git
    cd bhamail
  2. Run setup script

    ./scripts/setup.sh
  3. Start services

    docker-compose up -d
  4. Seed database

    npm run seed
  5. Access the application

Production Deployment

See Production Deployment Guide for detailed instructions.

πŸ“ Project Structure

bhamail/
β”œβ”€β”€ api/                    # Backend API (Node.js + TypeScript)
β”‚   β”œβ”€β”€ src/               # Source code
β”‚   β”œβ”€β”€ migrations/        # Database migrations
β”‚   └── package.json
β”œβ”€β”€ web/                   # Frontend web app (React + Vite)
β”‚   β”œβ”€β”€ src/               # React components and pages
β”‚   β”œβ”€β”€ public/            # Static assets
β”‚   └── package.json
��── mobile/                # Mobile app (Flutter)
β”‚   β”œβ”€β”€ lib/               # Dart source code
β”‚   β”œβ”€β”€ android/           # Android-specific files
β”‚   β”œβ”€β”€ ios/               # iOS-specific files
β”‚   └── pubspec.yaml
β”œβ”€β”€ infra/                 # Infrastructure as code
β”‚   β”œβ”€β”€ k8s/               # Kubernetes manifests
β”‚   └── terraform/         # Terraform configurations
β”œβ”€β”€ docs/                  # Documentation
β”‚   β”œβ”€β”€ api.md             # API documentation
β”‚   β”œβ”€β”€ deployment.md      # Deployment guide
β”‚   └── architecture.md    # System architecture
β”œβ”€β”€ scripts/               # Utility scripts
β”‚   β”œβ”€β”€ setup.sh           # Development setup
β”‚   β”œβ”€β”€ seed.js            # Database seeding
β”‚   β”œβ”€β”€ backup.sh          # Backup script
β”‚   └── restore.sh         # Restore script
β”œβ”€β”€ tests/                 # Test suites
β”‚   β”œβ”€β”€ api/               # API tests
β”‚   β”œβ”€β”€ web/               # Web app tests
β”‚   └── e2e/               # End-to-end tests
└── docker-compose.yml     # Local development environment

πŸ› οΈ Technology Stack

Backend

  • Node.js - Runtime environment
  • TypeScript - Type-safe JavaScript
  • Express.js - Web framework
  • PostgreSQL - Primary database
  • Redis - Caching and queues
  • MinIO - Object storage (S3-compatible)
  • OpenSearch - Search and analytics
  • ClamAV - Antivirus scanning

Frontend

  • React - UI library
  • Vite - Build tool and dev server
  • Tailwind CSS - Utility-first CSS framework
  • Radix UI - Accessible component primitives
  • React Query - Data fetching and state management
  • React Router - Client-side routing

Mobile

  • Flutter - Cross-platform mobile framework
  • Dart - Programming language
  • Provider/Riverpod - State management
  • HTTP - API communication

Infrastructure

  • Docker - Containerization
  • Kubernetes - Container orchestration
  • Terraform - Infrastructure as code
  • GitHub Actions - CI/CD pipelines

πŸ“– Documentation

πŸ”§ Configuration

Environment Variables

# Database
DB_HOST=localhost
DB_PORT=5432
DB_NAME=bhamail
DB_USER=bhamail
DB_PASSWORD=bhamail123

# Redis
REDIS_HOST=localhost
REDIS_PORT=6379

# JWT
JWT_SECRET=your-super-secret-jwt-key
JWT_EXPIRES_IN=7d

# Mail
SMTP_HOST=mailhog
SMTP_PORT=1025
SMTP_SECURE=false

# Storage
MINIO_ENDPOINT=localhost:9000
MINIO_ACCESS_KEY=minioadmin
MINIO_SECRET_KEY=minioadmin
MINIO_BUCKET=bhamail-attachments

# Search
OPENSEARCH_HOST=localhost:9200

Docker Compose Services

Service Port Description
postgres 5432 PostgreSQL database
redis 6379 Redis cache and queues
minio 9000/9001 MinIO object storage
opensearch 9200 OpenSearch cluster
mailhog 1025/8025 Email testing (SMTP/Web)
clamav 3310 Antivirus scanning
api 3001 Backend API server
web 3000 Frontend web app

πŸ§ͺ Testing

API Tests

cd api
npm test
npm run test:coverage

Web Tests

cd web
npm test
npm run test:e2e

Integration Tests

npm run test:integration

🀝 Contributing

We welcome contributions! Please see our Contributing Guide for details.

Development Workflow

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/amazing-feature
  3. Make your changes
  4. Add tests for your changes
  5. Run the test suite: npm test
  6. Commit your changes: git commit -m 'Add amazing feature'
  7. Open a Pull Request

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ†˜ Support

🎯 Roadmap

Version 1.1 (Next Release)

  • Calendar integration
  • Contact management
  • Email templates
  • Mobile push notifications
  • Advanced spam filtering

Version 1.2 (Future)

  • End-to-end encryption (PGP)
  • Chat integration
  • File sharing and collaboration
  • Advanced analytics dashboard
  • Multi-language support

Version 2.0 (Long-term)

  • AI-powered email categorization
  • Video calls integration
  • Advanced workflow automation
  • Third-party app marketplace
  • Enterprise features (SSO, LDAP)

⭐ Sponsors

Thank you to our sponsors who make this project possible!

Become a sponsor and get your logo here.

πŸ† Acknowledgments


Made with ❀️ by the BhaMail team - Open Source Email Service

A production-grade, Gmail-like email service built with modern web technologies. BhaMail provides a complete email solution with web and mobile clients, focusing on privacy, security, and ease of deployment.

πŸš€ Quick Start

Prerequisites

  • Docker Desktop
  • Node.js 18+ (for development)
  • Git

Local Development Setup

  1. Clone and Setup
git clone <repository-url>
cd BhaMail
cp .env.example .env
  1. Start Services
docker-compose up -d
  1. Initialize Database and Seed Data
npm run setup
npm run seed
  1. Access the Application

πŸ“ Project Structure

BhaMail/
β”œβ”€β”€ api/                 # Node.js + TypeScript Backend
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ controllers/ # API controllers
β”‚   β”‚   β”œβ”€β”€ services/    # Business logic
β”‚   β”‚   β”œβ”€β”€ models/      # Database models
β”‚   β”‚   β”œβ”€β”€ middleware/  # Express middleware
β”‚   β”‚   β”œβ”€β”€ routes/      # API routes
β”‚   β”‚   └── utils/       # Utilities
β”‚   β”œβ”€β”€ migrations/      # Database migrations
β”‚   β”œβ”€β”€ tests/           # Backend tests
β”‚   └── package.json
β”œβ”€β”€ web/                 # React + Vite Frontend
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ components/  # React components
β”‚   β”‚   β”œβ”€β”€ pages/       # Page components
β”‚   β”‚   β”œβ”€β”€ services/    # API services
β”‚   β”‚   β”œβ”€β”€ hooks/       # Custom hooks
β”‚   β”‚   └── utils/       # Utilities
β”‚   β”œβ”€β”€ public/          # Static assets
β”‚   └── package.json
β”œβ”€β”€ mobile/              # Flutter Mobile App
β”‚   β”œβ”€β”€ lib/
β”‚   β”‚   β”œβ”€β”€ screens/     # Mobile screens
β”‚   β”‚   β”œβ”€β”€ widgets/     # Reusable widgets
β”‚   β”‚   └── services/    # API services
β”‚   └── pubspec.yaml
β”œβ”€β”€ infra/               # Infrastructure
β”‚   β”œβ”€β”€ docker-compose.yml
β”‚   β”œβ”€β”€ k8s/             # Kubernetes manifests
β”‚   └── helm/            # Helm charts
β”œβ”€β”€ docs/                # Documentation
β”œβ”€β”€ scripts/             # Utility scripts
└── tests/               # Integration & E2E tests

πŸ›  Technology Stack

Backend

  • API: Node.js + TypeScript + Express
  • Database: PostgreSQL
  • Cache: Redis
  • Queue: BullMQ
  • Search: OpenSearch
  • Storage: MinIO (S3-compatible)
  • Mail: MailHog (dev) / Postfix+Dovecot (prod)
  • Security: JWT, bcrypt, rate limiting
  • Monitoring: Prometheus + Grafana

Frontend

  • Web: React + Vite + TypeScript
  • Mobile: Flutter
  • PWA: Service Workers, offline support
  • UI: Tailwind CSS, shadcn/ui components

DevOps

  • Containers: Docker + Docker Compose
  • Orchestration: Kubernetes + Helm
  • CI/CD: GitHub Actions
  • Testing: Jest, Cypress, k6

πŸ”§ Development Commands

API Development

cd api
npm install
npm run dev          # Start development server
npm run build        # Build for production
npm run test         # Run tests
npm run migrate      # Run database migrations

Web Development

cd web
npm install
npm run dev          # Start development server
npm run build        # Build for production
npm run test         # Run tests
npm run preview      # Preview production build

Mobile Development

cd mobile
flutter pub get
flutter run          # Run on connected device
flutter build apk    # Build Android APK

πŸ“§ Core Features

Authentication & Security

  • βœ… Email/password signup and login
  • βœ… JWT + refresh token authentication
  • βœ… Password reset via email
  • βœ… Two-factor authentication (TOTP)
  • βœ… Rate limiting and account lockouts
  • βœ… CSRF protection and CORS configuration

Email Functionality

  • βœ… Compose, send, reply, forward emails
  • βœ… Conversation threading
  • βœ… Drafts auto-save
  • βœ… Attachments with virus scanning
  • βœ… Labels and folders
  • βœ… Email filters and rules
  • βœ… Full-text search with OpenSearch
  • βœ… Schedule send and snooze
  • βœ… Offline support via service workers

Admin & Enterprise

  • βœ… Multi-tenant support
  • βœ… User management admin panel
  • βœ… Quota management and monitoring
  • βœ… Audit logs and compliance features
  • βœ… Backup and restore procedures

Protocols & Integration

  • βœ… SMTP sending and receiving
  • βœ… IMAP/POP3 support documentation
  • βœ… SPF/DKIM/DMARC configuration
  • βœ… External client support (Outlook, Thunderbird)

🚒 Production Deployment

VPS Deployment (< $20/month)

See docs/production-ops.md for detailed instructions.

Kubernetes Deployment

helm install bhamail ./infra/helm/bhamail

πŸ“š Documentation

πŸ§ͺ Testing

Unit Tests

npm run test

Integration Tests

npm run test:integration

E2E Tests

npm run test:e2e

Load Testing

npm run test:load

πŸ” Security

BhaMail implements security best practices:

  • TLS encryption for all communications
  • Secure password storage with bcrypt/Argon2
  • JWT tokens with secure refresh mechanism
  • CSRF tokens and XSS protection
  • Rate limiting and DDoS protection
  • Virus scanning for attachments
  • Audit logging for compliance

🌍 Internationalization

Currently supported languages:

  • English (default)
  • Hindi (example implementation)

πŸ“„ License

MIT License - see LICENSE file for details.

🀝 Contributing

See CONTRIBUTING.md for development setup and contribution guidelines.

πŸ“ž Support

For support, please open an issue on GitHub or join our community discussions.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors