Here is a shell script that will iterate through all your Plesk domains to quickly add email addresses in bulk without going through each domain’s settings yourself.
This specific script adds a webmaster email address with standard aliases like [email protected] and [email protected], but without an actual mailbox. The messages are forwarded to an address at another domain name. It will also enable the antivirus scanning.
When an address already exists it writes an error and continues to the next domain.
You can run the code manually to process all of your existing domains, but with the instructions below you can also have it executed each time a new domain is added to Plesk Onyx.
#!/bin/bash if [ $NEW_DOMAIN_NAME ]; then domains=$NEW_DOMAIN_NAME else query="SELECT name FROM domains WHERE parentDomainId=0;" domains=$(plesk db -Ne "$query") fi count=$(echo $domains | wc -w) i=0 echo -e "\e[33mAdding webmaster emails to \e[1m$count\e[0m\e[33m domains\e[0m" echo for domain in $domains; do i=$(expr $i + 1) echo -n "$i/$count - " plesk bin mail \ --create [email protected]$domain \ -mailbox false \ -aliases add:abuse,hostmaster,postmaster,mail,mailer-daemon,sysadmin \ -forwarding true \ -forwarding-addresses add:[email protected] \ -antivirus inout \ -cp-access false done
Make sure to change
[email protected]therdomain.tld to your real destination.
Automation with events
Save it in
/root/bin/domains_add_webmaster.sh and make it executable only by the root user:
chmod 0700 /root/bin/domains_add_webmaster.sh
Now go to Tools & Settings > Event Manager > Add Event Handler and enter the following details: