This guide provides step-by-step instructions for setting up and running the Sorting Office application, whether you're deploying to production or setting up a development environment.
- Prerequisites
- Getting the Code
- Building the Application
- Database Setup
- Configuration
- Schema Preparation
- Production Safety
- Starting the Application
- First Login
- Troubleshooting
⚠️ Warning
All the data in your production mail databases are at risk!
Before you let this application anywhere near your live mail databases, back them up.
Once up and runnig there is backup feature in this app as well.
You never know if there any accidental database commands or broken migration which deletes any existing data, so better be safe and do an initial manual backup.
Before you begin, ensure you have the following installed:
- Rust (latest stable version)
- MySQL (5.7+ or 8.0+)
- Docker and Docker Compose (optional, for containerized setup)
- Make (Optional, for using the provided Makefile commands)
-
Install rustup
sudo dnf install rustupor
brew install rustup -
Initialise rustup
rustup-init -
Install cargo binstall
cargo install cargo-binstall -
install Diesel CLI binary
cargo binstall diesel-cliOr MySQL only
cargo install diesel_cli --no-default-features --features mysql
- Fork the repository on GitHub
- Clone your fork:
git clone https://github.com/YOUR_USERNAME/sortingoffice.git cd sortingoffice
git clone https://github.com/flurdy/sortingoffice.git
cd sortingoffice- Go to the releases page
- Download the latest release archive
- Extract and navigate to the directory
# Install dependencies and build
cargo build --release
# The binary will be available at target/release/sortingoffice# Build the Docker image
docker build -t sortingoffice:latest .
# Or use the development Dockerfile
docker build -f Dockerfile.dev -t sortingoffice:dev .# Pull the official image (if available)
docker pull flurdy/sortingoffice:latestThe project includes Docker Compose configurations for easy database setup:
# Start all services (database + application)
docker-compose up -d
# Or start just the database
docker-compose up -d mysql-
Create the database:
CREATE DATABASE sortingoffice CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-
Create a user:
CREATE USER 'sortingoffice'@'%' IDENTIFIED BY 'your_secure_password'; GRANT ALL PRIVILEGES ON sortingoffice.* TO 'sortingoffice'@'%'; FLUSH PRIVILEGES;
-
Set environment variables:
export MYSQL_HOST=localhost export MYSQL_PORT=3306 export MYSQL_DATABASE=sortingoffice export MYSQL_USER=sortingoffice export MYSQL_PASSWORD=your_secure_password
# Create and setup production database
make prod-db-create
make prod-db-setup
# Or for development (includes seed data)
make dev-db-setupcp config/config.toml.example config/config.tomlOpen config/config.toml and update the following sections:
[[databases]]
id = "primary"
label = "Main Server"
url = "mysql://sortingoffice:your_password@localhost:3306/sortingoffice"[[admins]]
username = "admin"
# Generate a new password hash using the provided script
password_hash = "$2a$12$..." # Use scripts/generate_password_hash.sh
role = "edit"[global_features]
read_only = false
no_new_users = false
no_new_domains = false
no_password_updates = false
[databases.features]
read_only = false
no_seeding = true # Prevent seeding in production
no_migrations = true # Prevent migrations in production# Use the provided script
./scripts/generate_password_hash.sh "your_admin_password"Create a .env file for additional configuration:
cp env.example .envEdit .env to set:
ENVIRONMENT=production(for production safety)RUST_LOG=info(for logging)- Database connection details
The application expects certain fields in your database tables. If your existing database doesn't have these fields, you'll need to add them:
ALTER TABLE users
ADD COLUMN created DATETIME NULL,
ADD COLUMN modified DATETIME NULL;Apply the same pattern to all other relevant tables: domains, backups, aliases, relays, clients and relocated if present.
Note: The application will automatically set these timestamps when creating and updating records. Using NULL defaults is compatible with all MySQL versions and avoids issues with
CURRENT_TIMESTAMPlimitations in older MySQL versions.
# Run migrations
make migrate
# Or for all databases
make migrate-allThe application includes several safety features to prevent accidental data loss:
The following operations are automatically blocked in production:
- Seeding: Adding test/initial data
- Migrations: Database schema changes
- Database resets: Clearing all data
Set ENVIRONMENT=production to enable all safety features:
export ENVIRONMENT=productionIf you need to bypass protections:
# Force seeding
make seed-force
# Force migrations
make migrate-force
# Force database reset
make migrate-reset-force# Check compilation first
cargo check
# Run the application
cargo run
# Or run in release mode
cargo run --release# Start all services
docker-compose up -d
# View logs
docker-compose logs -f sortingofficedocker run -d \
--name sortingoffice \
-p 3000:3000 \
-v $(pwd)/config:/app/config \
-e ENVIRONMENT=production \
sortingoffice:latestCreate /etc/systemd/system/sortingoffice.service:
[Unit]
Description=Sorting Office
After=network.target mysql.service
[Service]
Type=simple
User=sortingoffice
WorkingDirectory=/opt/sortingoffice
ExecStart=/opt/sortingoffice/sortingoffice
Restart=always
Environment=ENVIRONMENT=production
[Install]
WantedBy=multi-user.targetEnable and start:
sudo systemctl enable sortingoffice
sudo systemctl start sortingoffice-
Access the application: Open your browser to
http://localhost:3000 -
Login with admin credentials:
- Username:
admin(or as configured in config.toml) - Password: The password you used to generate the hash
- Username:
-
Verify functionality:
- Check the dashboard loads
- Navigate to different sections
- Verify database connections are working
# Check database connectivity
make list-databases
# Test connection
mysql -h localhost -u sortingoffice -p sortingoffice# Validate configuration
cargo check
# Check configuration loading
RUST_LOG=debug cargo run# Ensure proper file permissions
chmod 644 config/config.toml
chmod 755 sortingoffice# Check what's using port 3000
lsof -i :3000
# Kill existing process
pkill -f sortingofficeexport RUST_LOG=debug
cargo run# View application logs
docker-compose logs sortingoffice
# View database logs
docker-compose logs mysql# View service logs
sudo journalctl -u sortingoffice -f- Check the documentation: Review other docs in the
/docsdirectory - Run tests: Ensure everything is working with
make test-unit - Check issues: Look for similar problems in the GitHub issues
- Create issue: If the problem persists, create a detailed issue report
After successful onboarding:
- Review the configuration: Ensure all settings match your requirements
- Set up monitoring: Consider adding health checks and monitoring
- Backup strategy: Implement regular database backups (see DATABASE_BACKUP.md)
- Security review: Ensure proper firewall and access controls
- Documentation: Update this guide with any environment-specific notes
- Change default passwords: Always change the default admin password
- Use HTTPS: Set up SSL/TLS for production deployments
- Firewall: Restrict access to the application port
- Database security: Use strong passwords and limit database access
- Regular updates: Keep the application and dependencies updated
For additional help, see the main README or other documentation in the /docs directory.