Deploying Mail-in-a-Box
Introduction
Mail-in-a-Box is a comprehensive, self-hosted email server solution that bundles everything needed to run your own mail server into an easy-to-deploy package. It takes the complexity out of self-hosted email by automatically configuring Postfix, Dovecot, Roundcube, and dozens of other components that work together for secure, reliable email hosting.
Designed for non-experts who want to take control of their email, Mail-in-a-Box handles everything from basic email to calendars, contacts, and file synchronization. The web-based admin panel makes management straightforward, while the system automatically configures DKIM, SPF, DMARC, and other email security standards.
Key highlights of Mail-in-a-Box:
- Complete Email Solution: SMTP, IMAP, webmail, and admin interface in one package
- Roundcube Webmail: Modern webmail interface accessible from any browser
- Calendar and Contacts: CalDAV and CardDAV synchronization
- Nextcloud Integration: Built-in file sync and sharing
- Automatic Security: DKIM, SPF, DMARC, and TLS configured automatically
- DNS Server: Built-in DNS management for your mail domain
- Spam Filtering: SpamAssassin integration for spam protection
- Admin Panel: Web-based administration for users and domains
- Status Checks: System health monitoring and recommendations
- Let’s Encrypt: Automatic SSL certificate provisioning
- Backup System: Built-in encrypted backup functionality
- Open Source: CC0 public domain dedication
This guide walks through deploying Mail-in-a-Box on Klutch.sh using Docker, configuring your email domain, and managing your mail server.
Why Deploy Mail-in-a-Box on Klutch.sh
Deploying Mail-in-a-Box on Klutch.sh provides several advantages:
Simplified Deployment: Klutch.sh handles the complexity of deploying a complete mail stack.
Persistent Storage: Attach persistent volumes for mailboxes, databases, and configuration.
GitHub Integration: Connect your configuration repository directly from GitHub.
Scalable Resources: Allocate CPU and memory based on email volume and user count.
Custom Domains: Use your own domain with proper DNS configuration.
Always-On Availability: Your mail server remains accessible 24/7.
Prerequisites
Before deploying Mail-in-a-Box on Klutch.sh, ensure you have:
- A Klutch.sh account
- A GitHub account with a repository for your configuration
- Basic familiarity with Docker and containerization concepts
- A domain name with ability to configure DNS records
- Understanding of email protocols and deliverability requirements
Understanding Mail-in-a-Box Architecture
Mail-in-a-Box integrates many components:
Postfix: SMTP server for sending and receiving mail.
Dovecot: IMAP server for mail access and storage.
Roundcube: Web-based email client.
Nextcloud: Calendar, contacts, and file sync.
nginx: Web server and reverse proxy.
PostgreSQL: Database backend.
SpamAssassin: Spam filtering.
nsd: Authoritative DNS server.
Fail2ban: Intrusion prevention.
Preparing Your Repository
To deploy Mail-in-a-Box on Klutch.sh, create a GitHub repository containing your configuration.
Repository Structure
mailinabox-deploy/├── Dockerfile├── README.md└── .dockerignoreCreating the Dockerfile
Create a Dockerfile in the root of your repository:
FROM ubuntu:22.04
# Prevent interactive promptsENV DEBIAN_FRONTEND=noninteractive
# Install dependenciesRUN apt-get update && apt-get install -y \ curl \ wget \ git \ sudo \ && rm -rf /var/lib/apt/lists/*
# Set environment variablesENV PRIMARY_HOSTNAME=box.example.comENV NONINTERACTIVE=1
# Clone Mail-in-a-BoxRUN git clone https://github.com/mail-in-a-box/mailinabox.git /mailinabox
WORKDIR /mailinabox
# Create directoriesRUN mkdir -p /home/user-data
# Expose portsEXPOSE 25 53 53/udp 80 443 587 993 4190
# Health checkHEALTHCHECK --interval=60s --timeout=30s --start-period=300s --retries=3 \ CMD curl -f http://localhost/admin/me || exit 1
CMD ["bash", "-c", "setup/start.sh && tail -f /var/log/syslog"]Creating the .dockerignore File
Create a .dockerignore file:
.git.github*.mdLICENSE.gitignore*.log.DS_Store.env.env.localEnvironment Variables Reference
| Variable | Required | Default | Description |
|---|---|---|---|
PRIMARY_HOSTNAME | Yes | - | Hostname for the mail server (box.example.com) |
NONINTERACTIVE | No | 0 | Set to 1 for non-interactive setup |
SKIP_NETWORK_CHECKS | No | 0 | Skip network connectivity checks |
Deploying Mail-in-a-Box on Klutch.sh
Once your repository is prepared, follow these steps to deploy:
- Port 25 for SMTP
- Port 53 for DNS (TCP/UDP)
- Port 80 for HTTP
- Port 443 for HTTPS
- Port 587 for Submission
- Port 993 for IMAPS
- Port 4190 for Sieve
- Detect your Dockerfile automatically
- Build the container image
- Attach the persistent volumes
- Start the Mail-in-a-Box container
Configure DNS Records
Before deployment, set up DNS records:
# NS records (point to your box)example.com. NS box.example.com.
# A record for the boxbox.example.com. A your-server-ip
# MX recordexample.com. MX 10 box.example.com.
# Additional records will be shown in admin panelPush Your Repository to GitHub
Initialize your repository and push to GitHub:
git initgit add Dockerfile .dockerignore README.mdgit commit -m "Initial Mail-in-a-Box deployment"git remote add origin https://github.com/yourusername/mailinabox-deploy.gitgit push -u origin mainCreate a New Project on Klutch.sh
Navigate to the Klutch.sh dashboard and create a new project. Give it a descriptive name like “mailinabox” or “email-server”.
Create a New App
Within your project, create a new app. Connect your GitHub account if you haven’t already, then select your Mail-in-a-Box repository.
Configure Traffic
Mail-in-a-Box requires multiple ports:
Note: Consult Klutch.sh documentation for full port configuration.
Set Environment Variables
In the environment variables section, add:
| Variable | Value |
|---|---|
PRIMARY_HOSTNAME | box.example.com |
NONINTERACTIVE | 1 |
Attach Persistent Volumes
Add the following volumes:
| Mount Path | Recommended Size | Purpose |
|---|---|---|
/home/user-data | 100+ GB | All user data, mailboxes, and databases |
Deploy Your Application
Click Deploy to start the build process. Klutch.sh will:
Complete Initial Setup
Access https://box.example.com/admin to complete setup and create your first admin account.
Initial Configuration
Admin Panel Access
Access the admin panel at https://box.example.com/admin:
- Create your admin email account during first login
- This account becomes the system administrator
- Use a strong password
DNS Configuration
The admin panel shows required DNS records:
- Navigate to System > External DNS
- Copy all required records
- Configure them with your domain registrar
- Wait for DNS propagation
- Verify with System Status
Adding Users
Create email accounts:
- Go to Mail > Users
- Click Add User
- Enter email address and password
- Set user privileges if needed
- Click Add User
Adding Aliases
Create email aliases:
- Go to Mail > Aliases
- Enter alias address
- Enter destination address(es)
- Click Add Alias
Using Mail Services
Webmail
Access email through Roundcube:
- Navigate to
https://box.example.com/mail - Log in with your email credentials
- Full-featured webmail interface
Calendar and Contacts
Use CalDAV and CardDAV:
- Go to
https://box.example.com/cloud - Log in with your email credentials
- Create calendars and contacts
- Sync with mobile devices
Desktop Client Setup
Configure email clients:
| Setting | Value |
|---|---|
| IMAP Server | box.example.com |
| IMAP Port | 993 (SSL) |
| SMTP Server | box.example.com |
| SMTP Port | 587 (STARTTLS) |
| Username | full email address |
System Status
Health Monitoring
Check system health:
- Navigate to System > Status Checks
- Review all status indicators
- Green checks indicate proper configuration
- Address any warnings or errors
Common Status Issues
- DNS Records: Ensure all required records exist
- Reverse DNS: PTR record must match hostname
- Blacklists: Check IP reputation
- TLS Certificates: Verify certificate validity
Production Best Practices
Security Recommendations
- Strong Passwords: Enforce strong passwords for all accounts
- Regular Updates: Keep the system updated
- Monitor Logs: Review logs for suspicious activity
- Backup Encryption: Enable encrypted backups
- Access Limits: Restrict admin panel access
Deliverability
Ensure emails reach recipients:
- PTR Record: Matching reverse DNS
- IP Reputation: Clean IP address
- Authentication: DKIM, SPF, DMARC configured
- Content: Avoid spammy content
- Volume: Gradual sending increase
Backup Strategy
Protect your email data:
- Built-in Backups: Enable in admin panel
- Backup Encryption: Use strong encryption password
- Remote Storage: Configure remote backup destination
- Regular Testing: Test backup restoration
Troubleshooting Common Issues
Mail Not Sending
Symptoms: Outgoing emails fail or bounce.
Solutions:
- Check System Status for errors
- Verify DNS records are correct
- Review mail logs for specific errors
- Check IP reputation and blacklists
Mail Not Receiving
Symptoms: Incoming emails not arriving.
Solutions:
- Verify MX records point to server
- Check spam folder for filtered messages
- Review mail logs for delivery issues
- Verify user mailbox exists
Certificate Errors
Symptoms: SSL certificate warnings.
Solutions:
- Check Let’s Encrypt status in admin
- Verify DNS A record for hostname
- Wait for certificate issuance
- Check certificate renewal logs
Webmail Not Loading
Symptoms: Cannot access Roundcube.
Solutions:
- Verify nginx is running
- Check web server logs
- Clear browser cache
- Review PHP error logs
Additional Resources
- Mail-in-a-Box Official Website
- Mail-in-a-Box Setup Guide
- Mail-in-a-Box GitHub
- Mail-in-a-Box Community Forum
- Klutch.sh Persistent Volumes
- Klutch.sh Deployments
Conclusion
Deploying Mail-in-a-Box on Klutch.sh gives you a complete, self-hosted email solution with webmail, calendars, contacts, and file sync. The combination of Mail-in-a-Box’s all-in-one approach and Klutch.sh’s deployment platform means you can focus on using email rather than configuring dozens of mail server components.
With automatic security configuration, built-in webmail, and comprehensive admin tools, Mail-in-a-Box makes self-hosted email accessible to everyone. Whether you’re taking control of personal email or setting up email for a small organization, Mail-in-a-Box on Klutch.sh provides a reliable, feature-complete solution.