There are plenty of reasons you’d want to run your own mail server. Privacy, security, and customization are just a few.

Putting together a custom mail server is a huge pain. It’s really not something that you’d want to do, let alone maintain. Thankfully, there are several nice options that provide turn-key solutions. This guide is going to focus on Mailcow.

Mailcow provides absolutely everything that you need for an email server pre-configured and bundled in a convenient Docker container. It even has a management interface for you to easily stay on top of your server.

This guide doesn’t cover absolutely everything involved in running a professional mail server; there’s just too much. You will need a web hosting company and a domain name. You will have to configure your DNS records on that web host. Since that configuration is specific to the company, there’s no way to cover it here.

Get Docker

Mailcow runs within a Docker container. If you’ve never heard of Docker before, don’t worry; you don’t need to be an expert to follow this guide. Just know that Docker containers act kind of like partial virtual machines. They create separate compartments where you can install software without it interfering with the rest of the system. That’s what allows Mailcow to arrive already set up and pre-assembled.

To install Docker, simply run the following commands:

Once it is completed, you might want to add your username to the “docker” group so you can execute docker as user (and not as root).

Replace “username” with your login username.

Next, set Docker to auto start during login:

Get Docker-Compose

You’re also going to need another tool for Docker. You need to install that too. Unfortunately, the version in Ubuntu’s repositories is really out of date, so we will grab the files directly from its source:

The above command will fetch docker-compose from github and move it to “/usr/local/bin” folder.

Grant it executable permission:

To test if it is installed properly:

You should see something like this:

Get and Install Mailcow

With Docker installed and working, you can grab the Mailcow container and install it on Ubuntu. Mailcow is available from Github, so you can just clone the repository. If you don’t already have Git, install that first.

Next, we will install mailcow in the “/opt” location. This will require root (superuser) permission.

Run the set up script:

It will prompt you for the hostname (it need to be a proper subdomain name, like “mail.yourdomain.com”). After that, it will generate the “mailcow.conf” file, which contains all the configuration option.

The default configuration will work fine, but you can edit the options in “mailcow.conf” file to customize your mailserver.

Pull The Docker Dependencies

Lastly, use the docker-compose tool that you installed earlier to pull in all of Mailcow’s dependencies.

The download is going to take a while to download everything. Sit back and relax for a bit while it does.

Run Mailcow

After the download finishes, you can start your Mailcow server.

First Run

With the Docker container up and running, you can access your mail server via its web interface. Navigate in your browser to the address that you set up when the configuration script asked you for one.

The Mailcow interface should pop up. The default admin login credentials are “username: admin, password: moohoo.” Once you log in, Mailcow will ask you to change that username and password.

After you update your login info, you can use the Mailcow interface to set up different email domains and start stetting up users and inboxes. You can now manage everything from Mailcow.

Final Thoughts

If you followed these steps, you do not have a production-ready email server. As stated above, you need to set up your DNS records through your hosting provider to make sure that you mail doesn’t get blocked as spam.

You’re also going to need to set up firewall rules and basic security configurations to protect your server as a whole. Make sure that you’re using best security practices before officially launching your server.