starzeus/mailrelay-smtp-server

By starzeus

Updated over 1 year ago

Node based SMTP server with rule engine

Image
Message queues
Developer tools
Monitoring & observability
0

561

starzeus/mailrelay-smtp-server repository overview

MailRelay SMTP Server

A modern, feature-rich SMTP server with a beautiful web UI for managing and processing emails based on customizable rules.

Features

1. SMTP Server
  • Lightweight SMTP server listening on port 2525
  • Accepts and processes incoming emails
  • No authentication required (perfect for development/testing)
  • Support for attachments and HTML content
  • Maximum message size: 30MB
2. Mail UI Features
  • Modern Web Interface: Clean, responsive design built with Next.js and Tailwind CSS
  • Real-time Email Viewing: See incoming emails instantly
  • Email Organization:
    • List view with search functionality
    • Detailed email viewer with HTML support
    • Attachment handling
    • Mark as read/unread
3. Rule Engine
  • Flexible Rule Creation:
    • Match by sender, recipient, subject, content
    • Support for regex patterns
    • Multiple conditions with AND/OR operators
  • Actions:
    • Forward emails to other addresses
    • Send to webhook endpoints
    • Push to Kafka topics
    • Execute custom JavaScript code
  • Rule Management:
    • Enable/disable rules
    • Test rules against sample emails
    • View processed emails by rule

Environment Variables

Required Environment Variables
# Database Configuration
DATABASE_URL="file:/path/to/your/database.db"  # SQLite database path

# SMTP Server Configuration
SMTP_HOST="0.0.0.0"        # SMTP server host, use 0.0.0.0 to accept all connections
SMTP_PORT="2525"           # SMTP server port
SMTP_MAX_SIZE="31457280"   # Maximum email size in bytes (default: 30MB)

# Web UI Configuration
NEXT_PUBLIC_HOST="0.0.0.0" # Web UI host
PORT="3000"                # Web UI port
Optional Environment Variables
# Kafka Integration (Optional)
KAFKA_BROKERS="localhost:9092"     # Comma-separated list of Kafka brokers
KAFKA_CLIENT_ID="email-rules"      # Kafka client ID

# Email Forwarding Configuration (Optional)
FORWARD_SMTP_HOST="smtp.gmail.com" # SMTP server for forwarding emails
FORWARD_SMTP_PORT="587"           # SMTP port for forwarding
FORWARD_SMTP_USER="[email protected]" # SMTP username
FORWARD_SMTP_PASS="your-password"  # SMTP password
FORWARD_SMTP_SECURE="true"        # Use TLS

# Development Options
NODE_ENV="production"              # Set to 'development' for development mode
DEBUG="smtp*"                      # Enable SMTP server debugging

Quick Start

Using Docker
# Pull the image
docker pull ${{ secrets.DOCKER_USERNAME }}/mailrelay-smtp-server:latest

# Run with environment variables
docker run -d \
  -p ${PORT:-3000}:3000 \
  -p ${SMTP_PORT:-2525}:2525 \
  -e DATABASE_URL=file:/app/data/mailrelay.db \
  -e SMTP_HOST=0.0.0.0 \
  -e SMTP_PORT=2525 \
  -e NEXT_PUBLIC_HOST=0.0.0.0 \
  -e PORT=3000 \
  -v $(pwd)/data:/app/data \
  --name mailrelay \
  ${{ secrets.DOCKER_USERNAME }}/mailrelay-smtp-server:latest
Using Docker Compose
version: '3.8'
services:
  mailrelay:
    image: ${{ secrets.DOCKER_USERNAME }}/mailrelay-smtp-server:latest
    ports:
      - "${PORT:-3000}:3000"        # Web UI
      - "${SMTP_PORT:-2525}:2525"   # SMTP Server
    environment:
      - DATABASE_URL=file:/app/data/mailrelay.db
      - SMTP_HOST=0.0.0.0
      - SMTP_PORT=2525
      - SMTP_MAX_SIZE=31457280
      - NEXT_PUBLIC_HOST=0.0.0.0
      - PORT=3000
      - NODE_ENV=production
      # Add optional variables as needed
      - KAFKA_BROKERS=${KAFKA_BROKERS}
      - FORWARD_SMTP_HOST=${FORWARD_SMTP_HOST}
      - FORWARD_SMTP_PORT=${FORWARD_SMTP_PORT}
      - FORWARD_SMTP_USER=${FORWARD_SMTP_USER}
      - FORWARD_SMTP_PASS=${FORWARD_SMTP_PASS}
    volumes:
      - ./data:/app/data  # Persist database
Example .env File

Create a .env file in the root directory:

# Required Configuration
DATABASE_URL=file:/app/data/mailrelay.db
SMTP_HOST=0.0.0.0
SMTP_PORT=2525
NEXT_PUBLIC_HOST=0.0.0.0
PORT=3000

# Optional Configuration
KAFKA_BROKERS=localhost:9092
FORWARD_SMTP_HOST=smtp.gmail.com
FORWARD_SMTP_PORT=587
[email protected]
FORWARD_SMTP_PASS=your-app-specific-password
FORWARD_SMTP_SECURE=true

Usage

  1. Access the Web UI:

    • Open http://localhost:3000 in your browser
    • You'll see the main dashboard with email list and viewer
  2. Send Test Emails:

    # Using telnet
    telnet localhost 2525
    
    # Using swaks
    swaks --to [email protected] --from [email protected] --server localhost --port 2525
    
    # Using curl
    curl smtp://localhost:2525 --mail-from [email protected] --mail-rcpt [email protected] --upload-file email.txt
    
  3. Create Rules:

    • Click "Rules" in the navigation
    • Click "New Rule"
    • Configure conditions and actions
    • Enable the rule
    • Test with sample emails

Development

# Clone the repository
git clone https://github.com/yourusername/mailrelay-smtp-server.git

# Install dependencies
npm install

# Initialize database
npx prisma generate
npx prisma migrate dev

# Start development servers
npm run dev

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

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

Tag summary

Content type

Image

Digest

sha256:453f08913

Size

410.5 MB

Last updated

over 1 year ago

docker pull starzeus/mailrelay-smtp-server:sha-ddfe86c