How to Set Up an Email Server in Ubuntu

How To Setup Email Server Ubuntu

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:

sudo curl -sSL | CHANNEL=stable sh

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

sudo usermod -aG docker username

Replace “username” with your login username.

Next, set Docker to auto start during login:

sudo systemctl enable docker.service
sudo systemctl start docker.service

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:

sudo curl -L "$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

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

Grant it executable permission:

sudo chmod +x /usr/local/bin/docker-compose

To test if it is installed properly:

docker-compose --version

You should see something like this:

docker-compose version 1.23.1, build b02f1306

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.

sudo apt install git

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

cd /opt
sudo git clone
cd mailcow-dockerized

Run the set up script:

sudo ./

It will prompt you for the hostname (it need to be a proper subdomain name, like “”). 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.

sudo docker-compose pull

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.

sudo docker-compose up -d

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.

Log In To Mailcow

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.

Nick Congleton
Nick Congleton

Nick is a freelance tech. journalist, Linux enthusiast, and a long time PC gamer.

Subscribe to our newsletter!

Our latest tutorials delivered straight to your inbox