mailserver2/mailserver

By mailserver2

Updated 3 months ago

Simple and full-featured mail server using Docker

Image
15

500K+

mailserver2/mailserver repository overview

mailserver2/mailserver

Fork

This is a fork that provides the bare minimum of maintenance for the excellent hardware/mailserver. Thank you very much.

Chat & questions

Build

Build Status

Docker image

mailserver2/mailserver is a simple and full-featured mail server build as a set of multiple docker images, including:

  • Postfix: a full-set SMTP email server
  • Dovecot: secure IMAP and POP3 email server
  • Rspamd: anti-spam filter with SPF, DKIM, DMARC, ARC, rate limiting and greylisting capabilities
  • Clamav: antivirus with automatic updates and third-party signature databases
  • Zeyple: automatic GPG encryption of all your emails
  • Sieve: email filtering (vacation auto-responder, auto-forward, etc...)
  • Fetchmail: fetch emails from external IMAP/POP3 server into local mailbox
  • Rainloop: web based email client
  • Postfixadmin: web-based administration interface
  • Unbound: recursive caching DNS resolver with DNSSEC support
  • NSD: authoritative DNS server with DNSSEC support
  • Træfik: modern HTTP reverse proxy
  • SSL: Let's Encrypt with auto-renewal (SAN and wildcard certificates), custom and self-signed certificates support
  • *OpenLDAP: [BETA] LDAP support available (only in 1.1-latest for now)
  • Supporting multiple virtual domains over MySQL/PostgreSQL backend
  • Integration tests with Travis CI
  • Automated builds on DockerHub
Summary
System Requirements

Please check, if your system meets the following minimum requirements:

With MariaDB/PostgreSQL and Redis on the same host
TypeWithout ClamAVWith ClamAV
CPU1 GHz1 GHz
RAM1.5 GiB2 GiB
With MariaDB/PostgreSQL and Redis hosted on another server
TypeWithout ClamAVWith ClamAV
CPU1 GHz1 GHz
RAM512 MiB1 GiB

Back to table of contents :arrow_up_small:

Prerequisites
Cleaning

Please remove any web server and mail services running on your server. I recommend using a clean installation of your preferred distribution. If you are using Debian, remember to remove the default MTA Exim4:

# apt-get purge exim4*

Also make sure that no other application is interfering with mail server configuration:

# netstat -tulpn | grep -E -w '25|80|110|143|443|465|587|993|995|4190'

If this command returns any results please remove or stop the application running on that port.

Ports

If you have a firewall, unblock the following ports, according to your needs:

ServiceSoftwareProtocolPort
SMTPPostfixTCP25
HTTPNginxTCP80
POP3DovecotTCP110
IMAPDovecotTCP143
HTTPSNginxTCP443
SMTPSPostfixTCP465
SubmissionPostfixTCP587
IMAPSDovecotTCP993
POP3SDovecotTCP995
ManageSieveDovecotTCP4190
DNS setup

I recommend you to use hardware/nsd-dnssec as an authoritative name server with DNSSEC capabilities. NSD is an authoritative only, high performance, simple and open source name server.

DNS records and reverse PTR

A correct DNS setup is required, this step is very important.

HOSTNAMECLASSTYPEPRIORITYVALUE
mailINA/AAAAany1.2.3.4
spamINCNAMEanymail.domain.tld.
webmailINCNAMEanymail.domain.tld.
postfixadminINCNAMEanymail.domain.tld.
@INMX10mail.domain.tld.
@INTXTany"v=spf1 a mx ip4:SERVER_IPV4 ~all"
{{selector}}._domainkeyINTXTany"v=DKIM1; k=rsa; p=YOUR DKIM Public Key"
_dmarcINTXTany"v=DMARC1; p=reject; rua=mailto:[email protected]; ruf=mailto:[email protected]; fo=0; adkim=s; aspf=s; pct=100; rf=afrf; sp=reject"

Notes:

  • Make sure that the PTR record of your IP matches the FQDN (default: mail.domain.tld) of your mailserver host. This record is usually set in your web hosting interface.
  • {{selector}} defaults to mail unless changed via DKIM_SELECTOR
  • DKIM, SPF and DMARC records are recommended to build a good reputation score.
  • The DKIM public key will be available on host after the container startup:
/mnt/docker/mail/dkim/domain.tld/{{selector}}.public.key

To regenerate your public and private keys, remove the /mnt/docker/mail/dkim/domain.tld folder. By default a 1024-bit key is generated, you can increase this size by setting the DKIM_KEY_LENGTH environment variable with a higher value. Check your domain registrar support to verify that it supports a TXT record long enough for a key larger than 1024 bits.

