Email intermediate ⏱ 60 minutes

Mail-in-a-Box: Simple Email Server Setup

One-command email server deployment. Webmail, spam filtering, and DNS configuration included.

By Homelab Team • 2025-01-15
#mail-in-a-box#email#smtp#simple#all-in-one

Introduction

Mail-in-a-Box is the simplest way to run your own email server. It’s a one-command installation that turns a fresh Ubuntu server into a fully functional mail server with webmail, contacts, calendar, and automatic configuration. Perfect for homelab beginners or anyone who wants email hosting without complexity.

Why Choose Mail-in-a-Box?

One-Command Installation: Run a single setup script, answer a few questions, and you have a working mail server in 15-30 minutes. No complex Docker configurations or manual service setup required.

Automatic Everything: DNS configuration checks, SSL certificates, spam filtering, backups, and system updates are all automated. The system continuously monitors itself and warns you about any issues.

Opinionated and Tested: Mail-in-a-Box makes security and reliability decisions for you based on best practices. Everything is pre-configured to work together seamlessly.

Beginner-Friendly: Clean web admin interface with plain English explanations. No command-line expertise required for day-to-day management.

Free and Open Source: Developed and maintained by Joshua Tauberer with an active community. No licensing costs, vendor lock-in, or feature limitations.

What You’ll Get

  • Complete Email Server: SMTP, IMAP, and webmail with Roundcube
  • Calendar and Contacts: CardDAV and CalDAV for syncing across devices
  • Automatic SSL: Let’s Encrypt certificates automatically obtained and renewed
  • Spam Filtering: SpamAssassin integrated and pre-configured
  • Web Admin Panel: Manage domains, mailboxes, aliases, and settings
  • Automatic Backups: Daily encrypted backups to local storage or S3
  • DNS Management: Built-in DNS server with configuration guidance
  • Status Monitoring: Dashboard showing system health and configuration issues

What Mail-in-a-Box Is NOT

Not Highly Customizable: Mail-in-a-Box is opinionated. You cannot easily change underlying software components (Postfix, Dovecot versions, etc.). If you need deep customization, consider Mailcow instead.

Not for Multiple Servers: Mail-in-a-Box is designed for single-server deployments. No clustering or load balancing support.

Not Containerized: Runs directly on Ubuntu, not in Docker. This simplifies management but means less isolation between services.

Ideal Use Cases

Personal Email: Self-host your own [email protected] email address

Family Email: Manage mailboxes for family members from one interface

Small Organizations: Host email for small teams (up to 50-100 users)

Learning Platform: Understand how email servers work without complexity

Privacy-Conscious Users: Keep email under your control without third-party access

Prerequisites

Hardware Requirements

Minimum Configuration:

  • CPU: 1 core (2+ recommended)
  • RAM: 1GB (2GB+ recommended)
  • Storage: 10GB minimum (20GB+ recommended for mailboxes)
  • Network: Public static IP address with clean reputation

Recommended Configuration:

  • CPU: 2 cores
  • RAM: 4GB (comfortable for 10-20 users)
  • Storage: 50GB+ SSD
  • Network: 1Gbps connection

Storage Planning:

  • System and software: 5GB
  • Per-user mailbox: 1-5GB average
  • Backups: 1.5× mailbox size
  • Logs: 1-2GB

Software Requirements

Operating System: Ubuntu 22.04 LTS (REQUIRED - no other distros supported)

Mail-in-a-Box only supports the specific LTS versions of Ubuntu Server. Do not use:

  • Ubuntu Desktop
  • Other Ubuntu versions
  • Debian, CentOS, or other Linux distributions
  • Windows or macOS

Fresh Installation: Mail-in-a-Box must be installed on a completely fresh Ubuntu Server installation with no other software. It will modify system configuration and cannot coexist with other services.

Server Requirements

Public IP Address: Your server needs a public static IP address that is not on spam blacklists.

Clean IP Reputation: Check your IP at MXToolbox Blacklist Check before starting. Cloud providers like DigitalOcean, Vultr, Linode, and Hetzner typically provide clean IPs.

Reverse DNS Control: You must be able to set PTR (reverse DNS) records for your IP. Most VPS providers allow this through their control panel.

