Why a self-hosted mail server? Most companies have preferred to have their own mail servers rather than to use public mail servers such as google. The advantage of using a self-hosted mail server is that you can have total control over it. Companies also prefer to have their emails use the domains that their websites run on.

What is Mail-in-a-box? Mail-in-a-box enables one to configure a mail server that can be controlled from top to bottom. This means that you will require a server with a fully qualified domain name and IP address that resolves to the FQDN. In this guide we are going to configure mail-in-a-box in a virtual machine running Ubuntu 18.04 operating system.

Mail-in-a-box Features

With Mail-in-a-box as a mail server, you get the enjoy the following features:

  • Provides webmail and an IMAP/SMTP server for use with mobile devices and desktop mail software
  • It uses a web-based control panel for email configurations and settings. The control panel displays comprehensive status checks for DNS records and system activity/monitoring.
  • It includes contacts and calendar synchronization.
  • The box also includes automatic DNS configuration, spam filtering, greylisting backups to Amazon S3, static website hosting, and free TLS (SSL) certificates from Let’s Enrypt.
  • Can host emails for multiple users and domains
  • It implements modern mail protocols (SPF, DKIM and DMARC) and the latest security best practices, including opportunistic TLS, strong ciphers, and HSTS.


To install mail in a box, ensure that you have the following:

  • Fully qualified domain name
  • IP address resolving to the FQDN
  • Properly configured MX record
  • Ubuntu 18.04 Virtual Machine

Install Mail-in-a-box on Ubuntu 20.04|18.04

Ensure you have configured the server hostname and IP addresses. If you have not, run the following commands on your server terminal:

$ sudo hostnamectl set-hostname box.example.com
$ echo " mail.example.com" | sudo tee -a /etc/hosts

Generate ssh key pair

It is recommended to access mail-in-a-box server using ssh instead of default root user and password. Generate ssh key pair on your local machine and copy the public key to your mail-in-a-box server. On your local machine terminal, run the following commands.

$ ssh-keygen

Once your key is saved on your local machine, copy the public key to your remote mail server with the command below:

$ ssh-copy-id [email protected]<your-mail-in-a-box-ip>

Test that you can access your mail-in-a-box using ssh key. Once you log in, disable password authentication.

$ sudo vim /etc/ssh/sshd_config

Change the file from ‘password authentication yes’ to ‘password authentication no

PasswordAuthentication no

Save the file and restart ssh

$ sudo systemctl restart ssh

How To Install Mail-in-a-box Mail Server

Let’s first update our system packages and reboot the server once updated.

$ sudo apt-get update
$ sudo apt-get upgrade
$ sudo reboot

To install mail-in-a-box, run the below command on the terminal

$ curl -s https://mailinabox.email/setup.sh | sudo -E bash

Mail-in-a-box will begin installation. You will be prompted to set an email address that you will use for configurations and server hostname. Set them as required. You will first see an introductory message as below:

Press Enter to continue. The next dialogue box will require you to enter an email address which will be used to manage the mail server. Key in the email ID and press Enter

Next, enter the server FQDN

A successful installation will output the below:

Installing nsd (DNS server)... 
Generating DNSSEC signing keys... 
Installing Postfix (SMTP server)... 
Installing Dovecot (IMAP server)... 
Creating new user database: /home/user-data/mail/users.sqlite 
Installing OpenDKIM/OpenDMARC... 
Installing SpamAssassin... 
Installing Nginx (web server)... 
Installing Roundcube (webmail)... 
Installing Nextcloud (contacts/calendar)... 

Upgrading to Nextcloud version 17.0.6 

Nextcloud is already latest version 
Installing Z-Push (Exchange/ActiveSync server)... 
Installing Mail-in-a-Box system management daemon... 
Installing Munin (system monitoring)... 
updated DNS: box.example.com
web updated 

Okay. I'm about to set up [email protected] for you. This account will also 
have access to the box's control panel. 
mail user added 
updated DNS: OpenDKIM configuration 
web updated 

Mail-in-a-Box uses Let's Encrypt to provision free SSL/TLS certificates 
to enable HTTPS connections to your box. We're automatically 
agreeing you to their subscriber agreement. See https://letsencrypt.org. 

Saving debug log to /var/log/letsencrypt/letsencrypt.log 
Registering without email! 

- Your account credentials have been saved in your Certbot 
  configuration directory at /home/user-data/ssl/lets_encrypt. You 
  should make a secure backup of this folder now. This configuration 
  directory will also contain certificates and private keys obtained 
  by Certbot so making regular backups of this folder is ideal. 


Your Mail-in-a-Box is running. 

Please log in to the control panel for further instructions at: 


You will be alerted that the website has an invalid certificate. Check that 
the certificate fingerprint matches: 


Then you can confirm the security exception and continue.

Accessing Mail-in-a-box Control Panel

Access your mail-in-a-box web control panel using the server IP address: https://<your-mail-server-ip>/admin.

You should see a login page as below:

Login with email account and password that you set during installation. Once you are in you should see a screen as below showing system status.

Go through the status check and correct/configure where needed. Once done, click on Reboot box to apply the settings. Once rebooted login again from the browser. You can go ahead to perform more configurations specific to your mail server. Click on system and check the dropdown menu.

Under Mail tab, check on the information concerning your server. You will also be able to set up users and aliases. Here, you will see the emails url, DNS settings and settings for manual desktop client configurations. Calender/Contacts tabs shows calender/contacts urls.

Mail-in-a-box user management.

You can add users and set permissions (normal user and administrator) under mail→ users.

Access Mail-in-a-box Webmail

Use the url as shown in mailinstructions: https://<box.example.com>/mail. You should get a login screen as below.

Login with an already created username and password.

That’s it. You have successfully configured Mail-in-a-box mail server on Ubuntu 18.04. Check below more interesting Linux guides:


  1. Hello there, nice article you have, but see on curl -s https://mailinabox.email/setup.sh | sudo -E bash command when I try to issue it on ubuntu 20.04 server doesn’t allow me to go through. It is saying that the script is meant for 18.04 or 14.04.. little help here please
    thank you in advance


Please enter your comment!
Please enter your name here