These DNS record will raise your trust reputation score and reduce abuse of your domain name. You can find more information here:

Testing

You can audit your mailserver with the following assessment services:

Back to table of contents :arrow_up_small:

Installation
1 - Prepare your environment

:bulb: The reverse proxy used in this setup is Traefik, but you can use the solution of your choice (Nginx, Apache, Haproxy, Caddy, H2O, etc pp).

:warning: This docker image may not work with some hardened Linux distribution using security-enhancing kernel patches like GrSecurity, please use a supported platform.

# Create a new docker network for Traefik (IPv4 only)
docker network create http_network
# If you want to support IPv6, please refer to [IPv6 support]

# Create the required folders and files
mkdir -p /mnt/docker/traefik/acme && cd /mnt/docker \
&& curl https://raw.githubusercontent.com/mailserver2/mailserver/master/docker-compose.sample.yml -o docker-compose.yml \
&& curl https://raw.githubusercontent.com/mailserver2/mailserver/master/sample.env -o .env \
&& curl https://raw.githubusercontent.com/mailserver2/mailserver/master/traefik.sample.toml -o traefik/traefik.toml \
&& touch traefik/acme/acme.json \
&& chmod 600 docker-compose.yml .env traefik/traefik.toml traefik/acme/acme.json

Edit the .env and traefik.toml, adapt to your needs, then start all services:

docker-compose up -d
2 - Postfixadmin installation

PostfixAdmin is a web based interface used to manage mailboxes, virtual domains and aliases.

3 - Rainloop installation (optional)

Rainloop is a simple, modern and fast web mail front end with Sieve scripts support (filters and vacation message), GPG and a modern user interface.

4 - Done, congratulation ! :tada:

At first launch, the container takes few minutes to generate SSL certificates (if needed), DKIM keypair generation and update Clamav database, all of this takes some time (1/2 minutes). This image comes with a snake-oil self-signed certificate, please use your own trusted certificates. See below for configuration.

List of webservices available:

Traefik dashboard use a basic authentication (user:admin, password:12345), the password can be encoded in MD5, SHA1 and BCrypt. You can use htpasswd to generate those ones. Users can be specified directly in the traefik.toml file. Rspamd dashboard use the password defined in your docker-compose.yml.

You can check the startup logs with this command:

# docker logs -f mailserver

[INFO] Let's encrypt live directory found
[INFO] Using /etc/letsencrypt/live/mail.domain.tld folder
[INFO] Creating DKIM keys for domain domain.tld
[INFO] Database hostname found in /etc/hosts
[INFO] Fetchmail forwarding is enabled.
[INFO] Automatic GPG encryption is enabled.
[INFO] ManageSieve protocol is enabled.
[INFO] POP3 protocol is enabled.
-------------------------------------------------------------------------------------
2017-08-26T11:06:58.885562+00:00 mail root: s6-supervise : spawning clamd process
2017-08-26T11:06:59.059077+00:00 mail root: s6-supervise : spawning freshclam process
2017-08-26T11:06:59.395214+00:00 mail root: s6-supervise : spawning rspamd process
2017-08-26T11:07:01.615597+00:00 mail root: s6-supervise : spawning unbound process
2017-08-26T11:07:01.870856+00:00 mail root: s6-supervise : spawning postfix process
2017-08-26T11:07:03.303536+00:00 mail root: s6-supervise : spawning dovecot process
...

Back to table of contents :arrow_up_small:

Rancher Catalog

rancher-logo

https://github.com/hardware/mailserver-rancher

This catalog provides a basic template to easily deploy an email server based on hardware/mailserver very quickly. To use it, just add this repository to your Rancher system as a catalog in Admin > Settings page and follow the readme. This catalog has been initiated by @MichelDiz.

rancher-ui

Back to table of contents :arrow_up_small:

Ansible Playbooks

logo

If you use Ansible, I recommend you to go to see @ksylvan playbooks here: https://github.com/ksylvan/docker-mail-server

Back to table of contents :arrow_up_small:

