From 81c08b82d51ccd1c07f7a9830a1e88e1973f403d Mon Sep 17 00:00:00 2001 From: Thomas VIAL Date: Sat, 2 May 2015 19:05:34 +0200 Subject: [PATCH] Added virtual aliases management using dedicated env variable. --- README.md | 7 +++++-- start-mailserver.sh | 40 ++++++++++++++++++++++++++-------------- 2 files changed, 31 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 51357b5e..ad3fd7a4 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,7 @@ Additional informations: - mails are stored in `/var/mail/${domain}/${username}` - email login are full email address (`username1@my-domain.com`) - ssl is strongly recommended +- do not add whitespace in `$docker_mail_users` or `$docker_mail_aliases` ## installation @@ -28,8 +29,7 @@ Additional informations: ## docker-compose template mail: - build: . - # or use 'image: tvial/docker-mailserver' + image: tvial/docker-mailserver hostname: mail domainname: my-domain.com ports: @@ -43,6 +43,9 @@ Additional informations: docker_mail_users: - "username1@my-domain.com|username1password" - "username2@my-domain.com|username2password" + docker_mail_aliases: + - "username1@my-domain.com|alias1,alias2,alias3" + - "username2@my-domain.com|alias4" # todo diff --git a/start-mailserver.sh b/start-mailserver.sh index 5a0e39bb..09ab63bf 100644 --- a/start-mailserver.sh +++ b/start-mailserver.sh @@ -2,30 +2,42 @@ echo "Regenerating 'vmailbox' for given users" -echo "docker_mail_users => $docker_mail_users" - echo "# WARNING: this file is auto-generated. Do not modify locally" > /etc/postfix/vmailbox echo $docker_mail_users | sed -r 's/\[|\]|\x27| //g' | sed -r 's/,/\n/g' > /tmp/docker_mail_users while IFS=$'|' read -r login pass do - # Setting variables for better readability - user=$(echo ${login} | cut -d @ -f1) - domain=$(echo ${login} | cut -d @ -f2) + # 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 '${pass}'" - echo "${login} ${domain}/${user}/" >> /etc/postfix/vmailbox - 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} - maildirmake /var/mail/${domain}/${user} - echo ${domain} >> /tmp/vhost.tmp + # Let's go! + echo "user '${user}' for domain '${domain}' with password '${pass}'" + echo "${login} ${domain}/${user}/" >> /etc/postfix/vmailbox + 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} + maildirmake /var/mail/${domain}/${user} + echo ${domain} >> /tmp/vhost.tmp done < /tmp/docker_mail_users rm /tmp/docker_mail_users makeuserdb +echo "Regenerating 'virtual' for given aliases" +echo $docker_mail_aliases | sed -r 's/\[|\]|\x27|//g' | sed -r 's/, /\n/g' > /tmp/docker_mail_aliases +while IFS=$'|' read -r login aliases +do + arr=$(echo $aliases | tr "," "\n") + for alias in $arr + do + user=$(echo ${login} | cut -d @ -f1) + domain=$(echo ${login} | cut -d @ -f2) + echo "$alias@$domain redirects to $login" + echo "$alias@$domain\t$login" >> /etc/postfix/virtual + done +done < /tmp/docker_mail_aliases + echo "Postfix configurations" postmap /etc/postfix/vmailbox touch /etc/postfix/virtual && postmap /etc/postfix/virtual