Domain Name: You need a domain name with DNS control to create required records.

Pre-Installation Checklist

# Verify Ubuntu version (must be 22.04)
lsb_release -a
# Should show: Ubuntu 22.04

# Check available RAM
free -h
# Should show at least 1GB total

# Check available disk space
df -h
# Should show at least 10GB free on root partition

# Verify system is up to date
sudo apt update
sudo apt upgrade -y

# Ensure hostname is set to FQDN
hostname -f
# Should return your mail server hostname like box.yourdomain.com

DNS Configuration

Configure DNS records before installation. Mail-in-a-Box will verify these during setup.

Required DNS Records

Replace yourdomain.com with your domain and YOUR-SERVER-IP with your server’s public IP.

A Record (Mail Server):

box.yourdomain.com.    300    IN    A    YOUR-SERVER-IP

A Record (Domain - points to same server):

yourdomain.com.    300    IN    A    YOUR-SERVER-IP

MX Record:

yourdomain.com.    300    IN    MX    10    box.yourdomain.com.

Reverse DNS (PTR Record): Contact your hosting provider to set reverse DNS for your IP to box.yourdomain.com.

Optional DNS Records

Mail-in-a-Box will auto-generate and manage these, but you can configure them manually:

SPF Record (TXT):

yourdomain.com.    300    IN    TXT    "v=spf1 mx -all"

DMARC Record (TXT):

_dmarc.yourdomain.com.    300    IN    TXT    "v=DMARC1; p=quarantine"

DKIM Record: Generated during installation (see Post-Installation DNS section)

DNS Verification

# Verify A record for mail server
dig box.yourdomain.com +short
# Should return: YOUR-SERVER-IP

# Verify MX record
dig yourdomain.com MX +short
# Should return: 10 box.yourdomain.com.

# Verify reverse DNS
dig -x YOUR-SERVER-IP +short
# Should return: box.yourdomain.com.

All records should resolve before proceeding.

Installation

Step 1: Prepare Ubuntu Server

Start with a fresh Ubuntu 22.04 LTS installation:

# Update system packages
sudo apt update && sudo apt upgrade -y

# Install required dependencies
sudo apt install -y curl git

# Set hostname to your mail server FQDN
sudo hostnamectl set-hostname box.yourdomain.com

# Verify hostname
hostname -f
# Should output: box.yourdomain.com

# Update /etc/hosts
echo "YOUR-SERVER-IP box.yourdomain.com box" | sudo tee -a /etc/hosts

IMPORTANT: The hostname MUST be a subdomain of your primary domain. Use box.yourdomain.com, mail.yourdomain.com, or similar.

Step 2: Run Installation Script

Mail-in-a-Box installation is a single command:

# Download and run setup script
curl -s https://mailinabox.email/setup.sh | sudo bash

The script will:

  1. Download Mail-in-a-Box source code
  2. Install system dependencies
  3. Configure services
  4. Install and configure email server components
  5. Set up SSL certificates
  6. Create initial admin account

Installation takes 15-30 minutes depending on server speed and network connection.

Step 3: Interactive Setup

The installer will prompt you for configuration:

Primary Hostname: Confirm box.yourdomain.com (auto-detected from system hostname)

Primary Domain: Enter your email domain: yourdomain.com

First Email Address: Enter admin email address: [email protected]

Email Password: Create strong password for admin account (12+ characters)

Country Code: Enter your two-letter country code (e.g., US, GB, DE)

Timezone: Confirm auto-detected timezone or enter manually (e.g., America/New_York)

Public IP Address: Confirm auto-detected public IP

After entering information, the installer automatically:

  • Installs Postfix, Dovecot, Roundcube, SpamAssassin
  • Configures SMTP, IMAP, DNS, and webmail
  • Obtains Let’s Encrypt SSL certificates
  • Sets up firewall rules
  • Creates admin account
  • Starts all services

Step 4: Verify Installation

Once installation completes, verify services are running:

# Check system status
sudo mailinabox
# Should show "Mail-in-a-Box is running"

# Check service status
sudo systemctl status postfix
sudo systemctl status dovecot
sudo systemctl status nginx

