You can support us by downloading this article as PDF from the Link below. Download the guide as PDF

Mailu is a simple but powerful mail server running on docker containers. It is a free software open to suggestions and contributions. It is meant to provide an easy email server set up. Mailu images should run on any cloud server running Docker (>= 1.11) and you can choose between Docker compose, Kubernetes and Rancher to run your Mailu mail server. This guide has been written to help users install and configure Mailu mail server on Ubuntu 20.04 server.

Features of Mailu Mail server

Just like any other mail server, mailu is expected to meet the requirements of sending and receiving emails. The following are some of the most important features of Mailu mail server:

  • Standard email server, IMAP and IMAP+, SMTP and Submission
  • Advanced email features, aliases, domain aliases, custom routing
  • Web access, multiple Webmails and administration interface
  • User features, aliases, auto-reply, auto-forward, fetched account
  • Admin features, global admins, announcements, per-domain delegation, quotas
  • Security, enforced TLS, Letsencrypt!, outgoing DKIM, anti-virus scanner
  • Antispam, auto-learn, greylisting, DMARC and SPF
  • Freedom, all FOSS components, no tracker included

Set up Mailu mail server on Ubuntu 20.04

Update your system packages before installations

sudo apt-get update
sudo apt-get upgrade

We need to ensure that our system has a valid IP address and a fully qualified domain name. There should also be valid mx record for our domain. To set server IP and hostname, run the below commands:

sudo hostnamectl set-hostname mail.example.com 

Also add a server’s FQDN and IP address to /etc/hosts file.

$ sudo vim /etc/hosts
62.15.116.167 mail.example.com

Once set, reboot your system

sudo reboot

The following ports should be allowed through your system firewall as they are critical for emails. You can open the ports with ufw as shown below:

sudo ufw allow proto tcp from any to any port 25,80,443,110,143,465,587,993,995

Install Docker and Docker compose on Ubuntu

To install docker and docker compose on Ubuntu 20.04, please check our guides on below.

Installing Docker on Ubuntu

Install Docker Compose on Ubuntu

Create Mailu Directory

After installing Docker and Docker Compose, proceed to create a directory where mailu will store its data.

sudo mkdir /mailu

Mailu uses a docker-compose.yml file and also relies on mailu.env for various settings. You need to generate a Mailu configuration for your environment using the online mailu set up utility. The generator will give you both a docker-compose.yml and a mailu.env file. Once the configuration is generated, you will receive links to use for downloading the files. Ensure that you download the files in the mailu directory. You should get a page like this when generating the files

For my installation case, I generated and got a file with the below content:

$ vim mailu.env

# Mailu main configuration file 
# 
# This file is autogenerated by the configuration management wizard for compose flavor. 
# For a detailed list of configuration variables, see the documentation at 
# https://mailu.io 

################################### 
# Common configuration variables 
################################### 

# Set to a randomly generated 16 bytes string 
SECRET_KEY=YPQAFO2THH5WSM7I 

# Subnet of the docker network. This should not conflict with any networks to which your system is connected. (Internal and external!) 
SUBNET=192.168.203.0/24 

# Main mail domain 
DOMAIN=example.com 

# Hostnames for this server, separated with comas 
HOSTNAMES=mailu.example.com

# Postmaster local part (will append the main mail domain) 
POSTMASTER=admin 

# Choose how secure connections will behave (value: letsencrypt, cert, notls, mail, mail-letsencrypt) 
TLS_FLAVOR=letsencrypt 

# Authentication rate limit (per source IP address) 
AUTH_RATELIMIT=10/minute;1000/hour  

# Opt-out of statistics, replace with "True" to opt out 
DISABLE_STATISTICS=False 

################################### 
# Optional features 
################################### 

# Expose the admin interface (value: true, false) 
ADMIN=true 

# Choose which webmail to run if any (values: roundcube, rainloop, none) 
WEBMAIL=roundcube 

# Dav server implementation (value: radicale, none) 
WEBDAV=radicale 

# Antivirus solution (value: clamav, none) 
ANTIVIRUS=clamav 

################################### 
# Mail settings 
################################### 

# Message size limit in bytes 
# Default: accept messages up to 50MB 
# Max attachment size will be 33% smaller 
MESSAGE_SIZE_LIMIT=50000000 

# Networks granted relay permissions 
# Use this with care, all hosts in this networks will be able to send mail without authentication! 
RELAYNETS= 

# Will relay all outgoing mails if configured 
RELAYHOST= 

# Fetchmail delay 
FETCHMAIL_DELAY=600 

# Recipient delimiter, character used to delimiter localpart from custom address part 
RECIPIENT_DELIMITER=+

And the docker-compose file is as below:

$ docker-compose.yml
# This file is auto-generated by the Mailu configuration wizard. 
# Please read the documentation before attempting any change. 
# Generated for compose flavor 

version: '2.2' 

