How to install Mailu mail server on Ubuntu 20.04

You can download this article in PDF format via the link below to support us.Download the guide in PDF formatClose

Mailu is a simple but powerful mail server running on a docker container. This is a free software, you are welcome to make suggestions and contributions. It aims to provide a simple email server setup. The Mailu image should run on any cloud server running Docker (>= 1.11), and you can choose between Docker compose, Kubernetes and Rancher to run the Mailu mail server. This guide aims to help users install and configure Mailu mail server on Ubuntu 20.04 server.

Features of Mailu Mail server

Like any other mail server, mailu is expected to meet the requirements for sending and receiving emails. Here are some of the most important features of Mailu mail server:

  • Standard email server, IMAP and IMAP+, SMTP and submission
  • Advanced email functions, aliases, domain aliases, custom routing
  • Web access, multiple Webmail and management interfaces
  • User function, alias, auto reply, auto forward, acquired account
  • Administrator functions, global administrators, announcements, delegation by domain, quotas
  • Security, enforced TLS, Letsencrypt!, outgoing DKIM, antivirus scanner
  • Anti-spam, automatic learning, greylisting, DMARC and SPF
  • Free, all FOSS components, excluding tracker

Set up Mailu mail server on Ubuntu 20.04

Update system packages before installation

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. Our domain should also have valid MX records. To set the server IP and hostname, run the following command:

sudo hostnamectl set-hostname mail.example.com 

Also add the FQDN and IP address of the server to the /etc/hosts file.

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

After setting, restart the system

sudo reboot

The following ports should be allowed through the system firewall because they are essential for email. You can use ufw to open the port as follows:

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 the guide below.

Install Docker on Ubuntu

Install Docker Compose on Ubuntu

Create Mailu directory

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

sudo mkdir /mailu

Mailu use docker-compose.yml File, also depends on mailu.env Used for various settings. You need to use the online mailu setup utility to generate the Mailu configuration for your environment. The generator will provide you with docker-compose.yml and mailu.env files. After generating the configuration, you will receive a link to download the file. Make sure you download the file to the mailu directory.When generating the file, you should get a page like this

For my installation case, I generated a file with the following 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=+

The docker-compose file is as follows:

$ 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

After completing the settings, use docker compose in the mailu directory to run mailu as follows

$ 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 up the administrator user by running the following 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

When finished, use your hostname to access the Mailu web portal: https://mailu.example.com. You will get a page to log in with the administrator password. After logging in, you will see the following page. By clicking “Make sure to update your password to a more secure password”Update password‘.

How to install Mailu mail server on Ubuntu 20.04

Create domain Mailu

To add a domain, click Domain → New Domain

How to install Mailu mail server on Ubuntu 20.04

Create user Mailu

To create a user, click Mail domain.under management, Click Mailbox icon Takes you to the user list.Click on Add user

How to install Mailu mail server on Ubuntu 20.04

Mailu Webmail

For my installation, I chose to use roundcube for Webmail. Visit webmail to start sending emails.Click on Webmail Then direct you to Round cube log in page.

How to install Mailu mail server on Ubuntu 20.04

It is to set up Mailu mail server on Ubuntu 20.04. hope it helps you. Check out more interesting Linux guides for daily installation:

  • Install Zimbra Mail Server on CentOS | RHEL
  • How to install iRedMail server on CentOS
  • Secure the iRedMail server by encrypting the SSL certificate
  • Migrate from IncrediMail to Outlook
  • Install and configure postal mail server on Ubuntu

You can download this article in PDF format via the link below to support us.Download the guide in PDF formatClose

Sidebar