Scan Email for Spam Before Forwarding

I have a requirement from a customer to scan email for spam before its forwarded to an external email address, and delete the spam.

I’ve tried using a standard forward email to in Virtualmin but its not being scanned before being forwarded (I can tell from the headers).

How would I set it up, on a single domain, to scan and delete spam before forwarding email?



would you not do this in VM-server configuration-Spam and Virus Delivery?

Delivery destinations
Destination for spam emails Throw away!
[size=2]Deliver normally
Write to standard spam file ~/mail/spam
Write to standard spam Maildir ~/Maildir/.spam/
Write to mail file under home directory
Forward to email address
Write to other file[/size]

I think I may have found my own solution.

I’ve enabled users own .procmailrc files:
VirtualMin (left hand menu) -> List Virtual Servers -> Configuration Category (drop-down) -> Spam Filtering Options -> Allow mailbox users to configure procmail : YES

and then set up a .procmailrc file in a users directory:
and in this file entered a simple forwarding rule:

:0 c

This has the desired effect since all email that’s forwarded to the forwarding address has been fully scanned for spam and viruses, as can be seen by the various email headers at the destination server:

X-Spam-Checker-Version: SpamAssassin 3.1.7 (2006-10-05)
X-Spam-Status: No, score=0.5 required=5.0 tests=DNS_FROM_RFC_ABUSE
autolearn=no version=3.1.7

Additionally if the original message was very spammy, it got deleted and not forwarded.

This seems to be the solution since procmailrc is the last thing carried out in the email delivery chain, after spam filtering, and just before the email is dropped into the users inbox folder.

I found that simply using the in-built “Forward to other addresses” in the user’s “Mail forwarding Settings” config forwarded the email early in the chain, before any spam filtering or spam deletion, and hence every message, including spam, was forwarded.

If anyone knows of a better solution, or any reasons why I shouldn’t do this, please let me know.