Mail-in-a-Box turns a fresh Ubuntu server into a fully functional email host in under 15 minutes. If you have been looking for a way to escape Big Tech email surveillance while maintaining full control over your communication infrastructure, this guide walks you through the complete setup process.
Why Run Your Own Email Server
Commercial email providers scan your messages for advertising purposes. Running your own Mail-in-a-Box instance gives you end-to-end control over your data, custom domain email addresses, and zero algorithmic profiling. For developers managing multiple projects or businesses requiring professional email presence, self-hosting eliminates monthly per-mailbox fees while providing unlimited accounts.
Prerequisites
Before beginning the installation, ensure you have:
- A clean Ubuntu 20.04 or 22.04 VPS with at least 2GB RAM and 20GB storage
- A registered domain name with access to DNS settings
- A static IP address or reverse DNS configured
- SSH access with root privileges
DigitalOcean, Linode, and Hetzner all offer suitable VPS plans starting at $5/month. For email deliverability, choose a provider with a positive sending reputation.
Initial Server Setup
Connect to your server via SSH and update the system packages:
ssh root@your-server-ip
apt update && apt upgrade -y
Set your server hostname to your domain name:
hostnamectl set-hostname mail.yourdomain.com
Create a non-root user with sudo privileges for daily operations:
adduser admin
usermod -aG sudo admin
Installing Mail-in-a-Box
Mail-in-a-Box provides an automated installation script that handles all configuration:
curl -s https://mailinabox.email/setup.sh | sudo bash
During installation, the script prompts for:
- Your email address (admin@yourdomain.com becomes your primary inbox)
- Your domain name
- Confirmation to proceed
The installation takes 10-15 minutes and automatically configures:
- Postfix mail transfer agent
- Dovecot IMAP/POP3 server
- Roundcube webmail interface
- SpamAssassin filtering
- OpenDKIM for email authentication
- Let’s Encrypt SSL certificates
DNS Configuration
After installation, Mail-in-a-Box displays the DNS records you need to create. Log into your domain registrar’s DNS management panel and add these records:
MX Record
Type: MX
Host: @
Value: mail.yourdomain.com
Priority: 10
A Record
Type: A
Host: mail
Value: your-server-ip
SPF Record
Type: TXT
Host: @
Value: v=spf1 mx -all
DKIM Record
Copy the DKIM key displayed after installation and create a TXT record with selector mail:
Type: TXT
Host: mail._domainkey
Value: v=DKIM1; k=rsa; p=your-dkim-key-here
DMARC Record
Type: TXT
Host: _dmarc
Value: v=DMARC1; p=quarantine; rua=mailto:dmarc@yourdomain.com
Allow 24-48 hours for DNS propagation before testing email delivery.
Accessing Your Email Server
Once DNS propagates, access your Mail-in-a-Box through:
- Webmail: https://mail.yourdomain.com/mail
- Admin Panel: https://mail.yourdomain.com/admin
The admin panel lets you create additional mailboxes, configure aliases, and manage DNS settings. Default credentials use the email address and password you specified during installation.
Configuring Email Clients
Mail-in-a-Box supports standard IMAP and SMTP protocols for any email client:
IMAP Settings
Server: mail.yourdomain.com
Port: 993
Encryption: SSL/TLS
SMTP Settings
Server: mail.yourdomain.com
Port: 587
Encryption: STARTTLS
Authentication: Normal password
Thunderbird, Apple Mail, and Microsoft Outlook all connect using these settings.
Hardening Your Mail Server
After basic setup, implement these security improvements:
Enable Two-Factor Authentication
Access the admin panel, navigate to Users, and enable 2FA for each mailbox using the TOTP standard.
Configure Fail2Ban
Mail-in-a-Box includes Fail2Ban by default, which blocks brute force attempts against SMTP and IMAP login forms.
Restrict SSH Access
Modify /etc/ssh/sshd_config to disable password authentication and permit only key-based login:
PasswordAuthentication no
PermitRootLogin no
Restart the SSH service after making changes.
Set Up Backup
Mail-in-a-Box includes automated backup to external storage. Configure S3-compatible storage in the admin panel under System > Backup.
Troubleshooting Common Issues
Email Not Delivering to Gmail or Outlook
Check your sender reputation at mail-tester.com. Ensure SPF, DKIM, and DMARC all pass. Gmail requires postmaster@yourdomain.com to exist—create this alias in the admin panel.
SSL Certificate Errors
Force certificate renewal:
sudo mailinabox ssl letsencrypt
IMAP Connection Timeouts
Verify your firewall allows ports 993 and 587:
sudo ufw status
Adding Secondary Domains
To host email for additional domains, navigate to Mail > External Domains in the admin panel. Enter the new domain and follow the DNS configuration steps. Mail-in-a-Box handles virtual aliasing automatically.
Automation with the API
Mail-in-a-Box exposes a REST API for programmatic management. Generate an API key in the admin panel under System > API Keys:
curl -X POST https://mail.yourdomain.com/admin/mail/users \
-H "Authorization: Bearer your-api-key" \
-H "Content-Type: application/json" \
-d '{"email": "newuser@yourdomain.com", "password": "secure-password"}'
Use this for provisioning accounts in scripts or integrating with user management systems.
Maintenance and Updates
Mail-in-a-Box includes an automated update mechanism. Check for updates through the admin panel or via command line:
sudo mailinabox version
sudo mailinabox update
Monitor disk space and memory usage regularly—email servers with active mailboxes consume resources quickly.
Running your own email server requires ongoing attention but provides unmatched privacy and control. Mail-in-a-Box reduces the complexity significantly while remaining fully customizable for advanced use cases.
Related Articles
- Set Up Own Email Server For Maximum Privacy Using Mail In
- How To Set Up Self Hosted Matrix Synapse Server For Private
- How To Set Up Proton Mail Bridge With Local Email Client For
- Set Up Catch All Email Domain For Unlimited Private Aliases
- to Physical Mail Privacy: Preventing Address Harvesting
Built by theluckystrike — More at zovo.one