Hint: You can use the Tab key to autocomplete all filenames and directories, so you don't have to type in the complete file or directory name manually.

Note: This tutorial uses the domain "testdomain.com" as an example. Whenever "testdomain.com" is mentioned, you must of course use your domain instead of this example domain.

This tutorial was last checked and updated on January 27, 2019.

Are you looking for very good, powerful and cheap servers? I've been renting my servers at Contabo for 5 years now and I can highly recommend Contabo to everyone!
Preparations

Before you can start installing Mailcow, you need to do some preparations, which mainly affect the DNS settings of the domain that you want to use to receive and send e-mails. To do this, follow the steps below:

  1. The hostname of your server should be "mail", so the FQDN should be "mail.testdomain.com".
  2. Add an A record for the subdomain "mail" (mail.testdomain.com) and let this point to the IP address of the mail server.
  3. Add an MX record for your domain and set the value to the mail subdomain you just created (mail.testdomain.com) with priority 10.
  4. Define a CNAME record for the subdomains "autodiscover" as well as "autoconfig" and set the destination of both CNAME records to the mail subdomain as well (mail.testdomain.com).
  5. Add an TXT record for your domain and set the value to "v=spf1 mx ~all", to allow the server specified in the MX record (the mail server where Mailcow will be installed) to send e-mails with your domain as the sender domain. The "~all" means that other servers are not allowed to send e-mails from your domain, but these e-mails will still be delivered (softfail).
  6. Define a PTR record (Reverse DNS) for the IP address of your server and set the value to the FQDN of your server ("mail.testdomain.com"). You can set this PTR record directly in the web interface of any good hoster like Contabo. For some providers, you have to write an e-mail or open a support ticket.
Mailcow Installation
  1. If you havn't already done so, download the program "PuTTY".
  2. Connect to your root server or VPS/vServer via SSH using PuTTY. To do this, open PuTTY and enter the domain or IP address of your server in the text box named "Host Name (or IP address)". Then click the "OK" button below.
  3. Update your package lists with the command apt update.
  4. Now install any available updates of the packages already installed on your server using the command apt upgrade -y.
  5. Next, install the packages needed for future installations in this tutorial by executing the following command: apt install curl nano git -y
  6. Install Docker by completing the following steps:
    1. Execute the command curl -sSL https://get.docker.com/ | CHANNEL=stable sh to download the Docker installation script and to install Docker.
    2. Activate the Docker service with the following command: systemctl enable docker.service
    3. Then start the Docker service by using the command systemctl start docker.service
  7. Now download Docker Compose with the command 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.
  8. Then use the command chmod +x /usr/local/bin/docker-compose to assign the required execution permissions to Docker Compose.
  9. Run the command cd /opt to change to the directory "/opt"
  10. Download Mailcow/the master branch of the corresponding repository with the following command: git clone https://github.com/mailcow/mailcow-dockerized
  11. Execute the command cd mailcow-dockerized to go to the Mailcow directory.
  12. Now the configuration file for Mailcow needs to be generated. Use the command ./generate_config.sh. You will then be asked for an FQDN. Enter the FQDN of your server ("mail.testdomain.com") and press enter. You can skip the question about the time zone by pressing enter, because the correct time zone should already be set by default.
  13. The configuration file is now generated. You can optionally customize it with the command nano mailcow.conf, if you, for example, already have a web server installed and you therefore have to use different ports ("HTTP_PORT" and "HTTPS_PORT") for the Mailcow web server. You can also change the value of the parameter "SKIP_LETS_ENCRYPT" to "y" if you don't want an SSL certificate to be automatically requested/issued from Let's Encrypt. If you made changes to this configuration, save them by pressing CTRL + X, then hit the "Y" key and press enter.
  14. Download the images needed for Mailcow with the following command: docker-compose pull
  15. Now start the Mailcow container by executing the command docker-compose up -d.
  16. Mailcow automatically requests a Let's Encrypt SSL certificate for the domain you specified as the hostname ("acme-mailcow" container), unless this feature has been explicitly disabled within the configuration file. Thus, you can visit the Mailcow web interface via HTTPS. To automatically redirect HTTP requests to HTTPS, perform the following steps:
    1. Run the command cd /opt/mailcow-dockerized/ to change to the Mailcow directory.
    2. Open the Nginx configuration file using the command nano data/conf/nginx/site.conf.
    3. Add the following content to the top of this configuration file:
    4. Save the changes to this configuration file by pressing CTRL + X, then hit the "Y" key followed by enter.
    5. Now restart Nginx. To do this, use the command docker-compose restart nginx-mailcow. All HTTP requests will now be automatically redirected to HTTPS.