# Verify ports are listening
sudo ss -tlnp | grep -E ':25|:80|:143|:443|:587|:993'
# Should show services listening on mail ports

Step 5: Access Admin Panel

Open your browser and navigate to:

https://box.yourdomain.com/admin

Login Credentials:

  • Email: [email protected] (or whatever you entered during setup)
  • Password: Password you created during setup

You’ll see the Mail-in-a-Box admin dashboard with system status.

Step 6: Review System Status

The admin panel Status Checks page shows configuration issues:

  1. Navigate to System > Status Checks
  2. Review all checks - green checkmarks are good, yellow/red need attention
  3. Common initial warnings:
    • DNS records not yet configured (if you skipped pre-configuration)
    • Reverse DNS not set (contact hosting provider)
    • DKIM record not published (see next section)

Follow on-screen instructions to resolve any issues.

Post-Installation DNS Configuration

Mail-in-a-Box generates DKIM keys and provides complete DNS configuration instructions.

Get DNS Configuration

  1. Log into admin panel at https://box.yourdomain.com/admin
  2. Navigate to System > External DNS
  3. Mail-in-a-Box displays all required DNS records

You’ll see records for:

  • A records for mail server and subdomains
  • MX record for email routing
  • SPF record for sender authentication
  • DKIM record for email signing
  • DMARC record for policy enforcement
  • Additional records for webmail, autodiscover, etc.

Add DKIM Record

Most critical post-installation DNS record:

# Format shown in admin panel:
mail._domainkey.yourdomain.com.    300    IN    TXT    "v=DKIM1; h=sha256; k=rsa; p=VERY-LONG-PUBLIC-KEY-HERE"

Copy the entire DKIM record from the admin panel and create it in your DNS provider.

Note: DKIM public keys are very long (300+ characters). Some DNS providers split long TXT records into multiple strings - this is normal and expected.

Add Additional Records

Add all other records shown in System > External DNS to your DNS provider. Mail-in-a-Box color-codes records:

  • Green: Record is configured correctly
  • Yellow: Record exists but has wrong value
  • Red: Record is missing

Using Mail-in-a-Box as DNS Server (Optional)

Mail-in-a-Box includes a built-in DNS server. You can use it as your domain’s nameserver:

At Your Domain Registrar:

  1. Set nameservers to:
    • ns1.box.yourdomain.com
    • ns2.box.yourdomain.com

In Mail-in-a-Box:

  1. Navigate to System > Custom DNS
  2. Add A records for nameservers:
    • ns1.box.yourdomain.com → YOUR-SERVER-IP
    • ns2.box.yourdomain.com → YOUR-SERVER-IP

Mail-in-a-Box will automatically manage all DNS records including DKIM rotation.

Note: Using external DNS (Cloudflare, your registrar, etc.) is simpler and recommended for beginners.

Configuration

Create Additional Mailboxes

  1. Navigate to Mail > Users
  2. Click Add User

User Configuration:

  • Email address: [email protected]
  • Password: Generate strong password (or let user set on first login)
  • Privileges: Normal User (or Administrator for admin access)
  • Quota: Default is unlimited (or set specific quota in MB)

Click Add to create mailbox.

Bulk User Creation: For multiple users, create CSV file and use API (see Advanced section).

Create Email Aliases

Aliases forward email to existing mailboxes:

  1. Navigate to Mail > Aliases
  2. Click Add Alias

Alias Examples:

Alias Configuration:

Multiple Recipients: Enter multiple addresses comma-separated to forward to multiple mailboxes.

Catch-All Alias: Create alias @yourdomain.com (note the @ prefix) to catch all unrouted email for the domain.

Add Additional Domains

Host email for multiple domains:

  1. Navigate to Mail > Users
  2. Click Add User
  3. Enter email with new domain: [email protected]
  4. Mail-in-a-Box automatically creates the domain

DNS Configuration: After adding domain, check System > External DNS for DNS records required for the new domain.

Configure Spam Filter

Mail-in-a-Box uses SpamAssassin with pre-configured rules.

Adjust Spam Threshold:

# Edit SpamAssassin configuration
sudo nano /etc/spamassassin/local.cf

Add or modify:

# Spam threshold (default 5.0, lower = stricter)
required_score 5.0

