How to Install a Mail Server (Postfix + Dovecot + Roundcube) Print

  • mail server, postfix, dovecot, roundcube, vps
  • 0

Setting up your own mail server on a VPS allows you to send, receive, and manage emails using your own domain. This guide walks you through installing Postfix (SMTP), Dovecot (IMAP/POP3), and Roundcube (Webmail) on Ubuntu or Debian-based systems.

 


 

Prerequisites

• A VPS running Ubuntu 20.04+ or Debian 11+

• A registered domain (e.g., example.com)

• A valid hostname set (e.g., mail.example.com)

• DNS records configured:

MX record pointing to mail.example.com

A record for mail.example.com

SPF, DKIM, and DMARC records (recommended)

 


 

Step 1: Update the System

apt update && apt upgrade -y

Set the hostname:

hostnamectl set-hostname mail.example.com

Replace mail.example.com with your actual mail subdomain.

 


 

Step 2: Install Postfix (SMTP Server)

apt install postfix -y

During installation, choose:

“Internet Site”

• Set your domain name (e.g., example.com)

 

You can modify settings later in /etc/postfix/main.cf.

 


 

Step 3: Install Dovecot (IMAP & POP3)

apt install dovecot-core dovecot-imapd dovecot-pop3d dovecot-lmtpd -y

Enable and start Dovecot:

systemctl enable dovecot
systemctl start dovecot

 

 


 

Step 4: Create Mail Directory and User

 

Create a system user for email:

adduser mailuser

Create a mail directory:

mkdir -p /home/mailuser/Maildir
chmod -R 700 /home/mailuser/Maildir

Edit Postfix to use Maildir format:

postconf -e "home_mailbox = Maildir/"

Reload Postfix:

systemctl restart postfix

 

 


 

Step 5: Test Sending and Receiving Mail (Optional)

 

Send a test email from terminal:

echo "Test message" | mail -s "Hello" [email protected]

Check email:

mail

 

 


 

Step 6: Install Roundcube Webmail

 

1. Install required packages:

apt install apache2 php php-mysql php-intl php-xml php-mbstring php-zip php-curl php-imagick php-common mariadb-server -y

2. Download and set up Roundcube:

cd /var/www/html
wget https://github.com/roundcube/roundcubemail/releases/download/1.6.5/roundcubemail-1.6.5-complete.tar.gz
tar xzf roundcubemail-1.6.5-complete.tar.gz
mv roundcubemail-1.6.5 roundcube
chown -R www-data:www-data /var/www/html/roundcube

3. Create MySQL database for Roundcube:

mysql -u root -p
CREATE DATABASE roundcube;
CREATE USER 'roundcubeuser'@'localhost' IDENTIFIED BY 'strongpassword';
GRANT ALL PRIVILEGES ON roundcube.* TO 'roundcubeuser'@'localhost';
FLUSH PRIVILEGES;
EXIT;

4. Configure Roundcube in your browser

 

Visit:

http://your_server_ip/roundcube/installer

Follow the on-screen setup. Use localhost for IMAP and SMTP servers.

 

Once done, delete the installer directory:

rm -rf /var/www/html/roundcube/installer

 

 


 

Step 7: Secure Your Mail Server (Recommended)

• Install Let’s Encrypt SSL for mail and web:

apt install certbot python3-certbot-apache -y
certbot --apache -d mail.example.com

• Configure SPF, DKIM, and DMARC DNS records

• Enable fail2ban to block brute-force attempts

 


 

Conclusion

 

You now have a fully functional mail server with Postfix, Dovecot, and Roundcube. This setup allows you to send and receive emails via both webmail and desktop clients.

 

For advanced features like spam filtering, DKIM, or virus scanning, or if you need help troubleshooting mail delivery, contact Hosteons Support or access your server through https://vps.hosteons.com.

 


Was this answer helpful?

« Back