Users like to forward email from emailaccounts under their own domain to their personal emailaccount at Hotmail, Google or other thirth party emailproviders. The current techniques does not handle forwarding spam very well, meaning that incoming spam is handled by your server and routed to the thirth party provider. The receiving provider thinks that you are sending spam and at some moment your server is blacklisted, either on public RBL’s or for example Microsoft their private RBL.
To prevent this from happening, the ideal situation would be to filter all spam and never forward spam anymore, however spamfilters are never 100% accurate. Besides this fact, we see many users who do configure their forwarder but do not configure or even enable the spamfilter (SpamAssassin for DirectAdmin). Since the receiving provider does filter the spam, the spam will never reach the customer his emailaccounts and everything works perfectly… for the user.
With the following code you can prevent the creation of forwarders to other domains if the SpamAssassin spamfilter is not configured. If SpamAssassin is not configured with a threshold of 3.0 and set to delete incoming spam the following error is shown when the user creates a forwarder to an other domain:
Create the following file and paste the code below in it: /usr/local/directadmin/scripts/custom/forwarder_create_pre.sh:
if [ -f /home/$username/.spamassassin/user_prefs ]; then
spamassassin_threshold=$(cat /home/$username/.spamassassin/user_prefs | grep "required_score" | sed -n -e 's/^.*required_score //p')
spam_policy=$(cat /etc/virtual/$domain/filter.conf | grep -o "where=.*" | cut -f2- -d=)
if [[ "$value" != *"$domain" && ($spamassassin_threshold != $spamassassin_minimum_required || $spam_policy != "delete") ]]; then
echo "<br><b>Forwarding to external emailaccounts is only allowed if SpamAssassin (the spamfilter) is configured with the required values:<br />
Current settings:<br />
SpamAssassin score: $spamassassin_threshold (required: $spamassassin_minimum_required)<br />
Policy: $spam_policy (required: $required_spam_policy)<br /><br />
Please adjust your <a href='/CMD_SPAMASSASSIN?domain=$domain'>SpamAssassin settings</a> to the required values and create the forwarder again.<br />
You can ignore the error below, this error is not applicable.
If you need additional spamfiltering or in case SpamAssassin does not work perfectly for you, then try our advanced SpamExperts spamfilter.