Back to blog
February 2, 2026Guides

How to Set Up a Private Email Server on VPS

Complete guide to setting up your own private email server using Postfix and Dovecot on a VPS. Learn how to host your own email with full privacy and control.

How to Set Up a Private Email Server on VPS

Running your own email server gives you complete control over your communications, ensuring privacy and avoiding reliance on third-party providers. While it requires some technical knowledge, setting up a private email server on your VPS is entirely achievable. This guide covers setting up Postfix (SMTP) and Dovecot (IMAP/POP3) for a complete email solution.

Why Host Your Own Email Server?

  • Complete privacy: Your emails are stored on your server, not scanned by third parties
  • No data mining: Avoid targeted advertising based on email content
  • Custom domains: Use your own domain for professional email addresses
  • Unlimited accounts: Create as many email addresses as you need
  • Full control: Configure spam filters, security policies, and storage limits
  • Cost-effective: One server can handle multiple email accounts

Prerequisites

  • VPS with at least 2GB RAM and 20GB storage
  • Domain name with DNS access
  • Static IP address (recommended)
  • Ubuntu 20.04 or Debian 11+
  • Root or sudo access

DNS Configuration

Before installing email software, configure DNS records:

  • A record: mail.yourdomain.com → your server IP
  • MX record: yourdomain.com → mail.yourdomain.com (priority 10)
  • SPF record: TXT "v=spf1 mx a:mail.yourdomain.com ~all"
  • DKIM record: Generated after installation
  • DMARC record: TXT "v=DMARC1; p=none; rua=mailto:admin@yourdomain.com"

Installing and Configuring Postfix

bash
apt update
apt install -y postfix postfix-mysql dovecot-core dovecot-imapd dovecot-pop3d dovecot-lmtpd dovecot-mysql

# During installation, select 'Internet Site' and enter your domain name
# Configure Postfix main settings:
nano /etc/postfix/main.cf

# Key settings:
myhostname = mail.yourdomain.com
mydomain = yourdomain.com
myorigin = $mydomain
mydestination = $myhostname, localhost.$mydomain, $mydomain
inet_interfaces = all

Configuring Dovecot

bash
nano /etc/dovecot/conf.d/10-mail.conf

# Set mail location:
mail_location = maildir:/var/mail/vhosts/%d/%n

nano /etc/dovecot/conf.d/10-auth.conf

# Enable authentication:
disable_plaintext_auth = no
auth_mechanisms = plain login

systemctl restart dovecot
systemctl restart postfix

Setting Up Webmail (Optional)

Install Roundcube for web-based email access:

bash
apt install -y roundcube roundcube-mysql roundcube-plugins
# Configure Roundcube during installation
# Access webmail at: https://yourdomain.com/webmail

Security Configuration

  • Enable SSL/TLS encryption for SMTP (port 587) and IMAP (port 993)
  • Configure firewall to allow only necessary ports (25, 587, 993, 995)
  • Set up fail2ban to prevent brute force attacks
  • Use strong passwords and consider two-factor authentication
  • Regularly update all email server software
  • Monitor logs for suspicious activity
  • Configure SPF, DKIM, and DMARC records properly

Important Tips

  • Email server IPs can get blacklisted - monitor your IP reputation
  • Start with a small setup and scale gradually
  • Keep backups of email data and configurations
  • Test email delivery to major providers (Gmail, Outlook, etc.)
  • Consider using a relay service for better deliverability
  • Monitor disk space - emails can consume significant storage

Setting up your own email server provides complete control and privacy over your communications. While it requires ongoing maintenance and monitoring, the benefits of privacy, customization, and independence from third-party providers make it worthwhile for those who value data sovereignty. Start with a basic setup and gradually add features as you become more comfortable with email server administration.