Postfix with Dovecot and Roundcube Webmail Setup on Ubuntu 22.04
Introduction
A complete mail server usually has three main parts:
Postfix for sending emails (SMTP), Dovecot for receiving and storing emails (IMAP/POP3),
and Roundcube for accessing mail through a web browser.
In this guide, we will set up Postfix, Dovecot, and Roundcube Webmail on Ubuntu 22.04 with simple steps.
Step 1: Update System
sudo apt update && sudo apt upgrade -y
Step 2: Set Hostname
Set your mail server hostname (example: mail.bitscentric.local):
sudo hostnamectl set-hostname mail.bitscentric.local
Step 3: Install Postfix
Install Postfix for sending emails:
sudo apt install -y postfix mailutils
During installation, select:
- General type of mail configuration: Internet Site
- System mail name: bitscentric.local
Step 4: Configure Postfix
Edit the main configuration file:
sudo nano /etc/postfix/main.cf
Add/modify the following lines:
myhostname = mail.bitscentric.local
mydomain = bitscentric.local
myorigin = $mydomain
inet_interfaces = all
inet_protocols = ipv4
home_mailbox = Maildir/
smtpd_tls_cert_file = /etc/letsencrypt/live/mail.bitscentric.local/fullchain.pem
smtpd_tls_key_file = /etc/letsencrypt/live/mail.bitscentric.local/privkey.pem
smtpd_use_tls = yes
Step 5: Install and Configure Dovecot
Dovecot handles IMAP and POP3 protocols for receiving emails.
sudo apt install -y dovecot-core dovecot-imapd dovecot-pop3d
Edit Dovecot config to use Maildir:
sudo nano /etc/dovecot/conf.d/10-mail.conf
mail_location = maildir:~/Maildir
Enable authentication:
sudo nano /etc/dovecot/conf.d/10-auth.conf
disable_plaintext_auth = no
auth_mechanisms = plain login
Step 6: Create Maildir for Users
For each user, create a Maildir folder:
sudo useradd -m user1
sudo passwd user1
sudo mkdir -p /home/user1/Maildir
sudo chown -R user1:user1 /home/user1/Maildir
Step 7: Install Roundcube Webmail
Roundcube is a webmail client that allows users to access emails via browser.
sudo apt install -y apache2 php php-cli php-mbstring php-zip php-gd php-mysql php-intl php-curl roundcube roundcube-core roundcube-mysql roundcube-plugins
Enable Apache and PHP modules:
sudo a2enconf roundcube
sudo systemctl reload apache2
Step 8: Configure Roundcube
Edit Roundcube config file:
sudo nano /etc/roundcube/config.inc.php
Set the IMAP and SMTP server:
$config['default_host'] = 'ssl://mail.bitscentric.local';
$config['default_port'] = 993;
$config['smtp_server'] = 'tls://mail.bitscentric.local';
$config['smtp_port'] = 587;
Step 9: Enable SSL Certificates
Secure mail services with Let’s Encrypt SSL:
sudo apt install certbot -y
sudo certbot certonly --standalone -d mail.bitscentric.local --agree-tos -m admin@bitscentric.local
Step 10: Restart Services
sudo systemctl restart postfix dovecot apache2
Step 11: Access Roundcube
Open your browser and visit:
http://mail.bitscentric.local/roundcube
Login using your system user (e.g., user1@bitscentric.local).
Best Practices
- Always use SPF, DKIM, DMARC DNS records for proper email delivery.
- Secure Dovecot and Postfix with TLS (never use plain text passwords).
- Limit relaying to avoid open relay abuse.
- Regularly monitor
/var/log/mail.log
for delivery issues. - Integrate spam filters like Rspamd or SpamAssassin for production use.
Conclusion
We have successfully set up a complete mail solution using Postfix, Dovecot, and Roundcube Webmail on Ubuntu 22.04.
Now users can send and receive emails securely and access their mailbox from a web browser.
This is a production-ready setup and a perfect learning project for students.