Linux Commands and Scripts

Setup your own Email Server in Linux

In this article, we will learn how to setup your own email server in Linux less than 5 minutes. For this demonstration, we will use mailcow docker and Ubuntu server.

When you set up your mail server, you are the only mailbox that sends mail on that site. This means you can assure the server’s privacy is optimum. Managing your mail server means you have the highest degree of protection possible.

You never know what protection protocols can abuse when other mail users are on the same site. When you build your cloud mail server, you’ll never have to worry about sending unwanted mail from other users on the site. It is reliable and easy to manage uptime.

Let’s get started with the installation.

Prerequisites

1. Dedicated server or VPS

2. A domain such as example.com, which will be used to setup an email address such as justin@example.com.

3. After you get the server, request for rDNS. It may take 24 hours to propagate.

4. SSH access of the server with root user.

Mail server installation

Login into the server using SSH.

Step 1: Keep the server up-to-date

It is recommended to keep your server updated.

# apt-get update

Step 2: Install curl and git

# apt-get install curl git

Step 3: Download Docker

# curl -sSL https://get.docker.com/ | CHANNEL=stable sh

Step 4: Download Docker Components

# curl -L https://github.com/docker/compose/releases/download/$(curl -Ls https://www.servercow.de/docker-compose/latest.php)/docker-compose-$(uname -s)-$(uname -m) > /usr/local/bin/docker-compose

Step 5: Update Docker permissions to executable

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

Step 6: Make sure your umask equals 0022.

# umask

Look for output 0022

Step 7: Change into /opt directory

# cd /opt

Step 8: Download Mailcow Files

# git clone https://github.com/mailcow/mailcow-dockerize

Step 9: Change into Mailcow directory

# cd mailcow-dockerized

Step 10: Generate Configuration File

# ./generate_config.sh

Provide the hostname of the mail server that you wish to use. IE: mail.example.com

Step 11: Pull the images

# docker-compose pull

Pulling unbound-mailcow … done
Pulling mysql-mailcow … extracting (100.0%)
Pulling redis-mailcow … extracting (100.0%)
Pulling clamd-mailcow  … digest: sha256:b274121b1eb0b08416…
Pulling php-fpm-mailcow …
Pulling sogo-mailcow … extracting (100.0%)
Pulling dovecot-mailcow …
Pulling postfix-mailcow …
Pulling memcached-mailcow …
Pulling nginx-mailcow …
Pulling rspamd-mailcow …
Pulling acme-mailcow …
Pulling netfilter-mailcow … extracting (100.0%)
Pulling watchdog-mailcow …
Pulling dockerapi-mailcow … done
Pulling ipv6nat …

Step 12: Run the composer file. The parameter -d will start mailcow: dockerized detached:

# docker-compose up -d

Installation is now complete. You can login to mail.example.com with username admin and password moohoo.

Login to mail.example.com with the above username and password to get started.

setup your own email server in Linux

Congratulations, we have seen how to setup your own email server in Linux.

[Need assistance to fix this error or install tools? We’ll help you.]

Related Articles