Environment variables
VariableDescriptionTypeDefault value
VMAILUIDvmail user idoptional1024
VMAILGIDvmail group idoptional1024
VMAIL_SUBDIRIndividual mailbox' subdirectoryoptionalmail
DKIM_KEY_LENGTHSize of your DKIM RSA key pairoptional1024
DKIM_SELECTORYour DKIM selectoroptionalmail
DEBUG_MODEEnable Postfix, Dovecot, Rspamd and Unbound verbose loggingoptionalfalse
PASSWORD_SCHEMEPasswords encryption schemeoptionalSHA512-CRYPT
DBDRIVERDatabase type: mysql, pgsql, ldapoptionalmysql
DBHOSTDatabase instance ip/hostnameoptionalmariadb
DBPORTDatabase instance portoptional3306 / 389 (sql/ldap)
DBUSERDatabase usernameoptionalpostfix
DBNAMEDatabase nameoptionalpostfix
DBPASSDatabase password or location of a file containing itrequired *1)null
REDIS_HOSTRedis instance ip/hostnameoptionalredis
REDIS_PORTRedis instance portoptional6379
REDIS_PASSRedis database password or location of a file containing itoptionalnull
REDIS_NUMBRedis database numberoptional0
RSPAMD_PASSWORDRspamd WebUI and controller password or location of a file containing itrequirednull
ADD_DOMAINSAdd additional domains to the mailserver separated by commas (needed for dkim keys etc.)optionalnull
RELAY_NETWORKSAdditional IPs or networks the mailserver relays without authenticationoptionalnull
WHITELIST_SPAM_ADDRESSESList of whitelisted email addresses separated by commasoptionalnull
DISABLE_RSPAMD_MODULEList of disabled modules separated by commasoptionalnull
DISABLE_CLAMAVDisable virus scanningoptionalfalse
DISABLE_SIEVEDisable ManageSieve protocoloptionalfalse
DISABLE_SIGNINGDisable DKIM/ARC signingoptionalfalse
DISABLE_GREYLISTINGDisable greylisting policyoptionalfalse
DISABLE_RATELIMITINGDisable rate limiting policyoptionaltrue
DISABLE_DNS_RESOLVERDisable the local DNS resolveroptionalfalse
DISABLE_SSL_WATCHDisable watching of acme.json and the Let's Encrypt directoryoptionalfalse
ENABLE_POP3Enable POP3 protocoloptionalfalse
ENABLE_FETCHMAILEnable fetchmail forwardingoptionalfalse
ENABLE_ENCRYPTIONEnable automatic GPG encryptionoptionalfalse
FETCHMAIL_INTERVALFetchmail polling intervaloptional10
RECIPIENT_DELIMITERRFC 5233 subaddress extension separator (single character only)optional+

*1) DBPASS is NOT required when using LDAP authentication

When using LDAP authentication the following additional variables become available. All DBUSER, DBNAME and DBPASS variables will not be used in this case:

