Removed "docker_mail_domain" env. variable to use docker hostname and improved documentation for #13

This commit is contained in:
Thomas VIAL 2015-08-17 22:16:08 +02:00
parent 09c8166a24
commit 63a7be0e97
3 changed files with 11 additions and 16 deletions

View file

@ -16,6 +16,7 @@ Additional informations:
- only config files, no *sql database required - only config files, no *sql database required
- mails are stored in `/var/mail/${domain}/${username}` - 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 (`username1@my-domain.com`) - email login are full email address (`username1@my-domain.com`)
- ssl is strongly recommended - ssl is strongly recommended
- user accounts are managed in `./postfix/accounts.cf` - user accounts are managed in `./postfix/accounts.cf`
@ -33,7 +34,7 @@ Additional informations:
## run ## 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) ## docker-compose template (recommended)
@ -47,11 +48,9 @@ Additional informations:
- "143:143" - "143:143"
- "587:587" - "587:587"
- "993:993" - "993:993"
environment:
docker_mail_domain: "my-domain.com"
volumes: volumes:
- ./spamassassin:/tmp/spamassassin/:ro - ./spamassassin:/tmp/spamassassin/
- ./postfix:/tmp/postfix/:ro - ./postfix:/tmp/postfix/
Volumes allow to: Volumes allow to:

View file

@ -1,23 +1,19 @@
#!/bin/sh #!/bin/sh
echo "Regenerating postfix 'vmailbox' and 'virtual' for given users" 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 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 # Creating users
while IFS=$'|' read -r login pass while IFS=$'|' read login pass
do do
# Setting variables for better readability # Setting variables for better readability
user=$(echo ${login} | cut -d @ -f1) user=$(echo ${login} | cut -d @ -f1)
domain=$(echo ${login} | cut -d @ -f2) domain=$(echo ${login} | cut -d @ -f2)
# Let's go! # Let's go!
echo "user '${user}' for domain '${domain}' with password '********'" echo "user '${user}' for domain '${domain}' with password '********'"
echo "${login} ${domain}/${user}/" >> /etc/postfix/vmailbox 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}" | userdbpw -md5 | userdb ${login} set systempw
echo "${pass}" | saslpasswd2 -p -c -u ${domain} ${login} echo "${pass}" | saslpasswd2 -p -c -u ${domain} ${login}
mkdir -p /var/mail/${domain} mkdir -p /var/mail/${domain}
@ -31,7 +27,7 @@ cp /tmp/postfix/virtual /etc/postfix/virtual
echo "Postfix configurations" echo "Postfix configurations"
postmap /etc/postfix/vmailbox postmap /etc/postfix/vmailbox
postmap /etc/postfix/virtual 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 cat /tmp/vhost.tmp | sort | uniq >> /etc/postfix/vhost && rm /tmp/vhost.tmp
echo "Fixing permissions" echo "Fixing permissions"
@ -39,7 +35,7 @@ chown -R 5000:5000 /var/mail
mkdir -p /var/log/clamav && chown -R clamav:root /var/log/clamav mkdir -p /var/log/clamav && chown -R clamav:root /var/log/clamav
echo "Creating /etc/mailname" echo "Creating /etc/mailname"
echo $docker_mail_domain > /etc/mailname echo $(hostname -d) > /etc/mailname
echo "Configuring Spamassassin" echo "Configuring Spamassassin"
echo "required_hits 5.0" >> /etc/mail/spamassassin/local.cf echo "required_hits 5.0" >> /etc/mail/spamassassin/local.cf