Uploaded by amadou diallo

Tutorial: How to Install and Configure Mailcow (Mail Server) - Bennet Richter

advertisement
Tutorial: How to Install and Configure Mailcow (Mail Server) - Bennet Richter
12/21/23, 4:24 PM
How to Install and Configure Mailcow (Mail Server)
This tutorial explains how to easily and quickly install and configure the Mailcow (Dockerized) mail server on your Linux
root server or VPS/vServer. To do this, please follow these steps.
Hint: You can use the Tab key to autocomplete all filenames and directories, so you don't have to type in
Visitor Counter
the complete file or directory name manually.
Total views:
Note: This tutorial uses the domain "testdomain.com" as an example. Whenever "testdomain.com" is
3,228,128
mentioned, you must of course use your domain instead of this example domain.
This tutorial was last checked and updated on April 3, 2023.
Are you looking for very good, powerful and cheap servers? I've been renting my servers at Contabo
Unique visitors (counted
only once a day):
2,015,098
for more than 10 years 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 emails 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".
https://www.bennetrichter.de/en/tutorials/mailcow-dockerized/#:~:…=Enter%20your%20domain%20in%20the,change%20it%20if%20you%20want.
Page 1 of 5
Tutorial: How to Install and Configure Mailcow (Mail Server) - Bennet Richter
2.
12/21/23, 4:24 PM
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 apt-transport-https ca-certificates gnupg2 softwareproperties-common -y 
6.
Install Docker by completing the following steps:
1.
Use the following command to add the key needed for the Docker repository:
For Debian: curl -fsSL https://download.docker.com/linux/debian/gpg | gpg --dearmor -o
/usr/share/keyrings/docker-archive-keyring.gpg 
For Ubuntu: curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor o /usr/share/keyrings/docker-archive-keyring.gpg 
2.
Add the repository needed to install Docker by executing this command:
For Debian: echo "deb [arch=$(dpkg --print-architecture) signedby=/usr/share/keyrings/docker-archive-keyring.gpg]
https://download.docker.com/linux/debian $(lsb_release -cs) stable" | tee
/etc/apt/sources.list.d/docker.list 
For Ubuntu: echo "deb [arch=$(dpkg --print-architecture) signedby=/usr/share/keyrings/docker-archive-keyring.gpg]
https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | tee
/etc/apt/sources.list.d/docker.list 
7.
3.
Now update your package lists again with the command apt update  .
4.
Install Docker with the following command: apt install docker-ce docker-ce-cli -y  .
Now download Docker Compose with the command curl -L
https://github.com/docker/compose/releases/download/v$(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
https://www.bennetrichter.de/en/tutorials/mailcow-dockerized/#:~…=Enter%20your%20domain%20in%20the,change%20it%20if%20you%20want.
Page 2 of 5
Tutorial: How to Install and Configure Mailcow (Mail Server) - Bennet Richter
12/21/23, 4:24 PM
("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. Finally, select the
branch "master" by typing "1" and pressing enter.
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.
Create an Nginx configuration file using the command nano /opt/mailcowdockerized/data/conf/nginx/redirect.conf  .
2.
Add the following content to this configuration file:
 Show content
3.
Save the changes to this configuration file by pressing CTRL + X, then hit the "Y" key followed
by enter.
4.
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:4433").
2.
Log in with the username "admin" and the default password "moohoo".
3.
Click "System" at the top menu and then "Configuration".
4.
Click on "Edit" right next to the "admin" user under "Edit administrator details".
5.
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.
6.
Click on "E-Mail" in the top menu and then click on "Configuration" to switch to the mail
configuration.
7.
The tab "Domains" is already selected. 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".
https://www.bennetrichter.de/en/tutorials/mailcow-dockerized/#:~…=Enter%20your%20domain%20in%20the,change%20it%20if%20you%20want.
Page 3 of 5
Tutorial: How to Install and Configure Mailcow (Mail Server) - Bennet Richter
8.
12/21/23, 4:24 PM
Switch to the "Mailboxes" tab, click "Mailboxes" there again 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.
9.
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 "System" at the top menu. Then click on
"Configuration".
2.
Click on the "Options" tab and then on "ARC/DKIM keys"
3.
For each configured domain, a DKIM key with the selector "dkim" and a key length of 2048 bits is
already generated automatically. 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".
4.
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 "Webmail" 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
https://www.bennetrichter.de/en/tutorials/mailcow-dockerized/#:~…=Enter%20your%20domain%20in%20the,change%20it%20if%20you%20want.
Page 4 of 5
Tutorial: How to Install and Configure Mailcow (Mail Server) - Bennet Richter
Incoming
IMAP
FQDN of the mail server (usually
12/21/23, 4:24 PM
993
SSL/TLS
mail.testdomain.com)
Outgoing
SMTP
FQDN of the mail server (usually
Normal
password
587
STARTTLS
mail.testdomain.com)
Normal
password
© Bennet Richter (2023) | Imprint | Privacy Policy
https://www.bennetrichter.de/en/tutorials/mailcow-dockerized/#:~…=Enter%20your%20domain%20in%20the,change%20it%20if%20you%20want.
Page 5 of 5
Download