Mailcow Configuration
  1. Open the Mailcow web interface under the domain of your server in your web browser via HTTPS. If you have changed the web server port in the configuration file, you must now of course specify this port (e.g. "https://mail.testdomain.com:4343").
  2. Log in with the username "admin" and the default password "moohoo".
  3. Click on "Edit" right next to the "admin" user under "Edit administrator details".
  4. Change the password of the administrator user. You can also change the username if you want. After you've done this, click on the "Save changes" button.
  5. Click on "Configuration" in the top menu and then click on "Mail Setup" to switch to the mail configuration.
  6. Select the tab "Domains" and add your domain by clicking on the "Add domain" button. In the dialog that appears, enter the domain in the "Domain" text box and a description in the "Description" text box. You can change the rest of the settings (e.g. the maximum amount of possible mailboxes or the mailbox quota), but the default values should be fine in most cases. Next, click on the button called "Add domain and restart SOGo".
  7. Switch to the "Mailboxes" tab and add a new mailbox by clicking on "Add mailbox". You have to enter the following information:
    • Username: Left part of the e-mail address (before the "@")
    • Domain: Domain to which the mailbox belongs
    • Full name: First and last name of the mailbox user
    • Quota (MiB): Quota of this mailbox (default 3072 MiB)
    • Password: Password of the mailbox user
    Then click on the "Add" button to create the mailbox.
  8. Mailcow is now basically set up. However, it's recommended to perform further configurations such as the DKIM configuration. The DKIM configuration is explained in the next step of this tutorial. For further information, the Mailcow documentation is very helpful.
DKIM Configuration
  1. Log in to the Mailcow web interface and click on "Configuration" at the top menu. Then click on "Configuration & Details".
  2. Go to the "Configuration" tab and enter your domain in the "Domain(s)" text box under "Add ARC/DKIM key".
  3. You can leave the DKIM selector (text box "Selector") at "dkim" or you can change it if you want.
  4. Then select "2048 bits" as the "DKIM key length (bits)" in the dropdown menu.
  5. Click on the "Add" button to generate a DKIM key for your domain.
  6. Now copy the contents of the text box above (public key matching the domain, starting with "v=DKIM1;k=rsa;t=s;s=email;p=") under "ARC/DKIM keys".
  7. Finally, add a TXT record for "dkim._domainkey.testdomain.com" (matching the DKIM selector) in your domain's DNS settings and set the previously copied content from the text box as the value of this TXT record.
Using the Webmail Client "SOGo"

Of course, you can use mail clients like Thunderbird or Outlook, but Mailcow also offers it's own webmail client. Using this webmail client, you can also read your e-mails directly in the browser:

  1. In the top menu of the Mailcow web interface, click on "Apps" and then click on "SOGo" or open the webmail client directly by appending "/SOGo" to the domain of your server.
  2. Now log in to the webmail client. Enter the complete e-mail address of the mailbox as user name and enter the corresponding password.
  3. You should already see an e-mail in the inbox, because a personal calendar was automatically created for you. Now you can use the SOGo webmail client.
Setting up a Mail Client (e.g. Thunderbird)

Of course, you can also add your mailboxes to traditional mail clients such as Thunderbird, Outlook or Apple Mail. Usually, you only need to specify the username (e-mail address of the mailbox) and the password. The server settings should be determined automatically. If this doesn't work, use the following server settings:

Server Protocol Server Hostname Port SSL Authentication
Incoming IMAP FQDN of the mail server (usually mail.testdomain.com) 993 SSL/TLS Normal password
Outgoing SMTP FQDN of the mail server (usually mail.testdomain.com) 465 SSL/TLS Normal password