Skip to content

Megallm/Raw

Repository files navigation

Bun PostgreSQL Redis Cloudflare R2 Apache Kafka Docker Next JS TailwindCSS Drizzle

Raw Mail

Open Source Multi-Tenant Email Platform

License: MIT

Features

  • Custom Domains - Add and verify your own domains
  • Full Email Server - Built-in SMTP/IMAP with DKIM signing
  • Multi-Tenant - Manage organizations and users
  • Object Storage - Cloudflare R2 for attachments
  • Real-time - Kafka event streaming
  • Analytics - Dashboard with metrics

Tech Stack

Runtime & Framework

  • Bun, Hono, Next.js 15

Database & Cache

  • PostgreSQL, Drizzle ORM, Redis

Storage & Messaging

  • Cloudflare R2, Apache Kafka

Email

  • Custom SMTP/IMAP servers, DKIM authentication

Payments

  • DodoPayments integration

Quick Start

Prerequisites

  • Bun 1.1.34+
  • PostgreSQL 14+
  • Redis 7+

Installation

git clone https://github.com/Bas3line/rawmail.git
cd rawmail
bun install

Environment Setup

apps/api/.env:

PORT=3001
DATABASE_URL=postgresql://user:password@localhost:5432/rawemail
REDIS_URL=redis://localhost:6379
JWT_SECRET=your-secret-key

MAIL_SERVER_HOSTNAME=mail.yourdomain.com
MAIL_SERVER_IP=your-server-ip

R2_ACCOUNT_ID=your-cloudflare-account-id
R2_ACCESS_KEY_ID=your-access-key
R2_SECRET_ACCESS_KEY=your-secret-key
R2_BUCKET_NAME=rmail-attachments
R2_PUBLIC_URL=https://pub-xxxxx.r2.dev

apps/web/.env:

NEXT_PUBLIC_API_URL=http://localhost:3001

Database Migration

cd packages/database
bun run generate
bun run migrate

Start Development

cd apps/api && bun run dev
cd apps/web && bun run dev

Open http://localhost:3000

Docker (Recommended)

# Copy environment template
cp .env.example .env

# Edit .env with your configuration
nano .env

# Build and run with docker-compose
docker-compose up -d

# View logs
docker-compose logs -f app

# Stop services
docker-compose down

API Overview

Auth: /api/auth/register, /api/auth/login Domains: /api/domains, /api/domains/:id/verify Emails: /api/emails, /api/emails/:id Analytics: /api/analytics/stats, /api/analytics/email-volume

DNS Configuration

When adding a domain, configure these records:

  • MX - Mail server routing
  • SPF - Sender authorization
  • DKIM - Email signing
  • DMARC - Email policy
  • TXT - Domain verification

Production Deployment

Docker Single Container

The unified Dockerfile builds and runs both API and web services in a single container:

# Set environment variables
export DATABASE_URL=postgresql://user:password@host:5432/dbname
export JWT_SECRET=your-secret-key
export R2_ACCOUNT_ID=your-account-id
# ... set other vars from .env.example

# Build with environment
docker build --build-arg DATABASE_URL="$DATABASE_URL" -t rmail:latest .

# Run container
docker run -d \
  -p 3000:3000 \
  -p 3001:3001 \
  -e DATABASE_URL="$DATABASE_URL" \
  -e JWT_SECRET="$JWT_SECRET" \
  -e R2_ACCOUNT_ID="$R2_ACCOUNT_ID" \
  # ... add other environment variables
  -v $(pwd)/logs:/app/logs \
  --name rmail \
  rmail:latest

Docker Compose (Recommended)

# Includes Redis, Kafka, and Zookeeper
docker-compose up -d

The container automatically:

  • Runs database migrations
  • Tests database connectivity
  • Starts API server (port 3001)
  • Starts web server (port 3000)
  • Provides health checks
  • Outputs logs to /app/logs/

Core Repo Maintainer

Kira - kiraa@tuta.io

License

MIT License

About

Open Source Multi-Tenant Email Platform

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published