# Whitelist trusted senders
whitelist_from *@trusted-domain.com
whitelist_from [email protected]

# Blacklist spam sources
blacklist_from *@spam-domain.com

Restart SpamAssassin:

sudo systemctl restart spampd

Spam Folder: Spam is automatically moved to Spam folder in each mailbox. Users can review and recover false positives.

Configure Backups

Mail-in-a-Box includes automatic daily backups.

Local Backup (Default):

Backups are stored in /home/user-data/backup/encrypted/

View Backup Status:

  1. Navigate to System > Backup Status
  2. See list of recent backups
  3. Verify backups are completing successfully

S3-Compatible Remote Backup:

Store backups on Amazon S3, Backblaze B2, or compatible storage:

  1. Navigate to System > Backup Status
  2. Click Configure Backups
  3. Select backup target: S3 Compatible

S3 Configuration:

  • Bucket: s3://your-bucket-name/mail-backups/
  • Access Key ID: Your S3 access key
  • Secret Access Key: Your S3 secret key
  • Region: Your bucket region (e.g., us-east-1)

Backblaze B2 Configuration:

  • Bucket: b2://your-bucket-name/mail-backups/
  • Access Key ID: Your B2 application key ID
  • Secret Access Key: Your B2 application key
  • Region: us-west-000 (or your B2 region)

Click Save to enable remote backups. Next backup will upload to remote storage.

Backup Retention: Mail-in-a-Box keeps backups for 30 days by default. Older backups are automatically deleted.

Enable Two-Factor Authentication

Enable 2FA for admin security:

  1. Navigate to Login in admin panel
  2. Click Enable Two-Factor Authentication
  3. Scan QR code with authenticator app (Authy, Google Authenticator, 1Password, etc.)
  4. Enter 6-digit verification code
  5. Save backup codes in secure location

Disable 2FA (if locked out):

# SSH into server
sudo management/cli.py user mfa disable [email protected]

SSL Certificate Management

Mail-in-a-Box automatically manages SSL certificates via Let’s Encrypt.

Check Certificate Status:

  1. Navigate to System > TLS Certificates
  2. View certificate expiration dates
  3. See certificate details and renewal status

Certificates auto-renew 30 days before expiration. No manual intervention required.

Force Certificate Renewal:

# Renew certificates manually
sudo management/ssl_certificates.py renew

Greylisting Configuration

Greylisting temporarily rejects email from unknown senders, reducing spam.

Enable/Disable Greylisting:

# Edit Postgrey configuration
sudo nano /etc/default/postgrey

Modify settings:

# Delay before accepting email (default 300 seconds = 5 minutes)
POSTGREY_OPTS="--delay=300"

# Disable greylisting entirely (not recommended)
# Comment out POSTGREY_OPTS line

Restart Postgrey:

sudo systemctl restart postgrey

Side Effect: Greylisting delays first email from new senders by 5 minutes. Subsequent emails are delivered immediately.

Email Client Configuration

Automatic Configuration

Mail-in-a-Box supports autodiscover/autoconfig for automatic client setup.

Thunderbird, Outlook, Mobile Devices:

  1. Add email account
  2. Enter email address: [email protected]
  3. Enter password
  4. Client automatically detects server settings

Manual Configuration

IMAP Settings (Receiving Email):

  • Server: box.yourdomain.com
  • Port: 993
  • Security: SSL/TLS
  • Username: Full email address ([email protected])
  • Password: Mailbox password

SMTP Settings (Sending Email):

  • Server: box.yourdomain.com
  • Port: 587
  • Security: STARTTLS
  • Authentication: Required
  • Username: Full email address ([email protected])
  • Password: Mailbox password

POP3 Settings (Alternative to IMAP):

  • Server: box.yourdomain.com
  • Port: 995
  • Security: SSL/TLS
  • Username: Full email address ([email protected])
  • Password: Mailbox password

Webmail Access

Users access webmail via Roundcube:

https://box.yourdomain.com/mail

Roundcube Features:

  • Clean, responsive webmail interface
  • Contact management
  • Email filters and folders
  • HTML email composer
  • Attachment support
  • Address book
  • Identity management

Mobile Device Configuration

