Skip to content

Instantly share code, notes, and snippets.

@ceelsoin
Created May 15, 2023 19:49
Show Gist options
  • Save ceelsoin/07827c41a0018dc22e3fab65690d3dfa to your computer and use it in GitHub Desktop.
Save ceelsoin/07827c41a0018dc22e3fab65690d3dfa to your computer and use it in GitHub Desktop.
Docker MailServer + Round Cube (easy install)

Setup Docker MailServer + Round Cube (easy install)

1. Create docker-compose.yml (content below) and up

$ docker-compose up -d

2. Download setup script

$ wget https://raw.githubusercontent.com/docker-mailserver/docker-mailserver/master/setup.sh
$ chmod a+x ./setup.sh

3. Create config files:

Run this command to fix: "Recipient address rejected: User unknown in local recipient table"

$ echo "mydestination = localhost.$mydomain, localhost" >> ./docker-data/dms/config/postfix-main.cf

and create domains in /etc/hosts like:

domainxyz.com 127.0.0.1
domainxtp.com 127.0.0.1

4: Setup dns rightly (to score in mail-tester.com)

  • MX mail [SERVER IP]

  • MX @ [SERVER IP]

  • MX smtp [SERVER IP]

  • A @ [SERVER IP] (if not exists)

  • A webmail [SERVER IP]

  • TXT @ v=spf1 a mx ip4:[SERVER IP] ~all

  • TXT _dmarc v=DMARC1; p=none

5: Add roundcube to reverse proxy (nginx)

server {
    listen      80;
    server_name webmail.YOURSITE.COM;
    
    location / {
      proxy_set_header Host $host;
      proxy_set_header X-Real-IP $remote_addr;
      proxy_pass http://localhost:9002;
  }
}

6. HTTPS SSL (opticional)

$ certbot --nginx

7. Add email accounts (work with multiple domains in same server)

$ ./setup.sh email add contato@[yourdomain] [your_strong_password]
$ ./setup.sh email add contato@[youranotherdomain] [your_strong_password]

NOTE:

  • Dont forget to allow all ports from docker composer file on ufw or another firewall if is enabled
  • If you work with multiple domains, you need to repeat steps for dns and hosts configuration for your domains
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: [yourhostname] #can be your main hostname
ports:
- "25:25" # SMTP (explicit TLS => STARTTLS)
- "143:143" # IMAP4 (explicit TLS => STARTTLS)
- "465:465" # ESMTP (implicit TLS)
- "587:587" # ESMTP (explicit TLS => STARTTLS)
- "993:993" # IMAP4 (implicit TLS)
- "110:110" # POP3
- "995:995" # POP3 (with TLS)
volumes:
- ./docker-data/dms/mail-data/:/var/mail/
- ./docker-data/dms/mail-state/:/var/mail-state/
- ./docker-data/dms/mail-logs/:/var/log/mail/
- ./docker-data/dms/config/:/tmp/docker-mailserver/
- /etc/localtime:/etc/localtime:ro
environment:
- ENABLE_RSPAMD=1
- ENABLE_CLAMAV=1
- ENABLE_FAIL2BAN=1
cap_add:
- NET_ADMIN # For Fail2Ban to work
restart: always
roundcubemail:
image: roundcube/roundcubemail:latest
container_name: roundcubemail
# restart: unless-stopped
volumes:
- ./www:/var/www/html
- ./db/sqlite:/var/roundcube/db
ports:
- 9002:80
environment:
- ROUNDCUBEMAIL_DB_TYPE=sqlite
- ROUNDCUBEMAIL_SKIN=elastic
- ROUNDCUBEMAIL_DEFAULT_HOST=tls://mailserver
- ROUNDCUBEMAIL_SMTP_SERVER=tls://mailserver
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment