How to turn off mail for every domain in plesk

Here is a little script that will turn off mail for every domain in plesk! I use it as part of an automated domain creation script to be doubly sure that mail is sent from external mail services and isn’t received internally in the plesk machine (preventing users getting their mails)

Script to turn off mail for every domain in plesk

#!/bin/sh 
# change this bit if you want to disable on a specific domain -- just add the domain name you want
dir=`ls /var/www/vhosts/`
for dirs in $dir; do
/usr/local/psa/bin/mail --off $dirs
done

There used to be a setting in the plesk control panel to turn this off per domain, but its been disabled now.

We use an external mail provider to send outgoing mail over smtp and all the users inboxes are in these services too (usually gmail or outlook.com) so we have no need for the mail service to be running and resources, we also need to make sure that any mail sent from the domain is delivered to the external mailboxes and doesn’t get trapped inside the mail service for the domain in plesk.

The script takes a few seconds to run through all the domains in /var/www/vhosts and runs the plesk cli command to turn off the mail service for that domain. it takes less than 2 seconds to run for 250 hosts.

I keep this here so that I can remember the code in the file incase it needs to be updated between plesk updates and incase I ever need to reconstruct the code manually (though its now in our source-code repo with a host of other plesk related scripts that are used on a daily basis)

Sources: Plesk CLI Manual though this was written using an older version

Leave a Reply