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.
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.
Install the Docker Repository
In order to ensure that you have the most up-to-date version of Docker, it’s best to install the Docker repository on Ubuntu. Start by grabbing the dependencies that you’ll need.
sudo apt install apt-transport-https ca-certificates curl software-properties-common
cURL to grab Docker’s GPG key and add it.
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
Finally, add the repository to Ubuntu.
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
Install Docker with Apt
Update your package listing and install Docker. Docker recommends specifying the version that you want to install on production systems. This just helps guarantee stability.
sudo apt update sudo apt-cache madison docker-ce
apt-cache, you’ll see the version listed. You can pick the latest version now, and you’ll stick with that until there is a reason to upgrade beyond it.
sudo apt install docker-ce=17.03.1~ce-0~ubuntu-xenial
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. Since it’s a Python package, it is available with the
pip Python package installer. Install Pip and use it to install
sudo apt install python-pip sudo pip install --upgrade pip sudo pip install docker-compose
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 git clone https://github.com/mailcow/mailcow-dockerized cd mailcow-dockerized
Once you’re in the newly-cloned folder, you can run the script in there that generates your configuration file. Provide your domain name and timezone when you’re asked for them.
Pull The Docker Dependencies
The script won’t take long. When it finishes, 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.
After the download finishes, you can start your Mailcow server.
sudo docker-compose up -d
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.
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.