• The new Python extension is now available. It allows customers to deploy and manage WSGI-based Python applications on their websites directly from Plesk.
  • The Plesk Mobile apps for iOS and Android and the Plesk Mobile Center extension have been deprecated, and are no longer available for new installations. In Plesk Obsidian 18.0.84, the Plesk Mobile Center extension will be removed from servers during the upgrade, and the Plesk Mobile apps will lose their server management features.
  • The Social Login extension has been deprecated and will be removed in Plesk Obsidian 18.0.84. After that, it will no longer be possible to log in to Plesk with a Google, Facebook, GitHub account, or with a passkey. Plesk usernames and passwords, as well as logging in with a WebPros Account, are not affected.

Question Disable Email Forwarding

Hangover2

Regular Pleskian
Server operating system version
Debian
Plesk version and microupdate number
Latest
Hello,

Is there an easy way to disable the email forwarding feature in the Plesk GUI — ideally per subscription, while still allowing local forwarding? Has anyone done this before and can share a suitable solution? I don’t expect Plesk to implement such a change just on request.

Background: we’re seeing increasing issues with users forwarding mail to external providers, especially when spam is involved.

Any ideas are welcome—thanks!
 
@Sebahat.hadzhi We used this plugin in the past; however, it has been incompatible with the latest Plesk releases for quite some time. We reached out to the author in 2022, but he no longer uses Plesk and does not plan to invest further effort into maintaining it.
 
I see. We have an existing feature request for that (not sure if it's yours), but there are no plans to implement it for the time being. I'll check if we can do something about the extension.
 
I'd really welcome the ability to enforce stricter forwarding control in Plesk. I too, am struggling with users setting up mail forwarding to external services/mailboxes which gets ours servers/ips a reputation hit sometimes because spam gets forwarded too. Even tough I am putting considerable effort into filtering spam (incoming and outgoing).

I am also not really keen on the fact that users can forward email to any email address, without first validating the recipients address (with a some sort of code for example). I occasionally have users setting up forwarding to non existing email addresses or worse, to some other some unknowing recipient :confused:
 
@danami This could be a nice feature for your Plesk extension, Warden Antispam and Virus protection. We’re using it on all of our servers.
This is something that really should be handled by Plesk. If you look at that "Internal Mail-Forwarding" extension all it was doing was overriding the default javascript to add the extra restrictions (something that Plesk should add so it doesn't break every time they change things).
 
I just wanted to remind everyone at Plesk that this issue continues to affect a large number of server administrators.

Forwarding emails to external domains often causes significant problems, and this is likely to become even more common in the future. Many email providers are continuously tightening their anti-spam policies and enforcement measures.

As a result, important emails may not be delivered, and our servers risk being placed on email blacklists.

It is very important that this functionality could at least be provided as a Plesk extension, similar to the previous extension that offered this feature but is no longer compatible with the current version of Plesk.
 
Hi everyone ... I used to have forwarding problems too. They are now almost completely gone.
Fixes I used:
- increase SA_MAX_MAIL_SIZE in /etc/psa/psa.conf (most important, Plesk default is 265KB. I increased to 5MB). Spammers know this and like to send mails bigger than 265 KB or even 1,5 MB.
- set delete spam in forwarding mailboxes instead of marking it.
- enable DNSBL(zen.spamhaus.org) and SPF-/DMARC-Checks for incoming mails.
- let Spamassasin query blocklists via local BIND - before it went via IONOS (my Hoster) and that was overusing.
- disable DSN, only allow it locally. That's also a technique spammers use. not really needed anymore.

Plesk already uses SRS and ARC - gmail knows, that the forwarded email has passed SPF and DMARC

I did not have any forwarding problems after these fixes.
 
- set delete spam in forwarding mailboxes instead of marking it.
The issue is that deleting spam instead of marking it (or storing it in the spam folder) is not a viable option for many, inlcuding myself. I've spent a great deal of time optimizing SpamAssassin, with great effect, but unfortunately there always remain some false positives. I.e regular, sometimes even important, messages that are marked spam. Which is why I can never opt to simply discard spam messages.
 
I dug a little deeper and tested.

Plesk runs the spam filter before forwarding, and what it does with spam decides (tested with a blocklisted sender): spam that is deleted or moved to the Spam folder is not forwarded, spam that is only marked is.
So moving is ok too ... marking is not really. It will probably harm your servers reputation (for all customers)
 
Maybe:
Code:
#tab-redirect-button,
#tab-redirect { display: none !important; }

Put this into the custom CSS of the "Skins and Color Schemes" extension (survives Plesk updates, no core files touched).

Notes:
- It only hides the Forwarding tab in the UI (for admins and customers alike). It does not block forwarding via API/CLI, and it cannot distinguish internal from external targets.
- The ID is from a current Plesk version (Obsidian, German UI). If it does not match on your server, check the tab button with F12 (Inspect) and adjust the selector.
- Test with a customer account, not only as admin.

Regards
Tessa
 
Re: #13 - CSS is only cosmetic. What actually helps against the real problem (spam / reputation damage through forwarding):

1) Make sure spam is not forwarded (biggest effect)
Per Mehl (#12): Plesk runs the spam filter before forwarding. Spam that is deleted or moved to the Spam folder is NOT forwarded, spam that is only marked IS. So in forwarding mailboxes use "move to Spam folder" (or delete), never "mark only". Moving avoids the false-positive problem Kaspar mentioned.

2) Reject spam at SMTP time, so it never gets accepted
Enable DNSBL (e.g. zen.spamhaus.org) and SPF/DMARC checks for incoming mail. What is rejected at SMTP time can never be forwarded later.

3) Tune the filter (Mehl #10)
- Increase SA_MAX_MAIL_SIZE in /etc/psa/psa.conf (default is small, spammers send mails above the limit so they skip the scan)
- Let SpamAssassin query blocklists via a local resolver
- Disable DSN for external recipients

4) Real "internal forwarding only" (not available out of the box, untested sketch)
The restriction has to be on the server side, not in the UI:
- Script (cron or Event Manager): read all forwarding targets from the Plesk DB, compare the target domain with the domains hosted on the server, remove or flag external targets
- or a Postfix restriction that rejects mail whose target is external after alias resolution (note: Plesk rewrites parts of the Postfix config on "plesk repair mail")
This also covers forwardings created via API, CLI or Roundcube, which the CSS does not.

Summary: CSS hides the button. 1 and 2 actually reduce the damage. 4 is the only real enforcement, and it has to be built by hand. Please vote on the existing feature request at features.plesk.com so Plesk offers this natively.

Regards
Tessa
 
Hi,

This could be a way to get real enforcement, but please treat it as an idea / starting point, not a finished solution. I tested the script logic only against a mocked "plesk" command, never on a real Plesk server. The plesk CLI/DB parts are unverified assumptions. Dry run is the default, so check the output first and try it on a non-production box.

Why not Postfix: smtpd restrictions only see the original recipient, not the target after alias expansion. Removing external targets with the Plesk CLI avoids that.

What it does:
- reads all domains and domain aliases hosted on this server
- reads all forwarding targets from the Plesk DB
- reports (dry run) or removes (--apply) targets whose domain is not hosted here
- skips targets listed in an optional whitelist
- never touches targets with unusual characters (e.g. unicode domains), it only reports them
- aborts if a DB query fails or returns no domains
- refuses --apply if more than MAX_REMOVE (default 25) targets would be removed
- writes a list of everything it removed to /var/backups/check-forwards/

1) Verify the two assumptions first (should print rows, not errors, and the data should look right):
Code:
plesk db -Ne "SELECT name FROM domain_aliases LIMIT 3"
plesk db -Ne "SELECT CONCAT(m.mail_name,'@',d.name), mr.address FROM mail m JOIN domains d ON d.id=m.dom_id JOIN mail_redir mr ON mr.mn_id=m.id WHERE m.mail_group='true' LIMIT 5"
Better: create a test mailbox, forward it to one internal and one external address in the GUI, and check that exactly these two rows show up.

2) Save as /usr/local/sbin/check-forwards.sh, chmod 700:
Code:
#!/bin/bash
# check-forwards.sh - remove forwarding targets that are not hosted on this server
# Default is a dry run. Nothing is changed without --apply.
export PATH="$PATH:/usr/local/sbin:/usr/sbin:/usr/local/bin:/usr/bin:/sbin:/bin"

ALLOW=${ALLOW:-/etc/check-forwards.allow}       # optional whitelist: one domain or full address per line
BACKUP_DIR=${BACKUP_DIR:-/var/backups/check-forwards}
LOCK=${LOCK:-/var/lock/check-forwards.lock}
MAX_REMOVE=${MAX_REMOVE:-25}                     # --apply refuses to remove more targets than this

APPLY=0
[ "$1" = "--apply" ] && APPLY=1

log() { echo "$(date -Is) $*"; }

exec 9>"$LOCK"
flock -n 9 || { log "already running"; exit 0; }

# Read everything first. Any error or empty domain list aborts, so a failed
# query can never make all targets look "external".
DOMS=$(plesk db -Ne "SELECT name FROM domains UNION SELECT name FROM domain_aliases") \
  || { log "ERROR: domain query failed, aborting"; exit 1; }
[ -n "$DOMS" ] || { log "ERROR: no local domains read, aborting"; exit 1; }
FWD=$(plesk db -Ne "SELECT CONCAT(m.mail_name,'@',d.name), mr.address FROM mail m JOIN domains d ON d.id=m.dom_id JOIN mail_redir mr ON mr.mn_id=m.id WHERE m.mail_group='true'") \
  || { log "ERROR: forwarding query failed, aborting"; exit 1; }
[ -n "$FWD" ] || { log "no forwardings found"; exit 0; }

declare -A LOCAL ALLOWED TOTAL EXT
while read -r d; do [ -n "$d" ] && LOCAL["${d,,}"]=1; done <<< "$DOMS"

if [ -r "$ALLOW" ]; then
  while read -r a; do
    a="${a%%#*}"; a="${a//[[:space:]]/}"
    [ -n "$a" ] && ALLOWED["${a,,}"]=1
  done < "$ALLOW"
fi

REMOVE=0
while IFS=$'\t' read -r box target; do
  [ -z "$target" ] && continue
  target="${target,,}"; tdom="${target##*@}"
  TOTAL["$box"]=$(( ${TOTAL["$box"]:-0} + 1 ))
  # unusual characters (e.g. unicode IDN): never touch automatically
  if [[ ! "$tdom" =~ ^[a-z0-9.-]+$ ]]; then
    log "skip (check manually): $box -> $target"; continue
  fi
  [ -n "${LOCAL[$tdom]}" ] && continue
  if [ -n "${ALLOWED[$target]}" ] || [ -n "${ALLOWED[$tdom]}" ]; then continue; fi
  EXT["$box"]+="$target,"
  REMOVE=$((REMOVE + 1))
  log "external: $box -> $target"
done <<< "$FWD"

log "$REMOVE external target(s) found"
[ "$APPLY" -eq 1 ] || exit 0
[ "$REMOVE" -gt 0 ] || exit 0
if [ "$REMOVE" -gt "$MAX_REMOVE" ]; then
  log "ERROR: $REMOVE > MAX_REMOVE ($MAX_REMOVE), not applying. Check the dry run, then run: MAX_REMOVE=$REMOVE $0 --apply"
  exit 1
fi

# keep a record so removed targets can be restored
mkdir -p "$BACKUP_DIR"; chmod 700 "$BACKUP_DIR"
BACKUP="$BACKUP_DIR/$(date +%Y%m%d-%H%M%S).txt"
for box in "${!EXT[@]}"; do
  printf '%s\t%s\n' "$box" "${EXT[$box]%,}" >> "$BACKUP"
done

for box in "${!EXT[@]}"; do
  list="${EXT[$box]%,}"
  n=$(tr ',' '\n' <<< "$list" | wc -l)
  if [ "$n" -ge "${TOTAL[$box]}" ]; then
    plesk bin mail -u "$box" -forwarding false || log "ERROR: could not disable forwarding for $box"
  fi
  plesk bin mail -u "$box" -forwarding-addresses del:"$list" \
    || { log "ERROR: removing targets failed for $box"; continue; }
  log "removed: $box -> $list"
done

3) Optional whitelist /etc/check-forwards.allow (whole domain or single address per line):
Code:
# allowed external targets
partner-company.example
[email protected]

4) Dry run (changes nothing):
Code:
/usr/local/sbin/check-forwards.sh

5) Remove external targets. If the dry run found more than 25, the script refuses and prints the command with the right MAX_REMOVE:
Code:
/usr/local/sbin/check-forwards.sh --apply

6) Optional, hourly via /etc/cron.d/check-forwards (only after you ran --apply by hand successfully):
Code:
0 * * * * root /usr/local/sbin/check-forwards.sh --apply >> /var/log/check-forwards.log 2>&1

Restore (syntax untested): the backup files contain "mailbox<TAB>targets", so a removed target can be re-added with
Code:
plesk bin mail -u [email protected] -forwarding true -forwarding-addresses add:[email protected]

Open questions / limits:
- Not verified: that mail_group='true' really means "forwarding active", and that plesk accepts "del:" on a mailbox where forwarding was just switched off (the script switches off first, then removes the targets). Please test with one mailbox first.
- "Internal" means any domain or alias in the Plesk DB, even if its mail service is disabled or points to an external mail server.
- Not real-time (runs hourly), catch-all addresses and Sieve rules in Roundcube are not covered.
- Removing targets is silent for the customer. You may want to inform them.
- Not verified: that "del:" matches case-insensitively (the script lowercases targets). Test with a forwarding target containing uppercase letters.

Combined with moving spam to the Spam folder instead of only marking it (see #10/#12), this should cover most of the reputation problem. If someone tests it, please report back.

Regards
Tessa
 
Last edited:
Back
Top