Skip to content

Commit

Permalink
Removed "docker_mail_domain" env. variable to use docker hostname and…
Browse files Browse the repository at this point in the history
… improved documentation for docker-mailserver#13
  • Loading branch information
tomav committed Aug 17, 2015
1 parent 09c8166 commit 63a7be0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 16 deletions.
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Additional informations:

- only config files, no *sql database required
- mails are stored in `/var/mail/${domain}/${username}`
- you should use a data volume container for `/var/mail` for data persistence
- email login are full email address (`[email protected]`)
- ssl is strongly recommended
- user accounts are managed in `./postfix/accounts.cf`
Expand All @@ -33,7 +34,7 @@ Additional informations:

## run

docker run -v "$(pwd)/postfix":/tmp/postfix -v "$(pwd)/spamassassin":/tmp/spamassassin -p "25:25" -p "143:143" -p "587:587" -p "993:993" -e docker_mail_domain=my-domain.com -t tvial/docker-mailserver
docker run --name mail -v "$(pwd)/postfix":/tmp/postfix -v "$(pwd)/spamassassin":/tmp/spamassassin -p "25:25" -p "143:143" -p "587:587" -p "993:993" -h mail.my-domain.com -t tvial/docker-mailserver

## docker-compose template (recommended)

Expand All @@ -47,11 +48,9 @@ Additional informations:
- "143:143"
- "587:587"
- "993:993"
environment:
docker_mail_domain: "my-domain.com"
volumes:
- ./spamassassin:/tmp/spamassassin/:ro
- ./postfix:/tmp/postfix/:ro
- ./spamassassin:/tmp/spamassassin/
- ./postfix:/tmp/postfix/

Volumes allow to:

Expand Down
2 changes: 1 addition & 1 deletion postfix/accounts.cf
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[email protected]|mypassword
[email protected]|mypassword
16 changes: 6 additions & 10 deletions start-mailserver.sh
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
#!/bin/sh

echo "Regenerating postfix 'vmailbox' and 'virtual' for given users"
# rm /etc/postfix/virtual
# rm /etc/postfix/virtual.db
# rm /etc/postfix/vmailbox
# rm /etc/postfix/vmailbox.db
echo "# WARNING: this file is auto-generated. Modify accounts.cf in postfix directory on host" > /etc/postfix/vmailbox
# Checking that /tmp/postfix/accounts.cf ends with a newline
sed -i -e '$a\' /tmp/postfix/accounts.cf
# Creating users
while IFS=$'|' read -r login pass
while IFS=$'|' read login pass
do

# Setting variables for better readability
user=$(echo ${login} | cut -d @ -f1)
domain=$(echo ${login} | cut -d @ -f2)

# Let's go!
echo "user '${user}' for domain '${domain}' with password '********'"
echo "${login} ${domain}/${user}/" >> /etc/postfix/vmailbox
userdb ${login} set uid=5000 gid=5000 home=/var/mail/${domain}/${user} mail=/var/mail/${domain}/${user}
/usr/sbin/userdb ${login} set uid=5000 gid=5000 home=/var/mail/${domain}/${user} mail=/var/mail/${domain}/${user}
echo "${pass}" | userdbpw -md5 | userdb ${login} set systempw
echo "${pass}" | saslpasswd2 -p -c -u ${domain} ${login}
mkdir -p /var/mail/${domain}
Expand All @@ -31,15 +27,15 @@ cp /tmp/postfix/virtual /etc/postfix/virtual
echo "Postfix configurations"
postmap /etc/postfix/vmailbox
postmap /etc/postfix/virtual
sed -i -r 's/DOCKER_MAIL_DOMAIN/'"$docker_mail_domain"'/g' /etc/postfix/main.cf
sed -i -r 's/DOCKER_MAIL_DOMAIN/'"$(hostname -d)"'/g' /etc/postfix/main.cf
cat /tmp/vhost.tmp | sort | uniq >> /etc/postfix/vhost && rm /tmp/vhost.tmp

echo "Fixing permissions"
chown -R 5000:5000 /var/mail
mkdir -p /var/log/clamav && chown -R clamav:root /var/log/clamav

echo "Creating /etc/mailname"
echo $docker_mail_domain > /etc/mailname
echo $(hostname -d) > /etc/mailname

echo "Configuring Spamassassin"
echo "required_hits 5.0" >> /etc/mail/spamassassin/local.cf
Expand Down

0 comments on commit 63a7be0

Please sign in to comment.