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.
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:
- The hostname of your server should be "mail", so the FQDN should be "mail.testdomain.com".
- Add an A record for the subdomain "mail" (mail.testdomain.com) and let this point to the IP address of the mail server.
- Add an MX record for your domain and set the value to the mail subdomain you just created (mail.testdomain.com) with priority 10.
- 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).
- 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).
- 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.
- If you havn't already done so, download the program "PuTTY".
- 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.
- Update your package lists with the command
- Now install any available updates of the packages already installed on your server using the command
apt upgrade -y.
- Next, install the packages needed for future installations in this tutorial by executing the following command:
apt install curl nano git -y
- Install Docker by completing the following steps:
- Execute the command
curl -sSL https://get.docker.com/ | CHANNEL=stable shto download the Docker installation script and to install Docker.
- Activate the Docker service with the following command:
systemctl enable docker.service
- Then start the Docker service by using the command
systemctl start docker.service
- Execute the command
- 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.
- Then use the command
chmod +x /usr/local/bin/docker-composeto assign the required execution permissions to Docker Compose.
- Run the command
cd /optto change to the directory "/opt"
- Download Mailcow/the master branch of the corresponding repository with the following command:
git clone https://github.com/mailcow/mailcow-dockerized
- Execute the command
cd mailcow-dockerizedto go to the Mailcow directory.
- 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.
- 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.
- Download the images needed for Mailcow with the following command:
- Now start the Mailcow container by executing the command
docker-compose up -d.
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:
- Run the command
cd /opt/mailcow-dockerized/to change to the Mailcow directory.
- Open the Nginx configuration file using the command
- Add the following content to the top of this configuration file:
- Save the changes to this configuration file by pressing CTRL + X, then hit the "Y" key followed by enter.
- Now restart Nginx. To do this, use the command
docker-compose restart nginx-mailcow. All HTTP requests will now be automatically redirected to HTTPS.
- Run the command
- 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").
- Log in with the username "admin" and the default password "moohoo".
- Click on "Edit" right next to the "admin" user under "Edit administrator details".
- 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.
- Click on "Configuration" in the top menu and then click on "Mail Setup" to switch to the mail configuration.
- 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".
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
- 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.
- Log in to the Mailcow web interface and click on "Configuration" at the top menu. Then click on "Configuration & Details".
- Go to the "Configuration" tab and enter your domain in the "Domain(s)" text box under "Add ARC/DKIM key".
- You can leave the DKIM selector (text box "Selector") at "dkim" or you can change it if you want.
- Then select "2048 bits" as the "DKIM key length (bits)" in the dropdown menu.
- Click on the "Add" button to generate a DKIM key for your domain.
- 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".
- 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:
- 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.
- Now log in to the webmail client. Enter the complete e-mail address of the mailbox as user name and enter the corresponding password.
- 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:
|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|