mirror of
https://github.com/docker-mailserver/docker-mailserver.git
synced 2024-01-19 02:48:50 +00:00
Added virtual aliases management using dedicated env variable.
This commit is contained in:
parent
50e96ab406
commit
81c08b82d5
|
@ -16,6 +16,7 @@ Additional informations:
|
||||||
- mails are stored in `/var/mail/${domain}/${username}`
|
- mails are stored in `/var/mail/${domain}/${username}`
|
||||||
- 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
|
||||||
|
- do not add whitespace in `$docker_mail_users` or `$docker_mail_aliases`
|
||||||
|
|
||||||
## installation
|
## installation
|
||||||
|
|
||||||
|
@ -28,8 +29,7 @@ Additional informations:
|
||||||
## docker-compose template
|
## docker-compose template
|
||||||
|
|
||||||
mail:
|
mail:
|
||||||
build: .
|
image: tvial/docker-mailserver
|
||||||
# or use 'image: tvial/docker-mailserver'
|
|
||||||
hostname: mail
|
hostname: mail
|
||||||
domainname: my-domain.com
|
domainname: my-domain.com
|
||||||
ports:
|
ports:
|
||||||
|
@ -43,6 +43,9 @@ Additional informations:
|
||||||
docker_mail_users:
|
docker_mail_users:
|
||||||
- "username1@my-domain.com|username1password"
|
- "username1@my-domain.com|username1password"
|
||||||
- "username2@my-domain.com|username2password"
|
- "username2@my-domain.com|username2password"
|
||||||
|
docker_mail_aliases:
|
||||||
|
- "username1@my-domain.com|alias1,alias2,alias3"
|
||||||
|
- "username2@my-domain.com|alias4"
|
||||||
|
|
||||||
# todo
|
# todo
|
||||||
|
|
||||||
|
|
|
@ -2,30 +2,42 @@
|
||||||
|
|
||||||
echo "Regenerating 'vmailbox' for given users"
|
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 "# 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
|
echo $docker_mail_users | sed -r 's/\[|\]|\x27| //g' | sed -r 's/,/\n/g' > /tmp/docker_mail_users
|
||||||
while IFS=$'|' read -r login pass
|
while IFS=$'|' read -r 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 '${pass}'"
|
echo "user '${user}' for domain '${domain}' with password '${pass}'"
|
||||||
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}
|
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}
|
||||||
maildirmake /var/mail/${domain}/${user}
|
maildirmake /var/mail/${domain}/${user}
|
||||||
echo ${domain} >> /tmp/vhost.tmp
|
echo ${domain} >> /tmp/vhost.tmp
|
||||||
|
|
||||||
done < /tmp/docker_mail_users
|
done < /tmp/docker_mail_users
|
||||||
rm /tmp/docker_mail_users
|
rm /tmp/docker_mail_users
|
||||||
makeuserdb
|
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"
|
echo "Postfix configurations"
|
||||||
postmap /etc/postfix/vmailbox
|
postmap /etc/postfix/vmailbox
|
||||||
touch /etc/postfix/virtual && postmap /etc/postfix/virtual
|
touch /etc/postfix/virtual && postmap /etc/postfix/virtual
|
||||||
|
|
Loading…
Reference in a new issue