Skip to main content

Simple Localhost Mail Server (Docker Compose)

Here is the compose file:

name: mailserver
services:
  greenmail:
    image: greenmail/standalone:latest
    # we can reference this container from other containers with your-host-name.com
    # we can also send emails to this host and it will work
    hostname: your-host-name.com
    environment:
      - JAVA_OPTS=-Dgreenmail.verbose
    ports:
      - "9025:3025" # SMTP
      - "9110:3110" # POP3
      - "9143:3143" # IMAP
      - "9465:3465" # SMTPS
      - "9993:3993" # IMAPS
      - "9995:3995" # POP3S
      - "9003:8080" # API

  roundcubemail:
    image: roundcube/roundcubemail:latest
    ports:
      - 9002:80
    environment:
      - ROUNDCUBEMAIL_DB_TYPE=sqlite
      - ROUNDCUBEMAIL_SKIN=elastic
      - ROUNDCUBEMAIL_DEFAULT_HOST=your-host-name.com
      - ROUNDCUBEMAIL_SMTP_SERVER=your-host-name.com
      - ROUNDCUBEMAIL_DEFAULT_PORT=3143 # containers in the same network don't see exposed ports, only the internal ports
      - ROUNDCUBEMAIL_SMTP_PORT=3025


And here is how to add users:

curl --request POST \
  --url http://localhost:9003/api/user \
  --header 'content-type: application/json' \
  --data '{
  "email": "user@your-host-name.com",
  "login": "user",
  "password": "password"
}'