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.
Intro
This event script adds a hostmaster email address with standard aliases like postmaster@
and abuse@
, 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.
Script
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.
#!/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 hostmaster 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 hostmaster@$domain \
-mailbox false \
-aliases add:abuse,postmaster,mail,mailer-daemon,sysadmin \
-forwarding true \
-forwarding-addresses add:info@otherdomain.tld \
-antivirus inout \
-cp-access false
done
Make sure to change info@otherdomain.tld
to your real destination.
Automation with events
Save it in /root/bin/domains_add_hostmaster.sh
and make it executable only by the root user:
chmod 0700 /root/bin/domains_add_hostmaster.sh
Now go to Tools & Settings > Event Manager > Add Event Handler and enter the following details:
Event:
Domain created
Priority:
Lowest (0)
User:
root
Command:/root/bin/domains_add_hostmaster.sh
Leave a Reply