keepcalculator

06 Numbers and Powers

Set Up One Webmail for Multiple Domains on a VPS

Card No. 06·69992 · Updated · Standard formula, shown below

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

  1. Update your system
    SSH into your VPS and run:
    sudo apt update && sudo apt upgrade -y
  2. 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).
  3. Configure Postfix for multiple domains
    Edit /etc/postfix/main.cf and add:
    mydestination = localhost, example.com, example.net
    virtual_mailbox_domains = example.com, example.net
    virtual_mailbox_base = /var/mail/vhosts
    virtual_mailbox_maps = hash:/etc/postfix/vmailbox
    virtual_minimum_uid = 1000
    virtual_uid_maps = static:5000
    virtual_gid_maps = static:5000
  4. Create the virtual mailbox file
    Create /etc/postfix/vmailbox and add one line per mailbox:
    user@example.com example.com/user/
    info@example.net example.net/info/
    Then run sudo postmap /etc/postfix/vmailbox.
  5. Set up Dovecot
    Edit /etc/dovecot/conf.d/10-mail.conf and set:
    mail_location = maildir:/var/mail/vhosts/%d/%n
    Also edit 10-auth.conf to allow plaintext auth over TLS (default is fine).
  6. Create the vhost directory and user
    Run:
    sudo mkdir -p /var/mail/vhosts
    sudo useradd -r -u 5000 -g 5000 -d /var/mail/vhosts -s /sbin/nologin vmail
    sudo chown -R vmail:vmail /var/mail/vhosts
  7. Restart services
    sudo systemctl restart postfix dovecot
  8. 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.
  9. Configure Roundcube for multiple domains
    Edit /var/www/webmail/config/config.inc.php and 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).
  10. Set up Nginx
    Create a server block in /etc/nginx/sites-available/webmail pointing to the Roundcube directory. Enable it:
    sudo ln -s /etc/nginx/sites-available/webmail /etc/nginx/sites-enabled/
    sudo systemctl reload nginx
  11. 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 for mail.yourdomain.com if you want a dedicated mail subdomain.
  12. 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 postmap after 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/vhosts directory 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 with telnet 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_host setting.
  • 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

The whole Numbers and Powers drawer →