Guide to Configuring a Professional Mail Server on VPS with Postfix, Dovecot, and Roundcube
A detailed guide to setting up a professional mail server on VPS using Postfix, Dovecot, and Roundcube, including installation, configuration, SSL authentication, and activity...
Introduction
Building a professional mail server on a VPS allows businesses to fully control their email data, enhance security, and reduce costs compared to external email services. This guide walks through setting up a complete mail server using popular technologies: Postfix (SMTP mail transfer), Dovecot (IMAP/POP3 email retrieval), and Roundcube (webmail interface). The instructions apply to Ubuntu 22.04 LTS.
Prerequisites
- A VPS running Ubuntu 22.04 LTS with root access
- A static IP address and a registered domain (e.g., mail.yourdomain.com)
- Domain DNS configured: A record for mail.yourdomain.com, MX record, SPF, DKIM, and DMARC
- SSH access to the VPS
Install and Configure Postfix
Postfix handles email sending and receiving.
Install Postfix
Run the following commands on the VPS:
sudo apt update
sudo apt install postfix mailutils -y
During installation, select Internet Site and enter your domain (e.g., yourdomain.com).
Configure Postfix
Edit the configuration file:
sudo nano /etc/postfix/main.cf
Add or modify the following lines:
myhostname = mail.yourdomain.com
mydomain = yourdomain.com
myorigin = $mydomain
inet_interfaces = all
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
relayhost =
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
home_mailbox = Maildir/
smtpd_tls_cert_file = /etc/ssl/certs/ssl-cert-snakeoil.pem
smtpd_tls_key_file = /etc/ssl/private/ssl-cert-snakeoil.key
smtpd_tls_security_level = may
smtpd_sasl_auth_enable = yes
smtpd_sasl_type = dovecot
smtpd_sasl_path = private/auth
smtpd_sasl_security_options = noanonymous
smtpd_sasl_local_domain = $myhostname
smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination
smtp_tls_security_level = may
smtp_tls_cert_file = /etc/ssl/certs/ssl-cert-snakeoil.pem
smtp_tls_key_file = /etc/ssl/private/ssl-cert-snakeoil.key
Restart Postfix:
sudo systemctl restart postfix
Configure Dovecot
Dovecot manages email reception and provides IMAP/POP3 services.
Install Dovecot
sudo apt install dovecot-core dovecot-imapd dovecot-pop3d dovecot-lmtpd -y
Configure Dovecot
Edit the main configuration file:
sudo nano /etc/dovecot/dovecot.conf
Add the following line:
protocols = imap pop3 lmtp
Edit /etc/dovecot/conf.d/10-mail.conf:
mail_location = maildir:~/Maildir
Edit /etc/dovecot/conf.d/10-auth.conf:
auth_mechanisms = plain login
disable_plaintext_auth = no
auth_default_realm = yourdomain.com
auth_username_format = %n
Edit /etc/dovecot/conf.d/10-master.conf:
service auth {
unix_listener /var/spool/postfix/private/auth {
mode = 0666
user = postfix
group = postfix
}
}
Restart Dovecot:
sudo systemctl restart dovecot
Install and Configure Roundcube
Roundcube provides a web-based email interface.
Install Roundcube
sudo apt install roundcube roundcube-core roundcube-mysql roundcube-plugins -y
Configure Roundcube
Access the web installer in your browser: http://your-server-ip/roundcube
Select MySQL as the database, enter connection details, and create the database.
SSL Authentication
To secure the server, configure SSL for Postfix and Dovecot.
Generate a self-signed certificate:
sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/ssl/private/ssl-cert-snakeoil.key -out /etc/ssl/certs/ssl-cert-snakeoil.pem
Verify Operation
After configuration, verify:
- Send an email from a local machine or external email
- Access Roundcube via browser:
https://mail.yourdomain.com/roundcube - Check logs for errors:
sudo journalctl -u postfixandsudo journalctl -u dovecot
Troubleshooting
- Cannot send email: Check Postfix logs and MX record configuration.
- Cannot receive email: Verify Dovecot and IMAP/POP3 settings.
- Cannot access Roundcube: Confirm Apache/Nginx and virtual host setup.
References
Recommended NVMe Cloud VPS Plans to Deploy This Setup
Enterprise RAID 10 NVMe SSDs, CMC & FPT District 9 uplinks with Anycast Anti-DDoS and 99.99% SLA.
VPS-3E
10% VAT included
- CPU: 2 vCPU
- RAM: 4 GB
- SSD: 50 GB NVMe
