diff --git a/README.md b/README.md index a2ad5231..bfeea09a 100644 --- a/README.md +++ b/README.md @@ -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 (`username1@my-domain.com`) - ssl is strongly recommended - user accounts are managed in `./postfix/accounts.cf` @@ -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) @@ -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: diff --git a/postfix/accounts.cf b/postfix/accounts.cf index 94896e0d..ecb0f063 100644 --- a/postfix/accounts.cf +++ b/postfix/accounts.cf @@ -1 +1 @@ -user@domain.tld|mypassword \ No newline at end of file +user@domain.tld|mypassword diff --git a/start-mailserver.sh b/start-mailserver.sh index 60e50ecd..dc64c045 100644 --- a/start-mailserver.sh +++ b/start-mailserver.sh @@ -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} @@ -31,7 +27,7 @@ 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" @@ -39,7 +35,7 @@ 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