How to Create an Email Server in Linux with Mail-In-A-Box

A screenshot of a phone screen showing the Mail app icon.

Mail-in-a-Box is a small, yet effective program that aims to create an easy to deploy, all-in-one email server solution in your machine. This tutorial shows you how you can install Mail-In-A-Box on Ubuntu Linux.

Why Host Your Own Email Server

One of the biggest advantages of hosting your own email server is that it gives you privacy over your own data. Unlike a webmail service such as Gmail, running Mail-in-a-Box guarantees that there is no middle man between you and your emails.

A screenshot of a GMail inbox with advertisements.

A self-hosted server also gives you the flexibility with how you want to interact with your email. For example, Gmail uses tags instead of folders for organizing messages. This often breaks offline clients that try and fetch email from Gmail accounts.

A screenshot of a GMail mail directory in an offline client.

Lastly, hosting your own server lets you bypass identity checks when creating an email account. This is useful if you are privacy conscious and you do not want to share your information with third-party providers.

A screenshot of the Gmail account creation where it asks for a phone number.

Good to know: Privacy practices does not stop at creating your own email server. Learn how you can further protect yourself online by installing a group collaboration software like Citadel.

Preparing Your Email Server

Before you can install Mail-in-a-Box, you need to make sure that you have a running server and a domain name. This article is done on an Ubuntu VPS from Digitalocean.

Tip: If you are already running your own VPS, you can also install the Mailcow email server.

A screenshot of a Digitalocean droplet summary screen.

To get started, you need to configure your domain as a name server that points to your own machine. This is important since Mail-in-a-Box manages its own DNS records internally.

Note: The configuration for each domain registrar is different, so we won’t go through the instruction to create a nameserver. What you need to do is to create two nameservers: and pointing to the IP address of your server. You should also change your domain’s nameserver record to the one you have created.

A screenshot of the nameserver entries page.

FYI: You should never use your Mail-in-A-Box server to run email marketing campaigns as you could risk your server’s IP address being banned. Make use of these email marketing platforms instead.

Updating Your Machine’s Hostname

With your domain name and nameserver properly configured, you need to now modify your machine’s hostname. This will allow Mail-in-a-Box to properly set its default values during installation.

You can do this in Digitalocean by doing the following:

  1. Go to your droplet’s status page.
A screenshot of a Digitalocean droplet.
  1. Click the droplet’s name, replace it with your domain name and click the check mark to save it.
A screenshot of the machine's hostname in Digitalocean.
  1. Login to your VPS instance as root and run the following command:
echo "box" > /etc/hostname
A terminal window showing the contents of /etc/hostname.
  1. Next, run the following command to change your machine’s “/etc/hosts” file to your current domain name:
awk '$1 == "" { print $2 }' /etc/hosts | sed -i s/.*/
awk '$1 == "" { print $3 }' /etc/hosts | sed -i s/.*/box/
A terminal window showing the contents of /etc/hosts
  1. Reboot your machine to apply your new changes.
A terminal window showing the current system hostname.

Installing Mail-in-a-Box

With those done, you can now start installing Mail-in-a-Box in your machine.

  1. Begin the process by obtaining Mail-in-a-Box’s installation script:
curl -s | sudo -E bash
  1. Provide the email address that you want to use for your mail server.
A terminal window showing the installer script asking for the first email address.
  1. Provide a hostname for your mail server. In my case, I will use the default “”
A terminal window showing the system's current hostname in full.
  1. The installation script will then ask you for a timezone. For this, you need to provide your current timezone instead of the server’s physical location.
A terminal window showing a selection of timezone data.
  1. Write the password that you want to use for your email account.
A terminal window showing the password prompt for the new email account.

Tip: If you are using Outlook instead, learn how you can schedule your emails in Outlook.

Configuring Your Email Server

At this point, you now have a properly installed Mail-in-a-Box server in your machine. However, you still need to configure some of its settings to use it properly.

  1. Open the link that the installer wrote at the end of the script.
A terminal window showing the administrator address for the server.

When loading the website, your browser might throw a security exception at you. This is because Mail-in-a-Box uses a self-signed certificate for its initial website.

You can safely bypass this error by clicking “Advanced,” then “Accept the Risk and Continue.”

A screenshot showing the self-signed certificate error in Firefox.
  1. Login to your Mail-in-a-Box instance by providing your new email account and password.
A screenshot showing the email server's login page.
  1. Click “System,” then “TLS (SSL) Certificates.”
A screenshot showing the SSL certificates menu in the email server.
  1. Click the “Provision” button to create an SSL certificate for your server’s subdomains.
A screenshot showing the various SSL options for the email server.

There are instances where Mail-in-a-Box will not request an SSL certificate for all of your subdomains. You can fix this by clicking the “Provision” button again.

  1. Click “System,” then “Status Checks” to confirm that everything is working properly.
A screenshot showing the current status of the email server.

Tip: Learn more about SSL and encryption by creating your own self-signed certificate using OpenSSL.

Sending and Verifying Your First Email

From here, you can now login and use your Mail-in-a-Box server. Unlike other self-hosted mail solutions, Mail-in-a-Box provides a simple and intuitive web interface that you can immediately use and start with. This means that you do not need to install any external mail clients to use Mail-in-a-Box.

  1. Access the web interface in your browser by typing: “”
A screenshot of the email server's login page.
  1. Type your new email address and password in the server’s login page.
A screenshot of the email server login page filled with user credentials.
  1. Click the “Compose” button to create a new email message.
A screenshot of the email server's webmail client.
  1. Provide a valid email recipient and write a simple test message.
A screenshot showing a test email being sent to a test address.
  1. Once done, click the “Send” button.
  1. Lastly, check whether your mail arrived to its intended recipient by loading its own inbox.
A screenshot of the recipient getting his email.

Tip: There are times when a disposable email is useful. Check out these providers for disposable and throwaway emails.

Frequently Asked Questions

Is it possible to reconfigure my email server after installation?

Yes. You can reconfigure any of the server’s internal settings by going to your machine’s console and running the following command: sudo mailinabox.

Can I create a different email account in my Mail-in-a-Box server?

Yes. By default, Mail-in-a-Box allows you to create multiple email accounts in the same server. To do this, go to your Mail-in-a-Box administrator page, click “Mail & Users,” then “User.” This will load a prompt where you can provide an email address and password for a new user.

My mail is not arriving to its intended recipient.

The most likely cause of this is that your machine’s IP address is in an email blocklist. To fix this issue, you can either request for a new, “non-blocklist” IP address from your service provider or create a new VPS instance. Another way is to make use of a third-party SMTP server to help you send your mails.

Image credit: Brett Jordan via Unsplash. All alterations and screenshots by Ramces Red.

Ramces Red
Ramces Red

Ramces is a technology writer that lived with computers all his life. A prolific reader and a student of Anthropology, he is an eccentric character that writes articles about Linux and anything *nix.

Subscribe to our newsletter!

Our latest tutorials delivered straight to your inbox