Mail-in-a-Box is an all-in-one mail server solution that turns a fresh Ubuntu VPS into a fully functional email server with SMTP, IMAP, webmail, spam filtering, DKIM signing, SPF, DMARC, and automatic TLS certificates. It is the easiest way to self-host email with production-grade features. This guide covers deployment, configuration, and ongoing management.
Prerequisites
- A fresh Ubuntu 22.04 LTS VPS with at least 1GB RAM (2GB recommended)
- A dedicated IPv4 address not on any email blacklists
- A domain name with DNS control
- Port 25 (SMTP) not blocked by your hosting provider
- Reverse DNS (PTR record) set to your mail hostname
Pre-Installation DNS Setup
Before installing, set up these DNS records:
# A record for your mail server
box.example.com. A your-server-ip
# PTR record (reverse DNS) — set via your hosting provider
your-server-ip → box.example.com
# MX record for your domain
example.com. MX 10 box.example.com.
Installation
# Set hostname
sudo hostnamectl set-hostname box.example.com
# Download and run the installer
curl -s https://mailinabox.email/setup.sh | sudo bash
The installer will ask for:
- Your email address (becomes the first admin account)
- The hostname for your mail server (e.g., box.example.com)
- Your region/timezone
Installation takes 10-15 minutes. It installs and configures Postfix, Dovecot, Roundcube, Nginx, OpenDKIM, SpamAssassin, Postgrey, fail2ban, and automatic Let's Encrypt certificates.
Post-Installation Configuration
Access the Admin Panel
# Admin panel URL
https://box.example.com/admin
# Login with the email/password you set during installation
DNS Configuration
The admin panel shows all required DNS records. If Mail-in-a-Box manages your DNS (recommended), records are set automatically. For external DNS, add these records manually:
# SPF record
example.com. TXT "v=spf1 mx -all"
# DKIM record (get the actual key from admin panel)
mail._domainkey.example.com. TXT "v=DKIM1; k=rsa; p=MIIBIjAN..."
# DMARC record
_dmarc.example.com. TXT "v=DMARC1; p=quarantine; rua=mailto:admin@example.com"
# MTA-STS (for enforcing TLS)
_mta-sts.example.com. TXT "v=STSv1; id=20250115"
# Autoconfig/Autodiscover records for email client auto-setup
autoconfig.example.com. CNAME box.example.com.
autodiscover.example.com. CNAME box.example.com.
Managing Email Accounts
# Via admin panel: Mail → Users
# Or via command line:
sudo mailinabox-tools user add user@example.com
sudo mailinabox-tools user password user@example.com
sudo mailinabox-tools user remove user@example.com
sudo mailinabox-tools user list
Email Aliases
# Admin panel → Mail → Aliases
# Create aliases like:
# info@example.com → user@example.com
# support@example.com → user1@example.com, user2@example.com
# @example.com → catchall@example.com (catch-all)
Email Client Configuration
# IMAP settings
Server: box.example.com
Port: 993
Security: SSL/TLS
Username: user@example.com
# SMTP settings
Server: box.example.com
Port: 587
Security: STARTTLS
Username: user@example.com
# Most email clients auto-configure using Autoconfig/Autodiscover
Webmail Access
Mail-in-a-Box includes Roundcube webmail:
https://box.example.com/mail
Spam Filtering
Mail-in-a-Box uses SpamAssassin with Postgrey (greylisting). Spam handling:
- Messages scoring above the spam threshold go to the Junk/Spam folder
- Greylisting delays first-time senders (reduces spam significantly)
- Users can train the spam filter by moving messages to/from the Spam folder
Backup and Restore
# Mail-in-a-Box creates daily encrypted backups
# Configure backup destination in admin panel → System → Backup
# Backup options:
# - Local (default) — stored on the server
# - Amazon S3 — recommended for off-site backups
# - rsync — to another server
# Restore from backup
sudo mailinabox-tools backup restore
Adding Additional Domains
- Add DNS records for the new domain pointing to your mail server
- Create email accounts using the new domain in the admin panel
- Mail-in-a-Box automatically generates DKIM keys and shows required DNS records
Monitoring and Maintenance
# Check mail queue
sudo postqueue -p
# View mail logs
sudo tail -f /var/log/mail.log
# Check system status
sudo mailinabox-tools status
# TLS certificate renewal happens automatically
# Check certificate status in admin panel → System → TLS
Security Hardening
- Mail-in-a-Box installs fail2ban automatically to block brute-force attempts
- UFW firewall is configured to allow only necessary ports
- TLS certificates are auto-renewed via Let's Encrypt
- Keep the system updated:
sudo apt update && sudo apt upgrade
Troubleshooting
# Email not being received
# 1. Check if port 25 is open
telnet box.example.com 25
# 2. Check DNS records
dig MX example.com
dig TXT example.com
# 3. Test email deliverability
# Use https://www.mail-tester.com — send an email to their test address
# 4. Check if IP is blacklisted
# Use https://mxtoolbox.com/blacklists.aspx
Best Practices
- Use a dedicated VPS for Mail-in-a-Box — do not run other services on it
- Set up reverse DNS (PTR record) before installation
- Configure off-site backups to S3 or another server immediately after setup
- Check email deliverability with mail-tester.com after setup
- Monitor your IP reputation and blacklist status monthly
- Keep the system updated with automatic security updates enabled
- Start with a warm-up period — send low volume initially to build IP reputation