# Mailu Email Server

> Simple but full-featured mail server with spam filtering, antivirus, and webmail.

- Category: Productivity & Collaboration
- Difficulty: advanced
- Components: mailu-admin, postfix, dovecot, rspamd, clamav, roundcube
- Tags: email, mailu, postfix, dovecot, webmail
- Source: https://docker.recipes/productivity/mailu-email-stack

## Overview

Mailu is a comprehensive email server solution that emerged as a modern, Docker-native alternative to traditional mail server configurations. Built on proven open-source components, Mailu wraps Postfix, Dovecot, Rspamd, ClamAV, and Roundcube into a cohesive system with centralized administration through its custom admin interface. Unlike complex manual mail server setups that require deep expertise in multiple technologies, Mailu provides a unified configuration layer that handles the intricate interactions between SMTP delivery, IMAP storage, spam filtering, and webmail access.

This stack combines Postfix as the SMTP server for mail routing and delivery, Dovecot for IMAP/POP3 mailbox access, Rspamd for intelligent spam and malware detection, ClamAV for virus scanning, and Roundcube for browser-based email access. The Mailu admin component acts as the orchestrator, managing user accounts, domains, aliases, and security policies across all services while maintaining consistent configuration through a Redis backend. Each component communicates through a dedicated network, with the Nginx frontend handling SSL termination and protocol routing.

This configuration suits organizations requiring full control over their email infrastructure, compliance-conscious businesses needing on-premises mail handling, and privacy-focused users wanting to escape third-party email providers. System administrators appreciate Mailu's balance of enterprise-grade features with simplified deployment, while security teams value the integrated anti-spam and antivirus protection that processes all mail through multiple filtering layers before delivery.

## Features

- Integrated DKIM key generation and management for email authentication and deliverability
- Rspamd machine learning spam detection with customizable scoring rules and blacklists
- ClamAV real-time virus scanning of all incoming and outgoing email attachments
- Roundcube webmail interface with calendar, contacts, and mobile-responsive design
- Postfix SMTP server with support for encryption, relay controls, and delivery receipts
- Dovecot IMAP/POP3 server with full-text search and mailbox sharing capabilities
- Multi-domain hosting with per-domain administrators and custom security policies
- Rate limiting and connection throttling to prevent abuse and resource exhaustion

## Use cases

- Small to medium businesses replacing hosted email services with on-premises infrastructure
- Educational institutions requiring student and faculty email with administrative oversight
- Healthcare organizations needing HIPAA-compliant email with audit trails and encryption
- Privacy-conscious individuals wanting complete control over personal email data
- Development teams needing reliable email delivery for application notifications and alerts
- Remote organizations requiring webmail access with offline synchronization capabilities
- Compliance-heavy industries needing email archiving and retention policy enforcement

## Prerequisites

- Minimum 4GB RAM and 20GB storage for base installation plus mail volume growth
- Public static IP address with reverse DNS configured for proper mail delivery
- Domain ownership with ability to configure MX, SPF, DKIM, and DMARC DNS records
- SSL certificate for the mail domain (Let's Encrypt integration available)
- Firewall configuration allowing ports 25, 80, 143, 443, 465, 587, and 993
- Understanding of email authentication protocols and anti-spam best practices

## docker-compose.yml

```yaml
services:
  redis:
    image: redis:alpine
    volumes:
      - redis:/data
    networks:
      - mailu-net
    restart: unless-stopped

  front:
    image: ghcr.io/mailu/nginx:latest
    ports:
      - "80:80"
      - "443:443"
      - "25:25"
      - "465:465"
      - "587:587"
      - "143:143"
      - "993:993"
    volumes:
      - certs:/certs
      - overrides:/overrides:ro
    environment:
      LOG_LEVEL: INFO
      TZ: ${TZ}
    networks:
      - mailu-net
    restart: unless-stopped

  admin:
    image: ghcr.io/mailu/admin:latest
    volumes:
      - data:/data
      - dkim:/dkim
    environment:
      SECRET_KEY: ${SECRET_KEY}
      DOMAIN: ${DOMAIN}
      HOSTNAMES: ${HOSTNAMES}
      POSTMASTER: ${POSTMASTER}
    depends_on:
      - redis
    networks:
      - mailu-net
    restart: unless-stopped

  imap:
    image: ghcr.io/mailu/dovecot:latest
    volumes:
      - mail:/mail
      - overrides:/overrides:ro
    depends_on:
      - front
    networks:
      - mailu-net
    restart: unless-stopped

  smtp:
    image: ghcr.io/mailu/postfix:latest
    volumes:
      - mailqueue:/queue
      - overrides:/overrides:ro
    depends_on:
      - front
    networks:
      - mailu-net
    restart: unless-stopped

  antispam:
    image: ghcr.io/mailu/rspamd:latest
    volumes:
      - filter:/var/lib/rspamd
      - overrides:/overrides:ro
    depends_on:
      - front
    networks:
      - mailu-net
    restart: unless-stopped

  antivirus:
    image: ghcr.io/mailu/clamav:latest
    volumes:
      - filter:/data
    networks:
      - mailu-net
    restart: unless-stopped

  webmail:
    image: ghcr.io/mailu/roundcube:latest
    volumes:
      - webmail:/data
      - overrides:/overrides:ro
    depends_on:
      - imap
    networks:
      - mailu-net
    restart: unless-stopped

volumes:
  redis:
  data:
  dkim:
  mail:
  mailqueue:
  filter:
  certs:
  overrides:
  webmail:

networks:
  mailu-net:
    driver: bridge
```

## .env

```bash
# Domain Configuration
DOMAIN=example.com
HOSTNAMES=mail.example.com
POSTMASTER=admin

# Secret Key (generate with: openssl rand -hex 32)
SECRET_KEY=your_random_secret_key_here

# Timezone
TZ=UTC
```

## Usage notes

- Admin panel at https://mail.example.com/admin
- Webmail at https://mail.example.com/webmail
- Configure DNS records for SPF, DKIM, DMARC
- First admin created via: docker compose exec admin flask mailu admin

## Troubleshooting

- Admin interface shows 'Internal Server Error': Check SECRET_KEY environment variable is set and Redis container is running
- Emails marked as spam by recipients: Verify SPF, DKIM, and DMARC DNS records are properly configured and propagated
- Cannot send emails to Gmail/Outlook: Ensure reverse DNS is configured and IP address is not on blacklists
- Roundcube login fails with correct credentials: Restart dovecot container and check mail volume permissions
- ClamAV consuming excessive memory: Increase container memory limits or disable real-time scanning for large attachments
- Postfix queue backing up: Check disk space in mailqueue volume and verify recipient domain connectivity