iOS:

  1. Settings > Mail > Accounts > Add Account
  2. Select “Other”
  3. Enter email and password
  4. iOS auto-configures using autodiscover

Android:

  1. Open email app (Gmail app supports external IMAP)
  2. Add account > Other
  3. Enter email and password
  4. Android auto-configures using autoconfig

CalDAV/CardDAV Sync:

  • Server: box.yourdomain.com
  • Path: /cloud/dav.php
  • Username: Full email address
  • Password: Mailbox password

Syncs calendars and contacts to mobile devices.

Security Hardening

Firewall Configuration

Mail-in-a-Box configures firewall automatically using UFW.

View Firewall Rules:

sudo ufw status verbose

Default Open Ports:

  • 22/tcp (SSH)
  • 25/tcp (SMTP)
  • 53/tcp and 53/udp (DNS, if using Mail-in-a-Box DNS)
  • 80/tcp (HTTP, for Let’s Encrypt challenges)
  • 443/tcp (HTTPS)
  • 587/tcp (SMTP submission)
  • 993/tcp (IMAPS)
  • 995/tcp (POP3S)
  • 4190/tcp (Sieve)

Block Unnecessary Ports: All other ports are blocked by default.

SSH Hardening

Secure SSH access:

# Edit SSH configuration
sudo nano /etc/ssh/sshd_config

Recommended settings:

# Disable root login
PermitRootLogin no

# Disable password authentication (use SSH keys only)
PasswordAuthentication no

# Change default port (optional)
Port 2222

# Allow only specific users
AllowUsers yourusername

Restart SSH:

sudo systemctl restart sshd

If changing SSH port, update firewall:

sudo ufw allow 2222/tcp
sudo ufw delete allow 22/tcp

Fail2Ban Configuration

Mail-in-a-Box includes Fail2Ban to block brute-force attacks.

Check Banned IPs:

# View banned IPs for all jails
sudo fail2ban-client status

# View specific jail
sudo fail2ban-client status postfix
sudo fail2ban-client status dovecot

Unban IP Address:

sudo fail2ban-client set postfix unbanip IP-ADDRESS
sudo fail2ban-client set dovecot unbanip IP-ADDRESS

Whitelist IPs (your home IP, office IP, etc.):

# Edit Fail2Ban local configuration
sudo nano /etc/fail2ban/jail.d/mailinabox.conf

Add:

[DEFAULT]
ignoreip = 127.0.0.1/8 ::1 YOUR-HOME-IP YOUR-OFFICE-IP

Restart Fail2Ban:

sudo systemctl restart fail2ban

Regular System Updates

Keep system and Mail-in-a-Box updated:

# Update Mail-in-a-Box to latest version
sudo mailinabox

This command:

  • Checks for Mail-in-a-Box updates
  • Updates system packages
  • Applies security patches
  • Restarts services if needed

Run monthly to stay current with security updates.

Automatic Security Updates: Mail-in-a-Box enables automatic security updates by default via unattended-upgrades.

Email Authentication Verification

Verify SPF, DKIM, and DMARC are working:

Test Email Deliverability:

  1. Send test email to mail-tester.com
  2. Follow instructions to send email from your server
  3. Check score (should be 9/10 or 10/10)
  4. Review detailed report

Common Issues:

  • SPF Fails: Check DNS TXT record for your domain
  • DKIM Fails: Verify DKIM public key TXT record (see System > External DNS)
  • Reverse DNS Fails: Contact hosting provider to set PTR record

Backup Verification

Regularly test backup restoration:

# List available backups
sudo management/backup.py list

# Restore from specific backup (test on development server first!)
sudo management/backup.py restore BACKUP-FILE-NAME

Important: Restore testing should be done on a separate test server to avoid disrupting production email.

Troubleshooting

Cannot Send or Receive Email

Check Service Status:

sudo systemctl status postfix
sudo systemctl status dovecot
sudo systemctl status nginx

# Restart services if needed
sudo systemctl restart postfix dovecot nginx

Check Mail Logs:

# View recent mail log entries
sudo tail -f /var/log/mail.log

# Search for errors
sudo grep -i error /var/log/mail.log | tail -20

Check DNS Configuration:

