Set secure email server with docker-mailserver

Sarit Ritwirune
3 min readAug 8, 2023

--

I run my own email server for fun. Let’s get started the journey. This time it took me 3 days to complete.

This article is not a walkthrough, but a note to pitfall of the new user.

DNS

The use case will be I alone use sarit@elcolie.com and fetch/send email to my elcolie.com server.

In the DNS pay attention to mail.elcolie.com it has prefix, but it will not shown up in the email address. I confused this in the early setup.

Now go into my host server

  1. create compose.yaml
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: mail.elcolie.com
env_file: mailserver.env
# More information about the mail-server ports:
# https://docker-mailserver.github.io/docker-mailserver/latest/config/security/understanding-the-ports/
# To avoid conflicts with yaml base-60 float, DO NOT remove the quotation marks.
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)
volumes:
- ./docker-data/certbot/certs/:/etc/letsencrypt
- ./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
restart: always
stop_grace_period: 1m
# Uncomment if using `ENABLE_FAIL2BAN=1`:
# cap_add:
# - NET_ADMIN
healthcheck:
test: "ss --listening --tcp | grep -P 'LISTEN.+:smtp' || exit 1"
timeout: 3s
retries: 0

2. create mail.server.env download from repository. And add letsencrypt to line `SSL_TYPE=letsencrypt`

3. You have to create certs and renew it every 30 days. Ref

4. Add user `docker exec -ti <CONTAINER NAME> setup email add user@example.com`

5. docker compose up --force-recreate -d

Thunderbird

  1. Add new email account. It will help you detect secure imap connection.
Good!

At this point I can fetch the email. Then check the security.

Connection is secured.

Next I need to configure smtp . Since the automatic configuration is not work. I can’t send email.

smtp: 587 + STARTTLS

That’s it. I have private email server with secure connection.

Thanks to Brennan Kinney for kindly debugged and answered me line by line.

♠️️️️️️♠️♠️♠️♠️♠️♠️♠️♠️♠️♠️♠️♠️♠️♠️♠️♠️♠️♠️♠️♠️♠️♠️♠️♠️♠️♠️♠️♠️♠️♠️♠️♠️♠️♠️♠️♠️♠️♠️♠️♠️♠️♠️♠️♠️♠️♠️♠️♠️♠️♠️♠️♠️♠️♠️

--

--

Sarit Ritwirune
Sarit Ritwirune

Written by Sarit Ritwirune

On the way to full stack cross-platform. Currently make living by data science.

No responses yet