How to Host Multiple Domains in Modoboa Mail Server

This tutorial will be showing you how to set up multiple email domains with Modoboa, which is an easy-to-use and open-source mail hosting solution. To follow this tutorial, it’s assumed that you have already set up a Modoboa mail server with one domain name.

What You Need to Do

If you want to host multiple mail domains, then you need to

  • Add a new mail domain and user in Modoboa admin panel.
  • Create MX, A, SPF, DKIM and DMARC record for the new mail domain.
  • Set up Webmail, Postfix and Dovecot for multiple domains

PTR record is used to check if the sender’s IP address matches the HELO hostname. You don’t need to add another PTR record when adding a new mail domain.

Step 1: Adding Additional Domains in Modoboa Admin Panel

Log into Modoboa admin panel with the admin account. ( Then go to Domains tab and click Add button to add a new domain.

modoboa multiple domains

Then enter your main domain name in the Name field. It is highly recommended that you enable DKIM signing, which can help with your domain reputation. In Key selector filed, you can enter a random word like modoboa.  Choose 2048 as the key length.

host multiple email domains in modoboa

In the next screen, you can choose to create an admin account for your domain. The SMTP protocol requires that a mail server should have a [email protected] address.

modoboa add second domain

Click the Submit button and your new domain name will be added in Modoboa.

To add email addresses, go to Domains tab and click your second domain name.

modoboa simple mail hosting

Then click mailboxes.

modoboa virtual domain

Click Add button and choose Account.

modoboa domain mailbox

Then choose Simple user as the role. Enter an email address in Username field and enter a password.

modoboa add email address of second domain

In the next screen, you can optionally create an alias for this email address.


After clicking the submit button, the email address is created.

Step 2: Creating MX, A, SPF, DKIM and DMARC record for the new mail domain

MX and A Record

In your DNS manager, add MX record for the new domain like below.

Record Type    Name      Value

MX             @

The A record points to your mail server’s IP address.

Record Type    Name     Value

A              mail     IP-address-of-mail-server

If your server uses IPv6 address, be sure to add AAAA record.

SPF, DKIM and DMARC Record

Then create SPF record to allow the MX host to send email for the new mail domain.

Record Type    Name      Value

TXT            @         v=spf1 mx ~all

To create DKIM record, we need to get the public key. Go to Modoboa admin panel and select your second domain name in the Domains tab. In the DNS section, click Show key button.


The public key of the second domain will be revealed. There are two formats. We only need the Bind/named format.


Go to your DNS manager, create a TXT record, enter modoboa._domainkey in the Name field. (Recall that we used modoboa as the selector when adding the second domain name in the admin panel.) Copy everything in the parentheses and paste into the value field. Delete all double quotes. Your DNS manager may require you to delete other invalid characters, such as carriage return.

modoboa dkim format

To create a DMARC record, go to your DNS manager and add a TXT record. In the name field, enter _dmarc. In the value field, enter the following:

v=DMARC1; p=none; pct=100; rua=mailto:[email protected]

create dmarc record txt

The above DMARC record is a safe starting point. To see the full explanation of DMARC, please check the following article.

Step 3: Setting up Webmail, Postfix and Dovecot for Multiple Domains

It makes sense to let users of the first domain use and users of the second domain use when accessing webmail.

First, we need to add the second mail domain into the allowed hosts list. Edit the file.

sudo nano /srv/modoboa/instance/instance/

Find the following lines.


Add your second domain.


Save and close the file. Then restart uWSGI for the change to take effect.

sudo systemctl restart uwsgi

Next, we need to create an Nginx virtual host file the second domain. Change working directory to /etc/nginx/sites-enabled.

cd /etc/nginx/sites-enabled

Copy the content of the first mail domain virtual host file to the second domain virtual host file.

sudo cp

Edit the second domain virtual host file.

sudo nano

Find the following line.


We need to change the server_name to


There are 2 instances of server_name, you need to change both of them. Then comment out the following 3 lines.

upstream modoboa {
    server unix:/run/uwsgi/app/modoboa_instance/socket fail_timeout=0;

Save and close the file. Then test Nginx configuartion.

sudo nginx -t

If the test is successful, reload Nginx for the changes to take effect.

sudo systemctl reload nginx

Now use Certbot nginx plugin to obtain TLS certificate for all your mail domains, so you will have a single TLS certificate with multiple domain names on it.

sudo /opt/certbot-auto certonly --nginx --agree-tos -d, --cert-name --email your-email-address 

Notice that in the above command, we specified the cert name using the first mail domain, which will be used in the file path, so you don’t have to change the file path in Postfix or Dovecot configuration file. Also note that we tell certbot to only obtain but not install the certificate (certonly).

When it asks if you want to update existing certificate to include the new domain, answer U and hit Enter.

modoboa letsencrypt multi-domain

Now you should see the following message, which indicates the multi-domain certificate is successfully obtained.

modoboa multi-domain nginx certificate

Reload Nginx to pick up the new certificate.

sudo systemctl reload nginx

You should now be able to use different domains to access webmail. Also you need to reload Postfix SMTP server and Dovecot IMAP server in order to let them pick up the new certificate.

sudo systemctl reload postfix dovecot

Using Mail Client on Your Computer or Mobile Device

Fire up your desktop email client such as Mozilla Thunderbird and add a mail account of the second domain.

  • In the incoming server section, select IMAP protocol, enter as the server name, choose port 993 and SSL/TLS. Choose normal password as the authentication method.
  • In the outgoing section, select SMTP protocol, enter as the server name, choose port 587 and STARTTLS. Choose normal password as the authentication method.


Although Postfix SMTP server and Dovecot IMAP server are using the hostname of the first mail domain ( when communicating with others, they are now using a multi-domain certificate, so the mail client won’t display certificate warnings.

SPF and DKIM Check

Now you can use your desktop email client or webmail client to send a test email to [email protected] and get a free email authentication report. Here’s the report I got from

postfix spf dkim ubuntu

Don’t forget to test your email score at and also

That’s it! I hope this tutorial helped you host multiple email domains with Modoboa. As always, if you found this post useful, then subscribe to our free newsletter to get more tips and tricks. Take care 🙂

Rate this tutorial
[Total: 8 Average: 4.5]

Leave a Comment

  • Comments with links are moderated by admin before published.
  • Your email address will not be published.
  • Use <pre> ... </pre> HTML tag to quote the output from your terminal/console.
  • If my answer helped you, please consider supporting this site. Thanks :)