version: '3.8'

services:
  mailserver:
    image: ghcr.io/docker-mailserver/docker-mailserver:latest
    container_name: mailserver
    hostname: ${HOSTNAME}
    env_file: .env
    ports:
      - "25:25"
      - "143:143"
      - "465:465"
      - "587:587"
      - "993:993"
    volumes:
      - ./data/dms/mail-data:/var/mail
      - ./data/dms/mail-state:/var/mail-state
      - ./data/dms/mail-logs:/var/log/mail
      - ./data/dms/mail-config:/tmp/docker-mailserver
      - /etc/localtime:/etc/localtime:ro
    environment:
      - ENABLE_SPAMASSASSIN=0
      - ENABLE_CLAMAV=0
      - ENABLE_FAIL2BAN=0
      - ENABLE_POSTGREY=0
      - ONE_DIR=1
      - DMS_DEBUG=0
      - PERMIT_DOCKER=network
      - SSL_TYPE=
      - SPOOF_PROTECTION=0
      - ENABLE_SRS=0
    cap_add:
      - NET_ADMIN
    restart: unless-stopped
    stop_grace_period: 1m
    healthcheck:
      test: "ss --listening --tcp | grep -P 'LISTEN.+:smtp' || exit 1"
      timeout: 3s
      retries: 0

  roundcube:
    image: roundcube/roundcubemail:latest
    container_name: roundcube
    depends_on:
      - mailserver
    env_file: .env
    ports:
      - "8080:80"
    volumes:
      - ./data/roundcube/config:/var/roundcube/config
      - ./data/roundcube/db:/var/roundcube/db
    environment:
      - ROUNDCUBEMAIL_DB_TYPE=sqlite
      - ROUNDCUBEMAIL_SKIN=elastic
      - ROUNDCUBEMAIL_UPLOAD_MAX_FILESIZE=10M
      - ROUNDCUBEMAIL_DEFAULT_HOST=tls://mailserver
      - ROUNDCUBEMAIL_SMTP_SERVER=tls://mailserver
    restart: unless-stopped

networks:
  default:
    name: mail-network
