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.

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:

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.

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.

mc-admin-2

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.

mc-mailbox

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.

5 comments

  1. I’m curious how you found out about the Mailcow container. Is there a list somewhere of all the containers that are available for Docker? I’m guessing that if there’s a container for something like a mail server, there’s one for something like a web server (Nginx or Apache), and probably other things as well.

  2. sorry, but this line didn’t work:

    sudo add-apt-repository “deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable”

    because the next line results in errors:

    E: The repository ‘https://download.docker.com/linux/ubuntu xenial Release’ does not have a Release file.

  3. Hi, trying to set this up as a newbit.

    when I got to “sudo docker-compose up -d”, it showed me this error: ERROR: for unbound-mailcow Container “4d308fc148e0” is unhealthy.

    when I ran “docker logs 4d308fc148e0”, it showed the following 15 times:
    error: database is uninitialized and password option is not specified
    You need to specify one of MYSQL_ROOT_PASSWORD, MYSQL_ALLOW_EMPTY_PASSWORD and MYSQL_RANDOM_ROOT_PASSWORD

    thoughts?

    thanks in advance…

  4. I ended up commenting the health checks, then ran “generate_cnofig.sh” and finally the command again…I am now up!!!

Comments are closed.

Sponsored Stories