How to Host Multiple Mail Domains in PostfixAdmin on Ubuntu

This tutorial will be showing you how to set up multiple mail domains (virtual hosting) on Ubuntu server with PostfixAdmin, which is an open-source web-based interface to configure and manage a Postfix based email server for many domains and users.


To follow this tutorial, it’s assumed that you have already configured PostfixAdmin with one mail domain (Ubuntu 18.04 guide, Ubuntu 20.04 guide) and you have followed part 4 to set up SPF and OpenDKIM.

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 PostfixAdmin web-based panel.
  • Create MX, A and SPF record for the new mail domain.
  • Set up DKIM signing for the new domain.
  • Create DMARC Record for the new domain.
  • Set up RoundCube Webmail, Postfix and Dovecot for multiple domains
Reverse DNS check 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 PostfixAdmin Panel

Log into PostfixAdmin panel with the postmaster account. ( Then go to Domain List -> New Domain to add a new domain.

postfixadmin multiple domains

Note that the new domain should have DNS A record, or PostfixAdmin would throw the following error message. You can check the DNS propagation status on

Invalid domain, and/or not discoverable in DNS

Next, add a user under the new domain.

postfixadmin add new mailbox

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

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.

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

Step 3: Setting up DKIM signing for the new domain

We have installed and configured OpenDKIM for a single domain in part 4 of this tutorial series. Now we need to tell OpenDKIM to sign every outgoing email for the new mail domain.

Edit the OpenDKIM signing table file.

sudo nano /etc/opendkim/signing.table

Add the second domain like below.


Edit the key table file.

sudo nano /etc/opendkim/key.table

Add the second domain like below.

Edit the trusted hosts file.

sudo nano /etc/opendkim/trusted.hosts

Add the second domain like below.


Next, we need to generate a priavte/public keypair for the second domain. Create a separate folder for the second domain.

sudo mkdir /etc/opendkim/keys/

Generate keys using opendkim-genkey tool.

sudo opendkim-genkey -b 2048 -d -D /etc/opendkim/keys/ -s default -v

The above command will create 2048 bits keys. -d (domain) specifies the domain. -D (directory) specifies the directory where the keys will be stored and we use default as the selector (-s). Once the command is executed, the private key will be written to default.private file and the public key will be written to default.txt file.

Make opendkim as the owner of the private key.

sudo chown opendkim:opendkim /etc/opendkim/keys/

Display the public key

sudo cat /etc/opendkim/keys/

The string after the p parameter is the public key.

add a new domain in opendkim

In your DNS manager, create a TXT record for the second domain. Enter default._domainkey in the Name field. Copy everything in the parentheses and paste into the value field. Delete all double-quotes. (You can paste it into a text editor first, delete all double quotes, then copy it to your DNS manager. Your DNS manager may require you to delete other invalid characters, such as carriage return.)

create dkim record

After saving your changes. Check the TXT record with this command.

dig TXT

Now you can run the following command to test if your DKIM DNS record is correct.

sudo opendkim-testkey -d -s default -vvv

If everything is OK, you will see

opendkim-testkey: using default configfile /etc/opendkim.conf
opendkim-testkey: checking key ''
opendkim-testkey: key secure
opendkim-testkey: key OK

If you see “Key not secure”, don’t panic. This is because DNSSEC isn’t enabled on your domain name. DNSSEC is a security standard for secure DNS query. Most domain names haven’t enabled DNSSEC. You can continue to follow this guide.

Restart OpenDKIM so it will start signing emails for the second domain.

sudo systemctl restart opendkim

Step 4: Creating DMARC Record For the New Domain

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. Note that you need to create the [email protected] email address.

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 5: Setting up RoundCube, 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 using RoundCube webmail. I will show you how to do it with Apache and Nginx.


If Roundcube is served by Apache web server, then create a virtual host for the second domain.

sudo nano /etc/apache2/sites-available/

Put the following text into the file.

<VirtualHost *:80>
  DocumentRoot /var/www/roundcube/

  ErrorLog ${APACHE_LOG_DIR}/mail.domain2.com_error.log
  CustomLog ${APACHE_LOG_DIR}/mail.domain2.com_access.log combined

  <Directory />
    Options FollowSymLinks
    AllowOverride All

  <Directory /var/www/roundcube/>
    Options FollowSymLinks MultiViews
    AllowOverride All
    Order allow,deny
    allow from all


Save and close the file. Then enable this virtual host with:

sudo a2ensite

Reload Apache for the changes to take effect.

sudo systemctl reload apache2


If Roundcube is served by Nginx web server, then create a virtual host for the second domain.

sudo nano /etc/nginx/conf.d/

Put the following text into the file.

server {
  listen 80;
  root /var/www/roundcube/;
  index index.php index.html index.htm;

  error_log /var/log/nginx/;
  access_log /var/log/nginx/;

  location / {
    try_files $uri $uri/ /index.php;

  location ~ \.php$ {
   try_files $uri =404;
    fastcgi_pass unix:/run/php/php7.2-fpm.sock;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;

  location ~ /.well-known/acme-challenge {
    allow all;
    deny all;
  location ~ ^/(bin|SQL)/ {
    deny all;
 # A long browser cache lifetime can speed up repeat visits to your page
  location ~* \.(jpg|jpeg|gif|png|webp|svg|woff|woff2|ttf|css|js|ico|xml)$ {
       access_log        off;
       log_not_found     off;
       expires           360d;

Save and close the file. Then test Nginx configurations.

sudo nginx -t

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

sudo systemctl reload nginx

Obtaining TLS Certificate

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


sudo certbot --apache --agree-tos --redirect --hsts --staple-ocsp -d, --cert-name --email [email protected]


sudo certbot --nginx --agree-tos --redirect --hsts --staple-ocsp -d, --cert-name --email [email protected]

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.

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

certbot multi-domain iredmail

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

iredmail nginx multiple domain

Reload Apache or Nginx to pick up the new certificate.

sudo systemctl reload apache2
sudo systemctl reload nginx

You should now be able to use different domains to access RoundCube webmail. Also you need to reload Postfix SMTP server and Dovecot IMAP server in order to let them pick up the new certificate. That’s all you need to do for Postfix and Dovecot to serve multiple domains.

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.

iredmail multiple domain postfix dovecot

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 test email placement with GlockApps.

What if Your Emails Are Still Being Marked as Spam?

I have more tips for you in this article: How to stop your emails being marked as spam. Although it requires some time and effort, your emails will eventually be placed in the inbox after applying these tips.

Wrapping Up

That’s it! I hope this tutorial helped you host multiple email domains with PostfixAdmin. 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: 1 Average: 5]

36 Responses to “How to Host Multiple Mail Domains in PostfixAdmin on Ubuntu

  • Firstly, Thanks for the whole series, I really loved it and helped me a lot.

    If you can help, In Step 5 I cannot see the steps or configuration for Postfix and Dovecot for Multiple Domains.

    It will be really helpful if you can update it.

    Thank you!

    • You just need to reload Postfix and Dovecot to pick up the new certificate which has multiple domains on it. That’s all you need to do for Postfix and Dovecot, when you are using virtual mailbox domains.

      • Okay. Thank you very much!

        I’ll give it a try.

        Is there any changes I have to make in Postfix related myhostname or mymailname ? As I have two different @domain so while sending the emails form which domain it will go ? I might getting confused! 🙂

    • myhostname is only used when Postfix identifies itself to other SMTP servers. It won’t affect your sending domain. mymailname is used for emails without the sending domain specified. That usually happens on the command line.

      If you follow my tutorials, you don’t have to change any of that.

      • Got it! Thanks.

        One last question, I have followed your TLS for postfix using Let’s Encrypt but when I send email to gmail it is showing red lock and not encrypted. I have researched a lot. Mostly, this should resolve my problem smtpd_use_tls=yes but though not working.

        Any Idea!

    • smtpd_use_tls=yes is for the SMTP daemon when receiving emails from other SMTP server.

      To enable TLS when sending emails to other SMTP server, add the following two lines.

      smtp_tls_security_level = may
      smtp_tls_loglevel = 1

      Then restart Postfix.

      PS: This has already been mentioned in part 2 of this tutorial series.

  • This website is the best one that I’ve searched for long time. Help me so much. Really Thanks for the author to share suche detailed knowledge on internet.

  • Hey. First of all, you made a great tutorial for setting up a mail server and it all works fine as long as I have all the domains on the same server where this is set up. I’ve tried setting this part of the tutorial for a domain that is on a different server than where my postfix admin is set. Since I’m new to this and I assume that I made an error in my thinking process I have a question.

    My question is, can this work like this if domains are on different server than where postfix admin is, and if not, what would I actually need to do to make it work?

    • If you have PostfixAdmin on one server, and a domain name is using another mail server to send and receive emails, you can follow this tutorial to add that domain to your PostfixAdmin server, then move your existing email files to the PostfixAdmin server.

      • So I still need to do part 1 of this entire tutorial series on every server where my domains are to just setup Postfix and then I can follow up this part of the series?

        Or do I need to do everything besides setting up new PostfixAdmin on each of the servers?

    • Suppose you have server A, on which you have installed Postfix, Dovecot, PostfixAdmin and OpenDKIM by following part 1 to part 4, so your server A has one mail domain.

      If you need to host a second domain name on server A, then follow this tutorial. You don’t need to do any thing on other servers.

      • That part I know and I’m sorry if I haven’t been very clear up to now, but what you’re explaining to me here revolves only around 1 server and domains on that server, so I’ll try to be as specific as I can be.

        I have Postfix, Dovecot, PostfixAdmin and OpenDKIM all set up on server A which has my main domain and that works great.

        But I also have servers B and C in different areas of the world and I would like, for the domains that are on them ( servers B and C ), to use server A for sending and receiving mail.

        I have tried setting up this part of the tutorial on server A ( considering all the linux part) and server B ( all the MX, TXT, A and AAAA records ), hoping that it’ll be simple as that, but it didn’t work. So that’s where I’m stuck at this point.

    • If you want server B and C to use server A for sending and receiving mail, that’s not hosting multiple domains on one mail server. And it will require some advanced skills. Basically, you need to set up SMTP and IMAP proxy like in this article:, although it’s not 100% in line with your situation.

      • Ah, I see. Well, I did mention that I’m new to this 🙂

        But ok, thanks for the information and the link. I’ve checked it out and I think I understand the process and in worst case scenario, at least I know what to look for and how to explain my problem and that makes a world of difference 🙂

  • Can I add 2 more domains using this guide ?

  • Marshall Latham
    4 months ago

    I am getting the following message from PostfixAdmin: Invalid domain, and/or not discoverable in DNS. I don’t understand what I am doing wrong. I have this domain hosted on a VPS from HostWinds using Nginx. With just a few snags I was able to get the up and running from your tutorials (actually using the email address I configured using your tutorials), but now that I am trying to get a second domain in the system, the control panel is preventing me. I have configured the following:

    Type	Name	Value
    A	mail	
    MX	0
    A	www	

    I have the actual ip4 and ip6 address in the system without the . You can navigate to the under construction web page by going to address. Any idea what I might be missing?

    • Marshall
      4 months ago

      I wasn’t thinking about the information inside of angle braces being removed. The values for the DNS records are the appropriate ip4 and ip6 addresses. These ip addresses are the same as the ip addresses because they are on the same server.

    • I’m also confused. I can visit in my web browser. However, If I use dig to find the A or AAAA record, it seems there’s no such record for your domain.

      dig A +short

      Doing a DNS propagation check on also indicates there’s no A or AAAA record for this domain.

    • I can find the A record for and

      The A record and MX record for can’t be found.

      • Marshall
        4 months ago

        Thank you. I will check that out again and see if I can add some records that might make a difference. I appreciate you looking into this for me. Your tutorials have been a great help to me.

        • Marshall
          3 months ago

          The problem was fixed by a support agent re-entering the DNS records. Thanks again for looking into the problem for me.

  • Hello Xiao
    when using multiple domain we have to have the second domain hosted on the same company? I mean can be on, let’s say’ DigitalOcean and on Vultr?

    Thank You!

    • Your mail server ( and your main website ( can run on different boxes. As a matter of fact, I don’t recommend running mail server and the main website on the same box, because if the main website is behind a CDN (content delivery network), the mail server will leak the website’s real IP address, and the mail server will slow down your website’s page loading speed.

  • Zeeshan Mustafa
    1 month ago

    one issue

    1- modoboa always uses first domain hostname

  • Zeeshan Mustafa
    1 month ago

    i have already follow this but issue is that is using hostname

    what abouot revrse dns

    • There is nothing wrong with that.

      Actually, you should use only one HELO/EHLO hostname in Postfix, and the PTR record should be associated with only one hostname.

  • Zeeshan
    1 month ago

    i have done this but gmail is sending my email to spam
    if u say i can give you control or SSH

  • Hristo Karadzhov
    1 month ago

    Hello Xiao,
    Thank you for the easy to follow and well explained tutorial.
    Fantastic work! It helped me learn a lot.

    With regards to the hosting of multiple domains, is there method of hosting them on a different IPs so the rDNS-es resolve correctly on each domain.
    And also would it be necessary to point different SSL certificate at each domain, so the mail clients don’t scream every time we try to connect.

    hostname =

    Domain IP MX SSL /etc/letsencrypt/live/ … /etc/letsencrypt/live/ … /etc/letsencrypt/live/ …

    Something like that may be if exists…

    Many thanks

    • rDNS is designed to associate one IP address to one hostname. The receiving SMTP server doesn’t care what From: domain is in your email, as long as your IP address has an rDNS record and that hostname can resolve back to the same IP address.

      The certificate in this tutorial is a multi-domain certificate, so mail clients won’t throw security warnings.

  • Cristian
    6 days ago

    Hello Xiao,

    First of all, thank you for your valuable articles, you make our live easier.
    I have successfully configured the email server on one box.
    On a different box I have a website which needs to send reset password emails to the users. Normally I use smtp configuration on the website, I indicate a dedicated email address with password. Well, my email server does not send the emails, most probably because they’re originated from another IP address than the email server’s.
    What would you recommend to make that work?

    Thank you,

    • Cristian
      6 days ago

      Please ignore my message. I discovered it was working, yet I had not configured correctly the smtp port. Thank you anyway.

  • Frederic
    40 mins ago

    Hello Xiao, I’m getting an error after trying to update the certificate

    sudo certbot --apache --agree-tos --redirect --hsts --staple-ocsp -d, --cert-name --email [email protected]


    We were unable to find a vhost with a ServerName or Address of
    Which virtual host would you like to choose?

    it displays several apache conf file, I’ve selected the #5 but it failed (see the attached screenshot)

    Enhancement Strict-Transport-Security was already set.
    Enhancement Strict-Transport-Security was already set.
    Failed redirect for
    Unable to set enhancement redirect for
    Unable to find corresponding HTTP vhost; Unable to create one as intended addresses conflict; Current configuration does not support automated redirection

    I’ve 2 domains ( and both have been configured for running Apache and I’ve followed your Apache tutorial (part 1 & 2 about TLS)…no issue
    The initial mail server is called (works fine here also) and the one I was trying to configure is named

    Any idea what I might be missing ?

    Thank you

    • Frederic
      2 seconds ago

      Nevermin, you can ignore my message, I just missed the part 5 where I needed to configure the vhost for the secodn mail server !

      My bad !!

      Thanks anyway for your GREAT tutorial !

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.
  • Please use the community ( for questions unrelated to this article.
  • I don't have time to answer every question. Making a donation would incentivize me to spend more time answering questions.

The maximum upload file size: 2 MB.
You can upload: image.