# Verify MX record
dig yourdomain.com MX +short

# Verify A record
dig box.yourdomain.com +short

# Check reverse DNS
dig -x YOUR-SERVER-IP +short

Test Mail Server Connectivity:

# Test SMTP
telnet box.yourdomain.com 25

# Test IMAP
telnet box.yourdomain.com 993

Emails Going to Spam

Test Email Authentication:

Send email to mail-tester.com and check score.

Common Issues:

  1. Reverse DNS Missing: Contact hosting provider to set PTR record
  2. DKIM Record Missing: Check System > External DNS and add DKIM TXT record
  3. SPF Record Wrong: Verify SPF TXT record matches System > External DNS
  4. IP Reputation: Check if IP is blacklisted at MXToolbox

Check Email Headers: View headers of delivered email to see authentication results.

Web Interface Not Accessible

Check Nginx Status:

sudo systemctl status nginx

# Restart if needed
sudo systemctl restart nginx

Check SSL Certificate:

# View certificate details
sudo management/ssl_certificates.py status

# Force certificate renewal
sudo management/ssl_certificates.py renew

Check Firewall:

# Verify ports 80 and 443 are open
sudo ufw status | grep -E '80|443'

High Memory Usage

Check Memory Usage:

free -h

# View process memory usage
ps aux --sort=-%mem | head -10

Common Memory Consumers:

  • SpamAssassin (200-400MB)
  • Dovecot (100-300MB)
  • PostgreSQL/MySQL (100-200MB)
  • PHP/Nginx (100-200MB)

Reduce Memory Usage: If running low on RAM, consider disabling SpamAssassin (reduces spam protection but saves 300-400MB):

sudo systemctl stop spampd
sudo systemctl disable spampd

Disk Space Full

Check Disk Usage:

df -h

