Adding email accounts under Docker Mailserver

20th October 2019 (5 years ago)

These are some quick notes, mainly for myself. This is when you're adding new domains/users to an existing installation of Docker Mailserver

Account creation

Generate password entry for email/password combo:

docker run -e MAIL_USER=user1@domain.tld -e MAIL_PASS=mypassword -ti tvial/docker-mailserver /bin/sh -c 'echo "$MAIL_USER|$(doveadm pw -s SHA512-CRYPT -u $MAIL_USER -p $MAIL_PASS)"'

Add the output of the previous command to the file config/postfix-accounts.cf in your container's volume.

Aliases

Edit the file config/postfix-regexp.cf to catch email for different users.

This example routes all email for a domain to a single user account:

/^\S+@domain.tld/ info@domain.tld

If you want all usernames, except a select few, to go to a catch-all address add a line like this:

/^(?!alice|bob)\S+@example.com/ me@mydomain.com

You will need to restart the container after changes to regex aliases.