VariableDescriptionTypeDefault value
LDAP_TLS_ENABLEDEnable TLS on LDAPoptionalfalse
LDAP_TLS_CA_FILEThe TLS CA Filerequired if LDAP_TLS_ENABLED
LDAP_TLS_FORCEForce TLS connectionsrequired if LDAP_TLS_ENABLEDfalse
LDAP_BINDBind to LDAP Serveroptionaltrue
LDAP_BIND_DNThe DN to bind torequired if LDAP_BIND
LDAP_BIND_PWLDAP password or location of a file containing itrequired if LDAP_BIND
LDAP_DEFAULT_SEARCH_BASEThe base DN for all lookupsrequired
LDAP_DEFAULT_SEARCH_SCOPEThe default scope for all lookups (sub, base or one)optionalsub
LDAP_DOMAIN_SEARCH_BASEThe search base for domain lookupsoptional${LDAP_DEFAULT_SEARCH_BASE}
LDAP_DOMAIN_SEARCH_SCOPEThe search scope for domain lookupsoptional${LDAP_DEFAULT_SEARCH_SCOPE}
LDAP_DOMAIN_FILTERThe search filter for domain lookupsrequired
LDAP_DOMAIN_ATTRIBUTEThe attributes for domain lookuprequired
LDAP_DOMAIN_FORMATThe format for domain lookupsoptional
LDAP_MAILBOX_SEARCH_BASEThe search base for mailbox lookupsoptional${LDAP_DEFAULT_SEARCH_BASE}
LDAP_MAILBOX_SEARCH_SCOPEThe search scope for mailbox lookupsoptional${LDAP_DEFAULT_SEARCH_SCOPE}
LDAP_MAILBOX_FILTERThe search filter for mailbox lookupsrequired
LDAP_MAILBOX_ATTRIBUTEThe attributes for mailbox lookuprequired
LDAP_MAILBOX_FORMATThe format for domain mailboxoptional
LDAP_ALIAS_SEARCH_BASEThe search base for domain lookupsoptional${LDAP_DEFAULT_SEARCH_BASE}
LDAP_ALIAS_SEARCH_SCOPEThe search scope for domain lookupsoptional${LDAP_DEFAULT_SEARCH_SCOPE}
LDAP_ALIAS_FILTERThe search filter for domain lookupsrequired
LDAP_ALIAS_ATTRIBUTEThe attributes for domain lookuprequired
LDAP_ALIAS_FORMATThe format for domain lookupsoptional
LDAP_FORWARD_SEARCH_BASEThe search base for forward lookupsoptional${LDAP_DEFAULT_SEARCH_BASE}
LDAP_FORWARD_SEARCH_SCOPEThe search scope for forward lookupsoptional${LDAP_DEFAULT_SEARCH_SCOPE}
LDAP_FORWARD_FILTERThe search filter for forward lookupsoptional
LDAP_FORWARD_ATTRIBUTEThe attributes for forward lookupoptional
LDAP_FORWARD_FORMATThe format for forward lookupsoptional
LDAP_GROUP_SEARCH_BASEThe search base for group lookupsoptional${LDAP_DEFAULT_SEARCH_BASE}
LDAP_GROUP_SEARCH_SCOPEThe search scope for group lookupsoptional${LDAP_DEFAULT_SEARCH_SCOPE}
LDAP_GROUP_FILTERThe search filter for group lookupsoptional
LDAP_GROUP_ATTRIBUTEThe attributes for group lookupoptional
LDAP_GROUP_FORMATThe format for group lookupsoptional
LDAP_SENDER_SEARCH_BASEThe search base for sender lookupsoptional${LDAP_DEFAULT_SEARCH_BASE}
LDAP_SENDER_SEARCH_SCOPEThe search scope for sender lookupsoptional${LDAP_DEFAULT_SEARCH_SCOPE}
LDAP_SENDER_FILTERThe search filter for sender lookupsrequired
LDAP_SENDER_ATTRIBUTEThe attributes for sender lookuprequired
LDAP_SENDER_FORMATThe format for sender lookupsrequired
LDAP_DOVECOT_USER_ATTRSDovecot user attribute mappingrequired
LDAP_DOVECOT_USER_FILTERDovecot user search filterrequired
LDAP_DOVECOT_PASS_ATTRSDovecot user password attribute mappingrequired
LDAP_DOVECOT_PASS_FILTERDovecot user password filterrequired
LDAP_DOVECOT_ITERATE_ATTRSDovecot user iterate attributesoptional
LDAP_DOVECOT_ITERATE_FILTERDovecot user iterate filtersoptional
LDAP_MASTER_USER_ENABLEDEnable LDAP master usersoptionalfalse
LDAP_MASTER_USER_SEPARATORLDAP master user separatorrequired if LDAP_MASTER_USER_ENABLED*
LDAP_MASTER_USER_SEARCH_BASELDAP master user search baserequired if LDAP_MASTER_USER_ENABLED${LDAP_DEFAULT_SEARCH_BASE}
LDAP_MASTER_USER_SEARCH_SCOPELDAP master user scoperequired if LDAP_MASTER_USER_ENABLED${LDAP_DEFAULT_SEARCH_SCOPE}
LDAP_DOVECOT_MASTER_USER_ATTRSLDAP master user Dovecot attributesrequired if LDAP_MASTER_USER_ENABLED
LDAP_DOVECOT_MASTER_USER_FILTERLDAP master user Dovecot search filterrequired if LDAP_MASTER_USER_ENABLED

Back to table of contents :arrow_up_small:

Automatic GPG encryption of all your emails
How does it work ?

Zeyple catches email from the postfix queue, then encrypts it if a corresponding recipient's GPG public key is found. Finally, it puts it back into the queue.

zeyple

Enable automatic GPG encryption

:heavy_exclamation_mark: Please enable this option carefully and only if you know what you are doing.

Switch ENABLE_ENCRYPTION environment variable to true. The public keyring will be saved in /var/mail/zeyple/keys. Please don't change the default value of RECIPIENT_DELIMITER (default = "+"). If encryption is enabled with another delimiter, Zeyple could have an unpredictable behavior.

Import your public key

:warning: Make sure to send your public key on a GPG keyserver before to run the following command.

docker exec -ti mailserver encryption.sh import-key YOUR_KEY_ID
Import all recipients public keys

This command browses all /var/mail/vhosts/* domains directories and users subdirectories to find all the recipients addresses in the mailserver.

docker exec -ti mailserver encryption.sh import-all-keys
Specify another GPG keyserver
docker exec -ti mailserver encryption.sh import-key YOUR_KEY

Tag summary

Content type

Image

Digest

sha256:b6a65785a

Size

161.3 MB

Last updated

3 months ago

docker pull mailserver2/mailserver:1.1.23.1