Community Blog How to Install Mail-in-a-Box on Ubuntu 16.04

How to Install Mail-in-a-Box on Ubuntu 16.04

In this tutorial, we will be installing Mail-in-a-Box on an Alibaba Cloud ECS with Ubuntu 16.04.

By Hitesh Jethva, Alibaba Cloud Tech Share Author. Tech Share is Alibaba Cloud's incentive program to encourage the sharing of technical knowledge and best practices within the cloud community.

Mail-in-a-Box is an open source software that allows you to become your own mail service provider in a few easy steps. You can easily turn your fresh system into a working mail server. You don't need to be a technology expert to set it up. Mail-in-a-Box comes with lots of security features including, Fail2ban, UFW, graylisting, SPF, DKIM, DMARC, opportunistic TLS, strong ciphers, HSTS, and DNSSEC, making it easy to host a full-stack email solution for multiple domains.

Mail-in-a-Box uses the following components:

  1. Postfix: Used as the Simple Mail Transfer Protocol.
  2. Dovecot : Used as the Internet Message Access Protocol (IMAP), allowing you to sync your mail with an IMAP client such as your phone.
  3. Roundcube webmail : Used to manage your email through the web browser.
  4. Control Panel : Used to manage your mail server, including adding or removing mailboxes, changing passwords, backing up data, and changing DNS settings.
  5. Nsd4 Domain Name System : Allow you to add DNS entries to configure Sender Policy Framework (SPF), DomainKeys Identified Mail (DKIM) and Domain-based Message Authentication.

In this tutorial, we will be installing Mail-in-a-Box on an Alibaba Cloud Elastic Compute Service (ECS) Ubuntu 16.04 server.


  1. A fresh Alibaba Cloud Ubuntu 16.04 instance.
  2. Your domain provider needs to support setting custom nameservers and glue records so you can host your own DNS on your instance.
  3. A root password is set up to your instance.

Launch Alibaba Cloud ECS Instance

First, log in to your Alibaba Cloud ECS Console. Create a new ECS instance, choosing Ubuntu 16.04 as the operating system with at least 2GB RAM. Connect to your ECS instance and log in as the root user.

Once you are logged into your Ubuntu 16.04 instance, run the following command to update your base system with the latest available packages.

apt-get update -y

Set Up Hostname

Before starting, you will need to setup hostname of the instance. You can do this with the following command:

nano /etc/hostname

Add the following lines:


Save and close the file. Then, you will need to modify the /etc/hosts file to associate the hostname with the server's IP address.

nano /etc/hosts

Add the following lines:

your-server-ip test.example.com test

Save and close the file, when you are finished.

Configure Domain Name

It is recommended to delegate DNS responsibilities to the Mail-in-a-Box server. To do so, you will need to set up glue records so you can securely and correctly set up the server for email.

First, log in to your account on your domain name registrar's site and set up a Glue Record for your domain.

Next, open your DNS panel and add the following records

ns1.test.example.com your-server-ip
ns2.test.example.com your-server-ip

Note: Replace test.example.com with your FQDN and your-server-ip with the IP address of your new server.

Install Mail-in-a-Box

You can install Mail-in-a-Box easily using Mail-in-a-Box installation script. You can run this script with the following command:

curl -s https://mailinabox.email/bootstrap.sh | bash

The installation script will prepare Mail-in-a-Box installer to run. Once it completed, you should see the following thanks screen which says that the installer will ask us some answers required for the complete installation of Mail-in-a-Box.


Here, click on the OK button. You should see the following page:


Here, provide your first email address that you will use to your Mail-in-a-Box control panel and use as the default email address for your server. Then, click on the OK button, you should see the following page:


Now, provide hostname of your server and click on the OK button. You should see the following page:



Now, select your country and region corresponding with your timezone. Then, click on the OK button. You should see the following page:


Here, provide your default email address to log in to the control panel. Then, click on the OK button. Once the installation has been completed successfully. You should see the following output:

Mail-in-a-Box uses Let's Encrypt to provision free certificates
to enable HTTPS connections to your box. You'll now be asked to agree
to Let's Encrypt's terms of service.

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

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must
agree in order to register with the ACME server at
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(A)gree/(C)ancel: A

 - 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.

Access Mail-in-a-Box

Mail-in-a-Box is now installed and configured. It's time to access it through the web browser.

Open your web browser and type the URL https://your-server-ip/admin. You will get a security warning in your browser window.


Simply ignore the error and click on the Add Exception button. You should see the following page:


Now, click on the Confirm Security Exception button. You will be redirected to the Mail-in-a-Box login page as shown below:


Now, provide your email address and password. Then, click on the Sign In button. You will be redirected to the Mail-in-a-Box default dashboard as shown below:


That's it.

Congratulations! You have successfully installed and configured Mail-in-a-Box server on an Alibaba Cloud Elastic Compute Service with Ubuntu 16.04. You can now add additional email addresses to your Mail-in-a-Box server and deploy it in the production environment. You are recommended to add a CA Certificate so that you can use your Mail-in-a-Box in secure production environment.

Related Alibaba Cloud Products

Alibaba Cloud DirectMail is a simple and efficient service to send email notifications and batch email quickly and efficiently without the need to build your own email server. DirectMail is a key product for serving Alibaba's own e-commerce platforms, which includes servicing Alibaba's record-breaking annual sales festival.

DirectMail guarantees stable and high conversion rates across various mail channels. Emails can be sent with the product console, API interface, and SMTP interface.

1 0 0
Share on

Alibaba Clouder

2,605 posts | 747 followers

You may also like


5179851025491276 February 24, 2019 at 4:26 pm

Mujhe adhar cad check karna h