Skip to main content

Mail Server

Initial setup

 

1 - Updates
sudo apt update && sudo apt upgrade -y

 

2 - Install docker and docker compose
# Install required packages
sudo apt install -y apt-transport-https ca-certificates curl gnupg lsb-release

# Add Docker's official GPG key
curl -fsSL https://download.docker.com/linux/debian/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

# Set up the stable repository
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/debian $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

# Install Docker
sudo apt update
sudo apt install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin

# Add your user to docker group
sudo usermod -aG docker $USER

 

3 - Create DNS Records
  • A record: mail.yourdomain.com → your server IP
  • MX record: @mail.yourdomain.com (priority 10)
  • TXT record (SPF): v=spf1 mx ~all

 

4 - Install and configure mailserver
# Create directory for mail server
mkdir -p ~/mailserver
cd ~/mailserver

# Download docker-compose.yml and .env template
wget https://raw.githubusercontent.com/docker-mailserver/docker-mailserver/master/compose.yaml
wget https://raw.githubusercontent.com/docker-mailserver/docker-mailserver/master/mailserver.env

# Rename for easier use
mv compose.yaml docker-compose.yml
mv mailserver.env .env

 

5 - Edit .env variables
  • HOSTNAME=mail
  • DOMAINNAME=yourdomain.com
  • OVERRIDE_HOSTNAME=mail.yourdomain.com
  • ENABLE_SPAMASSASSIN=1
  • ENABLE_CLAMAV=1
  • ENABLE_FAIL2BAN=1
  • SSL_TYPE=letsencrypt (or manual if you have your own certs)
  • ACCOUNT_PROVISIONER=FILE

 

6 - Edit docker-compose.yml
services:
  mailserver:
    image: ghcr.io/docker-mailserver/docker-mailserver:latest
    container_name: mailserver
    # Provide the FQDN of your mail server here (Your DNS MX record should point to this value)
    hostname: mx.home.conorbriggs.com.au
    env_file: .env
    # More information about the mail-server ports:
    # https://docker-mailserver.github.io/docker-mailserver/latest/config/security/understanding-the-ports/
    ports:
      - "25:25"    # SMTP  (explicit TLS => STARTTLS, Authentication is DISABLED => use port 465/587 instead)
      - "143:143"  # IMAP4 (explicit TLS => STARTTLS)
      - "465:465"  # ESMTP (implicit TLS)
      - "587:587"  # ESMTP (explicit TLS => STARTTLS)
      - "993:993"  # IMAP4 (implicit TLS)
    volumes:
      - ./mail-data/:/var/mail/
      - ./mail-state/:/var/mail-state/
      - ./mail-logs/:/var/log/mail/
      - ./config/:/tmp/docker-mailserver/
      - /etc/localtime:/etc/localtime:ro
      - /etc/letsencrypt:/etc/letsencrypt:ro
    restart: always
    stop_grace_period: 1m
    # Uncomment if using `ENABLE_FAIL2BAN=1`:
    cap_add:
      - NET_ADMIN
    healthcheck:
      test: "ss --listening --ipv4 --tcp | grep --silent ':smtp' || exit 1"
      timeout: 3s
      retries: 0
    networks:
      - mailserver-network
networks:
  mailserver-network:
    driver: bridge

 

 


Connecting

IMAP (Incoming):

  • Server: mx.home.conorbriggs.com.au
  • Port: 993 (IMAPS with SSL/TLS)
  • Security: SSL/TLS
  • Authentication: Normal password

SMTP (Outgoing):

  • Server: mx.home.conorbriggs.com.au
  • Port: 587 (with STARTTLS) or 465 (with SSL/TLS)
  • Security: STARTTLS (port 587) or SSL/TLS (port 465)
  • Authentication: Normal password

 

## Container Management

### Basic Container Operations
```bash
# Start the mailserver
docker compose up -d

# Stop the mailserver
docker compose down

# Restart the mailserver
docker compose restart

# View logs (live)
docker compose logs -f

# View logs (last 100 lines)
docker compose logs --tail=100

# Check container status
docker ps -a

# Check container health
docker inspect mailserver | grep -A 10 Health