This guide walks you through configuring a single webmail interface (like Roundcube or SnappyMail) on your VPS to handle email for multiple domains. You’ll learn how to set up the mail server, create virtual domains and mailboxes, and point your webmail to the right accounts—all from one login page.
What You’ll Need
- A VPS with a Linux distribution (Ubuntu 22.04 or Debian 12 recommended) and root or sudo access.
- A registered domain name (or several) with DNS management access.
- At least 1 GB of RAM and 10 GB of free disk space (more if you expect heavy mail traffic).
- Basic comfort with the command line and editing text files (nano or vim).
- Ports 25, 143, 587, and 993 open in your firewall (or 80/443 for webmail).
Step-by-Step
- Update your system
SSH into your VPS and run:sudo apt update && sudo apt upgrade -y - Install a mail server stack
We’ll use Postfix (SMTP) and Dovecot (IMAP/POP3). Install them with:sudo apt install postfix dovecot-imapd dovecot-pop3d -y
During Postfix setup, choose “Internet Site” and enter your primary domain (e.g.,example.com). - Configure Postfix for multiple domains
Edit/etc/postfix/main.cfand add:mydestination = localhost, example.com, example.netvirtual_mailbox_domains = example.com, example.netvirtual_mailbox_base = /var/mail/vhostsvirtual_mailbox_maps = hash:/etc/postfix/vmailboxvirtual_minimum_uid = 1000virtual_uid_maps = static:5000virtual_gid_maps = static:5000 - Create the virtual mailbox file
Create/etc/postfix/vmailboxand add one line per mailbox:user@example.com example.com/user/info@example.net example.net/info/
Then runsudo postmap /etc/postfix/vmailbox. - Set up Dovecot
Edit/etc/dovecot/conf.d/10-mail.confand set:mail_location = maildir:/var/mail/vhosts/%d/%n
Also edit10-auth.confto allow plaintext auth over TLS (default is fine). - Create the vhost directory and user
Run:sudo mkdir -p /var/mail/vhostssudo useradd -r -u 5000 -g 5000 -d /var/mail/vhosts -s /sbin/nologin vmailsudo chown -R vmail:vmail /var/mail/vhosts - Restart services
sudo systemctl restart postfix dovecot - Install a webmail application
We’ll use Roundcube (the most common). Install dependencies:sudo apt install nginx php-fpm php-mysql php-mbstring php-xml php-json php-intl -y
Download Roundcube from the official site, extract to/var/www/webmail, and set permissions. - Configure Roundcube for multiple domains
Edit/var/www/webmail/config/config.inc.phpand set:$config['default_host'] = 'localhost';$config['smtp_host'] = 'localhost';$config['username_domain'] = ''; // leave blank to allow full email login
This lets users log in with their full email address (e.g.,user@example.com). - Set up Nginx
Create a server block in/etc/nginx/sites-available/webmailpointing to the Roundcube directory. Enable it:sudo ln -s /etc/nginx/sites-available/webmail /etc/nginx/sites-enabled/sudo systemctl reload nginx - Add DNS records for each domain
For each domain, add an MX record pointing to your VPS (e.g.,mail.yourvps.com) and an A record formail.yourdomain.comif you want a dedicated mail subdomain. - Test with a real email client
Create a test mailbox (add to vmailbox, run postmap) and try logging in via webmail. If it fails, check logs:sudo tail -f /var/log/mail.log.
Common Mistakes
- Forgetting to run
postmapafter editing the vmailbox file—this causes “mailbox unavailable” errors. - Wrong file permissions on the vhost directory—Dovecot can’t read mail if the vmail user doesn’t own it.
- Not updating DNS MX records—email will still go to the old server.
- Using the same password for all mailboxes—always use unique strong passwords.
- Blocking port 25—many VPS providers block it by default; you may need to request unblocking.
Tips
- Use SSL/TLS for both SMTP and IMAP—install a free certificate from Let’s Encrypt for your mail subdomain.
- Set up SPF and DKIM records to improve deliverability and avoid spam folders.
- Use a database (like MariaDB) for Roundcube to store contacts and settings—it’s more reliable than file-based.
- Regularly back up the
/var/mail/vhostsdirectory and your config files. - Consider using a mail filtering tool like SpamAssassin to reduce spam.
Troubleshooting
- Cannot connect to IMAP—Check that Dovecot is running:
sudo systemctl status dovecot. Test withtelnet localhost 143. - Mail not sending—Check Postfix logs:
sudo tail -f /var/log/mail.log. Ensure port 587 is open and Postfix is listening. - Webmail shows “Login failed”—Verify the mailbox exists in vmailbox and the password is correct. Also check Roundcube’s
default_hostsetting. - Roundcube page not loading—Check Nginx error logs:
sudo tail -f /var/log/nginx/error.log. Ensure PHP-FPM is running. - Emails going to spam—Set up SPF, DKIM, and DMARC records correctly. Test with tools like mail-tester.com.
Frequently Asked Questions
Can I use the same webmail for unlimited domains?
Yes, as long as each domain is added to Postfix’s virtual_mailbox_domains and has its mailboxes in the vmailbox file. There’s no hard limit.
Do I need a separate IP for each domain?
No, a single IP can handle all domains. Just make sure your MX records point to that IP.
How do I add a new mailbox later?
Add a line to /etc/postfix/vmailbox, run sudo postmap /etc/postfix/vmailbox, and create the directory in /var/mail/vhosts with proper ownership.
Can I use a different webmail like SnappyMail?
Yes, the configuration is similar—just point the webmail to your Dovecot IMAP server. The key is having the mail server configured correctly.
What if my VPS provider blocks port 25?
You’ll need to contact them to unblock it, or use a relay service. Without port 25, you can’t receive emails from external servers.
Is it safe to use plain passwords for mailboxes?
No, always use strong passwords and enable TLS encryption for connections. Plaintext passwords are only sent over the network if you don’t use SSL/TLS.
Related
Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.
More cards in this drawer
- Business partnership due diligence checklist what to verify before you sign?
- Does the FCC Protect Internet Privacy?
- Disaster Robbers Codes? Meaning & Origin
- Repair a Disk with Mac Disk Utility
- Avoid Vendor Lock-In: Cloud Provider Strategy
- Secure GitHub Accounts & Repos Against Malicious Code