This assumes you have installed Docker mailserver.
Use the docker inspect command to determine where the /tmp/docker-mailserver directory in the mailserver container is mounted on the Docker system (/usr/local/docker/mailserver/config in this example).
~]$ sudo docker inspect mailserver
/usr/local/docker/mailserver/config:/tmp/docker-mailserver:rw
Issue the following command to create email accounts, replacing the /usr/local/docker/mailserver/config volume on the Docker system with whatever directory you are using on your Docker system for the /tmp/docker-mailserver mount.
sudo docker run --rm --volume "/usr/local/docker/mailserver/config/:/tmp/docker-mailserver/" mailserver/docker-mailserver setup email add <user@domain> <password>
Or like this.
docker run --rm -it mailserver/docker-mailserver:latest /bin/sh -c 'echo "john.doe@example.com|$(doveadm pw -s SHA512-CRYPT -u john.doe@example.com -p itsasecret)"' >> /usr/local/docker/mailserver/config/postfix-accounts.cf
The following command can be used to list the email account that have been created.
~]$ sudo docker exec mailserver /usr/local/bin/setup email list
* john.doe@example.com ( 0 / ~ ) [0%]
In the mailserver container, the /tmp/docker-mailserver/postfix-accounts.cf file will contain the email accounts that have been created.
~]$ sudo docker exec mailserver cat /tmp/docker-mailserver/postfix-accounts.cf
john.doe@example.com|{SHA512-CRYPT}$6$HFjdDqNGTy2U0xZy$iOWerYaERlqukmZlfM3lldY50ivciXQ5BN7JtdP0eKP8LpjT8WfRILWho8/l/xylTER.GZPNDDa1RDQUFiBnj1
On the Docker host, the docker-data/dms/config/postfix-accounts.cf file will contain the email accounts that have been created.
~]$ cat docker-data/dms/config/postfix-accounts.cf
john.doe@example.com|{SHA512-CRYPT}$6$HFjdDqNGTy2U0xZy$iOWerYaERlqukmZlfM3lldY50ivciXQ5BN7JtdP0eKP8LpjT8WfRILWho8/l/xylTER.GZPNDDa1RDQUFiBnj1
You can then issue a command like this to send a user an email.
sudo docker exec mailserver echo "Hello World" | mail -s "Example Subject" -r no-reply@example.com john.doe@example.com
And now this command should contain something like this, showing 2.0K of emails in this example.
~]$ sudo docker exec mailserver setup email list
* john.doe@example.com ( 2.0K / ~ ) [0%]
In the container, the /var/mail/domain/user directory should contain the users emails.
~]$ sudo docker exec mailserver ls -l /var/mail/example.com/john.doe/new
-rw-r--r-- 1 docker docker 1216 Mar 18 09:48 1647614891.M334214P1512.mail.example.com,S=1216,W=1244
On the Docker host, the docker-data/dms/mail-data/domain/user directory shguld also contain the users emails.
~]$ ll docker-data/dms/mail-data/example.com/john.doe/new/
-rw-r--r-- 1 5000 5000 1216 Mar 18 09:48 1647614891.M334214P1512.mail.example.com,S=1216,W=1244
Did you find this article helpful?
If so, consider buying me a coffee over at