services: 

 # External dependencies 
 redis: 
   image: redis:alpine 
   restart: always 
   volumes: 
     - "/mailu/redis:/data" 
    
 # Core services 
 front: 
   image: ${DOCKER_ORG:-mailu}/${DOCKER_PREFIX:-}nginx:${MAILU_VERSION:-1.7} 
   restart: always 
   env_file: mailu.env 
   logging: 
     driver: json-file 
   ports: 
     - "62.15.116.167:80:80" 
     - "::1:80:80" 
     - "62.15.116.167:443:443" 
     - "::1:443:443" 
     - "62.15.116.167:25:25" 
     - "::1:25:25" 
     - "62.15.116.167:465:465" 
     - "::1:465:465" 
     - "62.15.116.167:587:587" 
     - "::1:587:587" 
     - "62.15.116.167:110:110" 
     - "::1:110:110" 
     - "62.15.116.167:995:995" 
     - "::1:995:995" 
     - "62.15.116.167:143:143" 
     - "::1:143:143" 
     - "62.15.116.167:993:993" 
     - "::1:993:993" 
   volumes: 
     - "/mailu/certs:/certs" 
     - "/mailu/overrides/nginx:/overrides" 


 admin: 
   image: ${DOCKER_ORG:-mailu}/${DOCKER_PREFIX:-}admin:${MAILU_VERSION:-1.7} 
   restart: always 
   env_file: mailu.env 
   volumes: 
     - "/mailu/data:/data" 
     - "/mailu/dkim:/dkim" 
   depends_on: 
     - redis 

 imap: 
   image: ${DOCKER_ORG:-mailu}/${DOCKER_PREFIX:-}dovecot:${MAILU_VERSION:-1.7} 
   restart: always 
   env_file: mailu.env 
   volumes: 
     - "/mailu/mail:/mail" 
     - "/mailu/overrides:/overrides" 
   depends_on: 
     - front 

 smtp: 
   image: ${DOCKER_ORG:-mailu}/${DOCKER_PREFIX:-}postfix:${MAILU_VERSION:-1.7} 
   restart: always 
   env_file: mailu.env 
   volumes: 
     - "/mailu/overrides:/overrides" 
   depends_on: 
     - front 

 antispam: 
   image: ${DOCKER_ORG:-mailu}/${DOCKER_PREFIX:-}rspamd:${MAILU_VERSION:-1.7} 
   restart: always 
   env_file: mailu.env 
   volumes: 
     - "/mailu/filter:/var/lib/rspamd" 
     - "/mailu/dkim:/dkim" 
     - "/mailu/overrides/rspamd:/etc/rspamd/override.d" 
   depends_on: 
     - front 

 # Optional services 
 antivirus: 
   image: ${DOCKER_ORG:-mailu}/${DOCKER_PREFIX:-}clamav:${MAILU_VERSION:-1.7} 
   restart: always 
   env_file: mailu.env 
   volumes: 
     - "/mailu/filter:/data" 

 webdav: 
   image: ${DOCKER_ORG:-mailu}/${DOCKER_PREFIX:-}radicale:${MAILU_VERSION:-1.7} 
   restart: always 
   env_file: mailu.env 
   volumes: 
     - "/mailu/dav:/data" 

 fetchmail: 
   image: ${DOCKER_ORG:-mailu}/${DOCKER_PREFIX:-}fetchmail:${MAILU_VERSION:-1.7} 
   restart: always 
   env_file: mailu.env 

 # Webmail 
 webmail: 
   image: ${DOCKER_ORG:-mailu}/${DOCKER_PREFIX:-}roundcube:${MAILU_VERSION:-1.7} 
   restart: always 
   env_file: mailu.env 
   volumes: 
     - "/mailu/webmail:/data" 
   depends_on: 
     - imap 


networks: 
 default: 
   driver: bridge 
   ipam: 
     driver: default 
     config: 
       - subnet: 192.168.203.0/24

When done with the settings, run mailu with docker compose as below in mailu directory

$ sudo docker-compose up -d
Recreating mailu_webdav_1    ... done 
Recreating mailu_fetchmail_1 ... done 
Recreating mailu_front_1     ... done 
Recreating mailu_antivirus_1 ... done 
Recreating mailu_admin_1     ... done 
Recreating mailu_antispam_1  ... done 
Recreating mailu_imap_1      ... done 
Recreating mailu_smtp_1      ... done 
Recreating mailu_webmail_1   ... done

Set admin user by running the below command:

$ docker-compose -p mailu exec admin flask mailu admin admin example.com PASSWORD
created admin user
This creates a user called [email protected] with admin rights.

Configure Mailu Mail Server on Ubuntu 20.04

Once done, access Mailu web portal using your hostname: https://mailu.example.com. You should get a page to login with you administrator password. Once you login, you should see a page as below. Ensure to update your password to a stronger one by clicking on ‘update password‘.

Create domains Mailu

To add a domain, click on domain→ new domain

Create users Mailu

To create users, click on Mail domains. Under manage, click on mailbox icon which takes you to user list. Click on Add user

Mailu Webmail

For my installation,I chose to use roundcube for webmail. Access webmail to start sending emails. Click on webmail which then directs you to roundcube login page.

That’s it for setting up Mailu mail server on Ubuntu 20.04. I hope it is helpful to you. Check more interesting Linux guides for your daily installations:

You can support us by downloading this article as PDF from the Link below. Download the guide as PDF