Complete Guide to Setting Up Mailu Mail Server on Linux

Mailu is a lightweight, secure, and easy-to-configure mail server based on Docker. It provides a full-featured mail solution with support for SMTP, IMAP, POP3, and webmail. This guide covers the complete setup of Mailu on a Linux server, including installation, configuration, and security.

Prerequisites

Ensure you have the following before starting:

  • A Linux server (Ubuntu 20.04/22.04 or CentOS 8 recommended)
  • Docker and Docker Compose installed
  • A registered domain (e.g., yourdomain.com)
  • Root or sudo access

Step 1: Prepare Your System

1. Update System Packages

Ensure your system is updated:

sudo apt update && sudo apt upgrade -y # For Ubuntu sudo yum update -y # For CentOS

2. Set the Hostname

sudo hostnamectl set-hostname mail.yourdomain.com

Add the hostname to /etc/hosts:

sudo nano /etc/hosts

Add this line:

127.0.0.1 mail.yourdomain.com mail localhost

Step 2: Install Docker and Docker Compose

1. Install Docker (Ubuntu):

sudo apt install docker.io -y

2. Install Docker Compose:

sudo apt install docker-compose -y

3. Enable Docker to Start on Boot:

sudo systemctl enable docker sudo systemctl start docker

Step 3: Download and Configure Mailu

1. Create Mailu Directory:

mkdir /mailu && cd /mailu

2. Generate Mailu Configuration Files:

Use the Mailu configuration tool: https://setup.mailu.io/1.9/

Download the generated docker-compose.yml and .env files to the /mailu directory.

Or manually create them:

wget https://setup.mailu.io/1.9/docker-compose.yml wget https://setup.mailu.io/1.9/mailu.env -O .env

Step 4: Customize the Mailu Configuration

  1. Edit the .env file:
sudo nano .env

Ensure the following variables are set correctly:

DOMAIN=yourdomain.com HOSTNAME=mail TLS_FLAVOR=letsencrypt ADMIN=admin@yourdomain.com PASSWORD=yourpassword
  1. Save and exit the file.

Step 5: Start Mailu Services

Navigate to the /mailu directory and start Mailu using Docker Compose:

cd /mailu sudo docker-compose up -d

Check if Mailu containers are running:

sudo docker ps

Step 6: Set Up DNS Records

Ensure the following DNS records are added to your domain registrar:

Record TypeNameValue
Amail.yourdomain.comYour server’s IP address
MXyourdomain.commail.yourdomain.com (Priority 10)
TXTyourdomain.comv=spf1 mx ~all
TXT_dmarc.yourdomain.comv=DMARC1; p=none
TXTdefault._domainkey.yourdomain.com(DKIM Key)

Step 7: Access Mailu Admin Interface

Open your browser and visit:

https://mail.yourdomain.com/admin

Login with:

Step 8: Add Email Users

  1. Go to “Users” in the Mailu admin panel.
  2. Create new email accounts.

Example command to create a user manually:

sudo docker-compose exec admin flask mailu admin admin@yourdomain.com yourpassword

Step 9: Secure Mailu with Fail2Ban

  1. Install Fail2Ban (Ubuntu):
sudo apt install fail2ban -y
  1. Enable Fail2Ban to start on boot:
sudo systemctl enable fail2ban sudo systemctl start fail2ban

Step 10: Monitor Mailu Services

  1. Check Docker Logs:
sudo docker-compose logs -f
  1. Restart Mailu Services:
sudo docker-compose restart

Step 11: Backup and Restore Mailu

  1. Create a Backup:
sudo docker-compose stop sudo tar -czvf mailu-backup.tar.gz /mailu sudo docker-compose start
  1. Restore from Backup:
sudo docker-compose stop sudo tar -xzvf mailu-backup.tar.gz -C / sudo docker-compose start

Recommended Services for Mailu

  • ClamAV – Virus protection
  • SpamAssassin – Spam filtering
  • Fail2Ban – Protection against brute-force attacks
  • Postgrey – Greylisting for improved spam control

Final Thoughts

You have successfully set up and secured a Mailu mail server on your Linux system. Regular maintenance and monitoring will ensure optimal performance and security.

Keywords: Mailu mail server setup, configure Mailu Docker, install Mailu on Ubuntu, secure Mailu email server, Docker mail server tutorial

Related Searches:

  • How to install Mailu mail server
  • Mailu email server Docker setup
  • Mailu vs Postfix vs Exim
  • Securing Mailu with SSL
  • Adding users to Mailu mail server

Tags:

  • Mailu Mail Server
  • Docker Mail Server
  • Email Server Setup
  • Secure Mail Server
  • Mailu Installation Guide

Leave a Comment