How to Configure Multi-Domain Support on a Mail Server (Ubuntu 20.04 + Postfix + Dovecot)

Welcome to Part 5 of our Mail Server Series on Ubuntu 20.04.
In Part 1, we built the SMTP server using Postfix.
In Part 2, we configured IMAP and TLS with Dovecot.
In Part 3, we added SPF and DKIM for email authentication.
In Part 4, we secured our domain reputation with a DMARC record.

Now in Part 5, we’ll take things further: adding multi-domain support to your mail server.


Why Support Multiple Domains?

If you manage multiple brands, projects, or clients, being able to send and receive emails using different domain names — all from one server — is extremely useful.

For example, you might want to manage:

  • admin@domain1.com
  • support@domain2.com
  • hello@domain3.org

…all on one VPS, one Postfix, one Dovecot.


Prerequisites

Make sure you’ve completed the previous setup, and already have:

  • Working mail server with Postfix + Dovecot
  • Valid SSL via Let’s Encrypt
  • DNS setup for your primary domain

You’ll need:

  • Additional domains (e.g., secondbrand.com, thirdbrand.org)
  • DNS access for those domains

Step 1: Configure DNS Records for Each Domain

For each additional domain, add these DNS records:

A Record:

Name: mail
Type: A
Value: [your server IP]

MX Record:

Name: @
Type: MX
Priority: 10
Value: mail.yourseconddomain.com

SPF (TXT):

Name: @
Type: TXT
Value: v=spf1 mx ~all

DKIM:

Repeat the Part 3 DKIM guide for each domain by generating a separate DKIM key and DNS record.

DMARC:

Name: _dmarc
Type: TXT
Value: v=DMARC1; p=none; pct=100; rua=mailto:you@domain.com

Wait until propagation is complete.


Step 2: Add Domains to Postfix

Postfix allows us to support multiple domains via virtual domains.

Open your Postfix main configuration:

sudo nano /etc/postfix/main.cf

Ensure you have:

virtual_alias_domains = domain1.com domain2.com domain3.org
virtual_alias_maps = hash:/etc/postfix/virtual

Save and exit.

Then edit the virtual file:

sudo nano /etc/postfix/virtual

Add each email address you want to forward to system users:

admin@domain1.com     user1
support@domain2.com   user2
hello@domain3.org     user3

Save, then generate the .db file:

sudo postmap /etc/postfix/virtual

Restart Postfix:

sudo systemctl restart postfix

Step 3: Add Users for Each Domain

If you haven’t already, create system users for each mailbox:

sudo adduser user1
sudo adduser user2
sudo adduser user3

These users will store their emails in ~/Maildir, as configured in Part 2.


Step 4: Adjust Dovecot to Handle Multi-Domain Logins

Open the Dovecot auth config:

sudo nano /etc/dovecot/conf.d/10-auth.conf

Ensure this line allows full email login:

auth_username_format = %u

Save and restart Dovecot:

sudo systemctl restart dovecot

Step 5: Test Each Domain

Try logging into each email address using:

  • Thunderbird or Outlook
  • Webmail (e.g., Roundcube if installed)
  • Send test emails between addresses

Check /var/log/mail.log for any issues.


Common Errors to Watch Out For

  • SPF/DKIM fails: Check DNS spelling, propagation, or missing TXT records
  • Authentication failed: Ensure you’re using full email address as login
  • Mail not delivered: Check postfix logs and aliases

What’s Next?

Congratulations! 🎉
You now have a single server handling multiple email domains securely and reliably.

More Reading

Post navigation

Leave a Comment

Leave a Reply

Your email address will not be published. Required fields are marked *

How to Create a DMARC Record to Protect Your Mail Server’s Reputation

How to Install Dovecot IMAP Server and Enable TLS Encryption on Ubuntu 20.04

How to Set Up a Secure Mail Server with Postfix on Ubuntu 20.04 (Complete with Real Config Examples)

How to Set Up SPF and DKIM on a Mail Server in Ubuntu 20.04