# Find large directories
du -sh /* | sort -h | tail -10

Common Disk Space Consumers:

  • Mailboxes: /home/user-data/mail/mailboxes/
  • Backups: /home/user-data/backup/
  • Logs: /var/log/

Free Up Space:

# Delete old backups (keeps latest 10)
cd /home/user-data/backup/encrypted/
ls -t | tail -n +11 | xargs rm -f

# Rotate logs
sudo logrotate -f /etc/logrotate.conf

# Clean apt cache
sudo apt clean

Password Reset

Reset User Password (admin can reset any user):

sudo management/cli.py user password [email protected] NEW-PASSWORD

Reset Admin Password (if locked out):

sudo management/cli.py user password [email protected] NEW-PASSWORD

Restore from Backup

List Available Backups:

sudo management/backup.py list

Restore Specific Backup:

# DANGER: This will overwrite current data
sudo management/backup.py restore BACKUP-FILE-NAME

Restore Single Mailbox (manual process):

# Extract backup
cd /home/user-data/backup/encrypted/
sudo duplicity restore --file-to-restore mail/mailboxes/yourdomain.com/user BACKUP-FILE-NAME /tmp/restore/

# Copy mailbox back
sudo cp -r /tmp/restore/* /home/user-data/mail/mailboxes/yourdomain.com/user/
sudo chown -R mail:mail /home/user-data/mail/mailboxes/

Advanced Configuration

Custom Web Hosting

Host websites on same server as Mail-in-a-Box:

# Web root directory
/home/user-data/www/default/

# Or per-domain
/home/user-data/www/yourdomain.com/

Upload Files:

# Upload via SFTP or SCP
scp -r website/* [email protected]:/home/user-data/www/yourdomain.com/

Set Permissions:

sudo chown -R www-data:www-data /home/user-data/www/
sudo chmod -R 755 /home/user-data/www/

Website will be accessible at https://yourdomain.com.

API Access

Mail-in-a-Box provides REST API for automation.

Get API Credentials:

  • Username: Admin email address
  • Password: Admin password

Example API Call:

# List all mail users
curl -X GET https://box.yourdomain.com/admin/mail/users   -u "[email protected]:password"

# Add new mailbox
curl -X POST https://box.yourdomain.com/admin/mail/users/add   -u "[email protected]:password"   -d "[email protected]"   -d "password=SecurePassword123"   -d "privileges=normal"

# List domains
curl -X GET https://box.yourdomain.com/admin/mail/domains   -u "[email protected]:password"

API Documentation: View full API docs at https://mailinabox.email/api-docs.html

Custom Webmail Theme

Customize Roundcube appearance:

# Roundcube skins directory
cd /usr/local/lib/roundcubemail/skins/

# Install custom skin
sudo git clone https://github.com/example/roundcube-skin custom_skin

# Configure Roundcube to use custom skin
sudo nano /etc/roundcubemail/config.inc.php

Change:

$config['skin'] = 'custom_skin';

Monitoring and Alerts

Status Monitoring API: Check system status programmatically:

curl -s https://box.yourdomain.com/admin/system/status   -u "[email protected]:password" | jq

Integration with Monitoring Tools: Use API to integrate with Uptime Kuma, Grafana, or other monitoring platforms.

Email Alerts: Mail-in-a-Box can send status alerts to admin email. Configure in admin panel.

Migration from Other Email Servers

Export Email from Old Server:

Use IMAP sync tools like imapsync to migrate mailboxes:

# Install imapsync
sudo apt install imapsync

# Sync mailbox from old server to Mail-in-a-Box
imapsync   --host1 old-mail-server.com --user1 [email protected] --password1 'oldpassword'   --host2 box.yourdomain.com --user2 [email protected] --password2 'newpassword'   --ssl1 --ssl2

Repeat for each user mailbox.

Update DNS: After verifying email works on new server, update MX record to point to Mail-in-a-Box.

Monitoring and Maintenance

Check System Status

Via Admin Panel:

  1. Log into https://box.yourdomain.com/admin
  2. Navigate to System > Status Checks
  3. Review all checks for issues

Via Command Line:

# Run status checks
sudo management/status_checks.py

View Logs

Mail Logs:

# Real-time mail log
sudo tail -f /var/log/mail.log

# Search for errors
sudo grep -i error /var/log/mail.log | tail -20

# View specific user's mail activity
sudo grep [email protected] /var/log/mail.log | tail -20

System Logs:

# View general system log
sudo journalctl -xe

# View specific service log
sudo journalctl -u postfix -f
sudo journalctl -u dovecot -f

Mail Queue Management

View Queue:

# Show queued messages
sudo mailq

Flush Queue (force immediate delivery):

sudo postqueue -f

Delete Message from Queue:

# Find message ID
sudo mailq

# Delete specific message
sudo postsuper -d MESSAGE-ID

# Delete all queued messages
sudo postsuper -d ALL

Disk Usage Monitoring

Check Mailbox Sizes:

# View per-domain disk usage
sudo du -sh /home/user-data/mail/mailboxes/*

# View per-user disk usage
sudo du -sh /home/user-data/mail/mailboxes/yourdomain.com/*

Set Mailbox Quotas: Mail-in-a-Box doesn’t have built-in quota support. Consider implementing quota management manually via Dovecot configuration.

Performance Monitoring

# Check CPU and memory usage
htop

# View network connections
sudo ss -tunap | grep -E ':25|:587|:993'

# Check load average
uptime

Next Steps

  1. Configure Remote Backups: Set up S3 or Backblaze B2 backups for off-site redundancy
  2. Add Monitoring: Integrate with Uptime Kuma or similar for availability monitoring
  3. Migrate Email: Import existing email from previous provider
  4. Document for Users: Create user guide for connecting email clients
  5. Set Up Additional Domains: Host email for family/friends on separate domains

Conclusion

You now have a fully functional Mail-in-a-Box email server with:

  • Complete email services (SMTP, IMAP, webmail)
  • Calendar and contact synchronization
  • Automatic SSL certificate management
  • Spam filtering and security
  • Automatic daily backups
  • Simple web administration

Key Success Metrics:

  • Email deliverability to major providers (Gmail, Outlook) without spam placement
  • System status checks all green in admin panel
  • Automated backups completing successfully
  • Users able to send/receive email on all devices
  • SPF, DKIM, DMARC all passing

Mail-in-a-Box provides enterprise-quality email hosting with homelab simplicity. The automated configuration and monitoring ensure reliable email service with minimal ongoing maintenance.

Community Resources:

Welcome to self-hosted email made easy!