In this example we create an “everyone” mail address for the user domain ad.domain.tld and the maildomain domain.tld.
The mail address destinations are autofilled by a script that’s executed regularly via cron.
Create a mail address everyone@domain.tld and set it to internal in the advanced settings. You need to add an user as destination to be able to save the new address.
Create a script file /usr/local/bin/set-everyone-address.sh with following content, adapt ad.domain.tld to your user domain and domain.tld to your mail domain.
/usr/local/bin/api-cli run cluster/list-domain-users --data '{"domain":"ad.domain.tld"}' | \
jq '{"atype":"domain","local":"everyone","domain":"domain.tld","internal":true,"destinations":[.users[]|select(.user!="Administrator")|{"dtype":"user","name":.user}]}' | \
/usr/local/bin/api-cli run module/mail1/alter-address --data -
Make the script executable:
chmod +x /usr/local/bin/set-everyone-address.sh
Edit /etc/crontab to add an entry to run the script regularly, in this example the script runs every hour at minute 3, like 8:03, 9:03 etc.
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
# For details see man 4 crontabs
# Example of job definition:
# .---------------- minute (0 - 59)
# | .------------- hour (0 - 23)
# | | .---------- day of month (1 - 31)
# | | | .------- month (1 - 12) OR jan,feb,mar,apr ...
# | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# | | | | |
# * * * * * user-name command to be executed
3 * * * * root /usr/local/bin/set-everyone-address.sh
Now it should be possible to send a mail to everyone@domain.tld and all domain users will get the mail.
To force adding (new) domain users as mail address destination you can execute the command:
/usr/local/bin/set-everyone-address.sh

