2021-01-16 09:16:05 +00:00
# Docker Mailserver
2016-06-25 08:57:46 +00:00
2021-01-16 09:16:05 +00:00
[![ci::status]][ci::github] [![docker::pulls]][docker::hub]
2020-12-22 10:08:50 +00:00
2021-01-16 09:16:05 +00:00
[ci::status]: https://img.shields.io/github/workflow/status/docker-mailserver/docker-mailserver/Build%2C%20Test%20%26%20Deploy?color=blue& label=CI& logo=github& logoColor=white& style=for-the-badge
[ci::github]: https://github.com/docker-mailserver/docker-mailserver/actions
[docker::pulls]: https://img.shields.io/docker/pulls/mailserver/docker-mailserver.svg?style=for-the-badge& logo=docker& logoColor=white
[docker::hub]: https://hub.docker.com/r/mailserver/docker-mailserver/
2020-12-19 12:17:48 +00:00
2021-01-16 09:16:05 +00:00
A fullstack but simple mail server (SMTP, IMAP, LDAP, Antispam, Antivirus, etc.). Only configuration files, no SQL database. Keep it simple and versioned. Easy to deploy and upgrade.
2015-03-28 15:44:40 +00:00
2020-11-05 11:43:03 +00:00
[Why this image was created. ](http://tvi.al/simple-mail-server-with-docker/ )
2020-09-09 15:19:48 +00:00
2021-01-16 09:16:05 +00:00
1. [Included Services ](#included-services )
2021-02-01 17:54:01 +00:00
2. [Issues and Contributing ](./CONTRIBUTING.md )
2021-01-16 09:16:05 +00:00
3. [Requirements ](#requirements )
4. [Usage ](#usage )
5. [Examples ](#examples )
6. [Environment Variables ](./ENVIRONMENT.md )
7. [Release Notes ](./CHANGELOG.md )
2020-03-16 17:38:28 +00:00
2021-01-16 09:16:05 +00:00
## Included Services
2015-03-29 12:07:56 +00:00
2020-09-24 12:54:21 +00:00
- [Postfix ](http://www.postfix.org ) with SMTP or LDAP auth
2021-01-19 08:27:01 +00:00
- [Dovecot ](https://www.dovecot.org ) for SASL, IMAP (or POP3), with LDAP Auth, Sieve and [quotas ](https://github.com/docker-mailserver/docker-mailserver/wiki/Configure-Accounts#mailbox-quota )
2019-08-31 07:15:42 +00:00
- [Amavis ](https://www.amavis.org/ )
- [Spamassasin ](http://spamassassin.apache.org/ ) supporting custom rules
- [ClamAV ](https://www.clamav.net/ ) with automatic updates
- [OpenDKIM ](http://www.opendkim.org )
- [OpenDMARC ](https://github.com/trusteddomainproject/OpenDMARC )
- [Fail2ban ](https://www.fail2ban.org/wiki/index.php/Main_Page )
- [Fetchmail ](http://www.fetchmail.info/fetchmail-man.html )
- [Postscreen ](http://www.postfix.org/POSTSCREEN_README.html )
- [Postgrey ](https://postgrey.schweikert.ch/ )
2016-01-26 11:56:26 +00:00
- [LetsEncrypt ](https://letsencrypt.org/ ) and self-signed certificates
2021-02-06 17:01:56 +00:00
- [Setup script ](https://github.com/docker-mailserver/docker-mailserver/wiki/setup.sh ) to easily configure and maintain your mailserver
2021-01-19 08:27:01 +00:00
- Basic [Sieve support ](https://github.com/docker-mailserver/docker-mailserver/wiki/Configure-Sieve-filters ) using dovecot
2020-10-06 12:45:55 +00:00
- SASLauthd with LDAP auth
2021-01-16 09:16:05 +00:00
- Persistent data and state
- [CI/CD ](https://github.com/docker-mailserver/docker-mailserver/actions )
- [Extension Delimiters ](http://www.postfix.org/postconf.5.html#recipient_delimiter ) (`you+extension@example.com` go to `you@example.com` )
2015-08-26 08:05:40 +00:00
2018-01-09 07:31:15 +00:00
## Requirements
2021-01-16 09:16:05 +00:00
**Recommended**:
2020-09-04 06:42:12 +00:00
2020-09-26 13:11:52 +00:00
- 1 Core
2019-10-28 12:55:18 +00:00
- 1-2GB RAM
- Swap enabled for the container
2018-01-09 07:31:15 +00:00
2021-01-16 09:16:05 +00:00
**Minimum**:
2020-09-04 06:42:12 +00:00
2020-09-26 13:11:52 +00:00
- 1 vCore
2018-01-09 07:31:15 +00:00
- 512MB RAM
2021-01-19 08:27:01 +00:00
**Note:** You'll need to deactivate some services like ClamAV to be able to run on a host with 512MB of RAM. Even with 1G RAM you may run into problems without swap, see [FAQ ](https://github.com/docker-mailserver/docker-mailserver/wiki/FAQ-and-Tips ).
2018-01-09 07:31:15 +00:00
2016-04-24 15:37:10 +00:00
## Usage
2015-03-31 15:28:13 +00:00
2021-01-24 22:18:37 +00:00
### Available image sources / tags
The [CI/CD workflows ](https://github.com/docker-mailserver/docker-mailserver/actions ) automatically build, test and push new images to container registries. Currently, the following registries are supported:
- [DockerHub ](https://hub.docker.com/repository/docker/mailserver/docker-mailserver )
- [GitHub Container Registry ](https://github.com/orgs/docker-mailserver/packages?repo_name=docker-mailserver )
All workflows are using the **tagging convention** listed below. It is subsequently applied to all images pushed to supported container registries:
| Event | Ref | Commit SHA | Image Tags |
|--------------|-----------------------|------------|-------------------------------|
| `push` | `refs/heads/master` | `cf20257` | `edge` |
| `push` | `refs/heads/stable` | `cf20257` | `stable` |
| `push tag` | `refs/tags/1.2.3` | `ad132f5` | `1.2.3` , `1.2` , `1` , `latest` |
| `push tag` | `refs/tags/v1.2.3` | `ad132f5` | `1.2.3` , `1.2` , `1` , `latest` |
2020-09-04 06:42:12 +00:00
### Get the tools
2016-04-20 08:15:51 +00:00
2020-10-21 15:02:39 +00:00
Download the `docker-compose.yml` , `compose.env` , `mailserver.env` and the `setup.sh` files:
2018-03-07 18:33:43 +00:00
2020-09-05 14:19:12 +00:00
``` BASH
2021-01-16 14:34:31 +00:00
wget https://raw.githubusercontent.com/docker-mailserver/docker-mailserver/master/setup.sh
wget https://raw.githubusercontent.com/docker-mailserver/docker-mailserver/master/docker-compose.yml
wget https://raw.githubusercontent.com/docker-mailserver/docker-mailserver/master/mailserver.env
wget -O .env https://raw.githubusercontent.com/docker-mailserver/docker-mailserver/master/compose.env
2020-10-18 12:54:23 +00:00
chmod a+x ./setup.sh
2020-09-04 06:42:12 +00:00
```
2016-02-01 14:05:29 +00:00
2020-09-04 06:42:12 +00:00
### Create a docker-compose environment
2018-02-07 18:37:26 +00:00
2020-10-06 12:45:55 +00:00
- [Install the latest docker-compose ](https://docs.docker.com/compose/install/ )
2020-10-21 15:02:39 +00:00
- Edit the files `.env` and `mailserver.env` to your liking:
2021-01-16 09:16:05 +00:00
- `.env` contains the configuration for Docker Compose
2020-10-21 15:02:39 +00:00
- `mailserver.env` contains the configuration for the mailserver container
2021-01-16 09:16:05 +00:00
- these files supports [only simple `VAR=VAL` ](https://docs.docker.com/compose/env-file/ )
- don't quote your values
- variable substitution is *not* supported (e.g. `OVERRIDE_HOSTNAME=$HOSTNAME.$DOMAINNAME` ).
- Variables in `.env` are expanded in the `docker-compose.yml` file **only** and **not** in the container. The file `mailserver.env` serves this case where environment variables are used in the container.
2021-01-19 08:27:01 +00:00
- If you want to use a bare domain (host name = domain name), see [FAQ ](https://github.com/docker-mailserver/docker-mailserver/wiki/FAQ-and-Tips#can-i-use-nakedbare-domains-no-host-name )
2020-01-18 10:42:23 +00:00
2020-09-24 12:54:21 +00:00
### Get up and running
2020-11-06 13:04:23 +00:00
2020-12-22 10:08:50 +00:00
If you'd like to use SELinux, add `-Z` to the variable `SELINUX_LABEL` in `.env` . If you want the volume bind mount to be shared among other containers switch `-Z` to `-z`
2020-11-06 13:04:23 +00:00
2020-09-04 06:42:12 +00:00
``` BASH
docker-compose up -d mail
2020-11-06 13:04:23 +00:00
2021-01-16 09:16:05 +00:00
# without SELinux
2020-09-04 06:42:12 +00:00
./setup.sh email add < user @ domain > [< password > ]
2020-12-09 20:02:27 +00:00
./setup.sh alias add postmaster@< domain > < user @ domain >
2020-09-04 06:42:12 +00:00
./setup.sh config dkim
2018-02-07 18:37:26 +00:00
2020-12-19 12:17:48 +00:00
# with SELinux
2020-10-30 15:51:27 +00:00
./setup.sh -Z email add < user @ domain > [< password > ]
2020-12-09 20:02:27 +00:00
./setup.sh -Z alias add postmaster@< domain > < user @ domain >
2020-10-30 15:51:27 +00:00
./setup.sh -Z config dkim
```
2021-01-27 13:09:24 +00:00
If you are using a LDAP setup the setup looks a bit different as you do not add user accounts directly. Therefore `postfix` doesn't know your domain(s) and you need to provide it when configuring `dkim` :
``` BASH
docker-compose up -d mail
./setup.sh config dkim < key-size > < domain.tld > [,< domain2.tld > ]
```
2020-12-19 12:17:48 +00:00
### Miscellaneous
#### DNS - DKIM
2020-11-06 13:04:23 +00:00
2021-01-16 09:16:05 +00:00
When keys are generated, you can configure your DNS server by just pasting the content of `config/opendkim/keys/domain.tld/mail.txt` to [set up DKIM ](https://mxtoolbox.com/dmarc/dkim/setup/how-to-setup-dkim ).
2018-02-07 18:37:26 +00:00
2020-12-19 12:17:48 +00:00
#### Custom user changes & patches
If you'd like to change, patch or alter files or behavior of `docker-mailserver` , you can use a script. Just place it the `config/` folder that is created on startup and call it `user-patches.sh` . The setup is done like this:
``` BASH
# 1. Either create the config/ directory yourself
# or let docker-mailserver create it on initial
# startup
2021-01-16 09:16:05 +00:00
/where/docker-mailserver/resides/ $ mkdir config & & cd config
2020-12-19 12:17:48 +00:00
# 2. Create the user-patches.sh script and make it
# executable
2021-01-16 09:16:05 +00:00
/where/docker-mailserver/resides/config/ $ touch user-patches.sh
/where/docker-mailserver/resides/config/ $ chmod +x user-patches.sh
2020-12-19 12:17:48 +00:00
# 3. Edit it
2021-01-16 09:16:05 +00:00
/where/docker-mailserver/resides/config/ $ vi user-patches.sh
/where/docker-mailserver/resides/config/ $ cat user-patches.sh
2020-12-19 12:17:48 +00:00
#! /bin/bash
# ! THIS IS AN EXAMPLE !
# If you modify any supervisord configuration, make sure
2021-02-01 17:39:05 +00:00
# to run `supervisorctl update` and/or `supervisorctl reload` afterwards.
2020-12-19 12:17:48 +00:00
2021-02-01 17:39:05 +00:00
# shellcheck source=/dev/null
. /usr/local/bin/helper-functions.sh
_notify 'Applying user-patches'
2020-12-19 12:17:48 +00:00
if ! grep '192.168.0.1' /etc/hosts
then
echo -e '192.168.0.1 some.domain.com' >> /etc/hosts
fi
```
2021-01-16 09:16:05 +00:00
And you're done. The user patches script runs right before starting daemons. That means, all the other configuration is in place, so the script can make final adjustments.
2020-09-04 06:42:12 +00:00
2020-11-25 12:31:21 +00:00
#### Supported Operating Systems
We are currently providing support for Linux. Windows is _not_ supported and is known to cause problems. Similarly, macOS is _not officially_ supported - but you may get it to work there. In the end, Linux should be your preferred operating system for this image, especially when using this mailserver in production.
#### Support for Multiple Domains
`docker-mailserver` supports multiple domains out of the box, so you can do this:
``` BASH
./setup.sh email add user1@docker.example.com
./setup.sh email add user1@mail.example.de
./setup.sh email add user1@server.example.org
```
#### Updating `docker-mailserver`
2018-02-07 18:37:26 +00:00
2020-09-04 06:42:12 +00:00
``` BASH
docker-compose down
2021-01-16 09:16:05 +00:00
docker pull docker.io/mailserver/docker-mailserver:< VERSION TAG >
2021-01-31 16:50:02 +00:00
docker-compose up -d mailserver
2020-09-04 06:42:12 +00:00
```
2018-02-07 18:37:26 +00:00
2020-10-06 12:45:55 +00:00
You're done! And don't forget to have a look at the remaining functions of the `setup.sh` script with `./setup.sh -h` .
2018-02-07 18:37:26 +00:00
2018-03-18 19:15:06 +00:00
#### SPF/Forwarding Problems
If you got any problems with SPF and/or forwarding mails, give [SRS ](https://github.com/roehling/postsrsd/blob/master/README.md ) a try. You enable SRS by setting `ENABLE_SRS=1` . See the variable description for further information.
2018-02-18 12:12:39 +00:00
#### Exposed ports
2020-04-27 06:23:32 +00:00
2020-09-04 06:42:12 +00:00
| Protocol | Opt-in Encryption ¹ | Enforced Encryption | Purpose |
| :------: | :----------------------: | :-----------------: | :------------: |
| SMTP | 25 | N/A | Transfer² |
| ESMTP | 587 | 465³ | Submission |
| POP3 | 110 | 995 | Retrieval |
| IMAP4 | 143 | 993 | Retrieval |
2020-04-27 06:23:32 +00:00
1. A connection *may* be secured over TLS when both ends support `STARTTLS` . On ports 110, 143 and 587, `docker-mailserver` will reject a connection that cannot be secured. Port 25 is [required ](https://serverfault.com/questions/623692/is-it-still-wrong-to-require-starttls-on-incoming-smtp-messages ) to support insecure connections.
2. Receives email and filters for spam and viruses. For submitting outgoing mail you should prefer the submission ports(465, 587), which require authentication. Unless a relay host is configured, outgoing email will leave the server via port 25(thus outbound traffic must not be blocked by your provider or firewall).
3. A submission port since 2018, [RFC 8314 ](https://tools.ietf.org/html/rfc8314 ). Originally a secure variant of port 25.
2021-01-19 08:27:01 +00:00
See the [wiki ](https://github.com/docker-mailserver/docker-mailserver/wiki ) for further details and best practice advice, especially regarding security concerns.
2018-02-18 12:12:39 +00:00
2020-09-09 15:19:48 +00:00
## Examples
2020-09-04 06:42:12 +00:00
2020-09-09 15:19:48 +00:00
### With Relevant Environmental Variables
2018-02-07 18:37:26 +00:00
2021-01-16 09:16:05 +00:00
This example provides you only with a basic example of what a minimal setup could look like. We **strongly recommend** that you go through the configuration file yourself and adjust everything to your needs. The default [docker-compose.yml ](./docker-compose.yml ) can be used for the purpose out-of-the-box, see the [usage section ](#usage ).
2020-11-25 12:31:21 +00:00
2020-09-09 15:19:48 +00:00
``` YAML
version: '3.8'
2016-09-07 17:39:27 +00:00
services:
2021-02-01 17:39:05 +00:00
mailserver:
2021-01-16 09:16:05 +00:00
image: docker.io/mailserver/docker-mailserver:latest
2020-09-26 13:11:52 +00:00
hostname: mail # ${HOSTNAME}
domainname: domain.com # ${DOMAINNAME}
container_name: mail # ${CONTAINER_NAME}
2016-09-07 17:39:27 +00:00
ports:
2019-05-05 18:22:51 +00:00
- "25:25"
- "143:143"
- "587:587"
- "993:993"
2016-04-24 15:37:10 +00:00
volumes:
2019-05-05 18:22:51 +00:00
- maildata:/var/mail
- mailstate:/var/mail-state
2019-09-15 13:40:05 +00:00
- maillogs:/var/log/mail
2019-05-05 18:22:51 +00:00
- ./config/:/tmp/docker-mailserver/
2016-12-25 21:54:37 +00:00
environment:
2019-05-05 18:22:51 +00:00
- ENABLE_SPAMASSASSIN=1
2020-05-02 17:10:36 +00:00
- SPAMASSASSIN_SPAM_TO_INBOX=1
2019-05-05 18:22:51 +00:00
- ENABLE_CLAMAV=1
- ENABLE_FAIL2BAN=1
- ENABLE_POSTGREY=1
2020-12-22 10:08:50 +00:00
- ENABLE_SASLAUTHD=0
2019-05-05 18:22:51 +00:00
- ONE_DIR=1
- DMS_DEBUG=0
2016-12-25 21:54:37 +00:00
cap_add:
2019-05-05 18:22:51 +00:00
- NET_ADMIN
- SYS_PTRACE
2020-09-21 11:54:31 +00:00
restart: always
2016-09-07 17:39:27 +00:00
volumes:
maildata:
2016-12-25 21:54:37 +00:00
mailstate:
2019-09-15 13:40:05 +00:00
maillogs:
2016-09-07 17:39:27 +00:00
```
2016-02-01 14:05:29 +00:00
2020-09-04 06:42:12 +00:00
#### LDAP setup
2017-07-03 11:16:16 +00:00
2020-09-04 06:42:12 +00:00
``` YAML
2020-09-09 15:19:48 +00:00
version: '3.8'
2017-07-03 11:16:16 +00:00
services:
2021-02-01 17:39:05 +00:00
mailserver:
2021-01-16 09:16:05 +00:00
image: docker.io/mailserver/docker-mailserver:latest
2020-09-26 13:11:52 +00:00
hostname: mail # ${HOSTNAME}
domainname: domain.com # ${DOMAINNAME}
container_name: mail # ${CONTAINER_NAME}
2017-07-03 11:16:16 +00:00
ports:
- "25:25"
- "143:143"
- "587:587"
- "993:993"
volumes:
- maildata:/var/mail
- mailstate:/var/mail-state
2019-09-15 13:40:05 +00:00
- maillogs:/var/log/mail
2017-07-03 11:16:16 +00:00
- ./config/:/tmp/docker-mailserver/
environment:
- ENABLE_SPAMASSASSIN=1
2020-05-02 17:10:36 +00:00
- SPAMASSASSIN_SPAM_TO_INBOX=1
2017-07-03 11:16:16 +00:00
- ENABLE_CLAMAV=1
- ENABLE_FAIL2BAN=1
- ENABLE_POSTGREY=1
- ONE_DIR=1
- DMS_DEBUG=0
- ENABLE_LDAP=1
- LDAP_SERVER_HOST=ldap # your ldap container/IP/ServerName
- LDAP_SEARCH_BASE=ou=people,dc=localhost,dc=localdomain
- LDAP_BIND_DN=cn=admin,dc=localhost,dc=localdomain
- LDAP_BIND_PW=admin
2018-11-03 20:52:17 +00:00
- LDAP_QUERY_FILTER_USER=(& (mail=%s)(mailEnabled=TRUE))
- LDAP_QUERY_FILTER_GROUP=(& (mailGroupMember=%s)(mailEnabled=TRUE))
2019-02-02 10:02:31 +00:00
- LDAP_QUERY_FILTER_ALIAS=(|(& (mailAlias=%s)(objectClass=PostfixBookMailForward))(& (mailAlias=%s)(objectClass=PostfixBookMailAccount)(mailEnabled=TRUE)))
- LDAP_QUERY_FILTER_DOMAIN=(|(& (mail=*@%s)(objectClass=PostfixBookMailAccount)(mailEnabled=TRUE))(& (mailGroupMember=*@%s)(objectClass=PostfixBookMailAccount)(mailEnabled=TRUE))(& (mailalias=*@%s)(objectClass=PostfixBookMailForward)))
2018-11-03 20:52:17 +00:00
- DOVECOT_PASS_FILTER=(& (objectClass=PostfixBookMailAccount)(uniqueIdentifier=%n))
- DOVECOT_USER_FILTER=(& (objectClass=PostfixBookMailAccount)(uniqueIdentifier=%n))
2017-07-03 11:16:16 +00:00
- ENABLE_SASLAUTHD=1
- SASLAUTHD_MECHANISMS=ldap
- SASLAUTHD_LDAP_SERVER=ldap
- SASLAUTHD_LDAP_BIND_DN=cn=admin,dc=localhost,dc=localdomain
- SASLAUTHD_LDAP_PASSWORD=admin
- SASLAUTHD_LDAP_SEARCH_BASE=ou=people,dc=localhost,dc=localdomain
2020-07-23 05:14:54 +00:00
- SASLAUTHD_LDAP_FILTER=(& (objectClass=PostfixBookMailAccount)(uniqueIdentifier=%U))
2017-07-03 11:16:16 +00:00
- POSTMASTER_ADDRESS=postmaster@localhost.localdomain
2018-10-15 19:17:45 +00:00
- POSTFIX_MESSAGE_SIZE_LIMIT=100000000
2017-07-03 11:16:16 +00:00
cap_add:
- NET_ADMIN
2017-10-10 06:15:18 +00:00
- SYS_PTRACE
2020-09-21 11:54:31 +00:00
restart: always
2017-07-03 11:16:16 +00:00
volumes:
maildata:
mailstate:
2019-09-15 13:40:05 +00:00
maillogs:
2017-07-03 11:16:16 +00:00
```