Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


Postifx Spam Solution/Problem

Posted on 2006-11-25
Medium Priority
Last Modified: 2010-03-18
A former employee of my company developed a spam filtering solution with Postifx/spamassassin for our clients who chose to host their email on their own server. The solution, as best as I can understand it, works like this:

Postifx pipes incoming messages to a script called "spamfilter" which lies in /usr/local/bin/. This script sends the message to spamc for spam checks. Once this is done, it checks the number of *'s are in the header section marked "X-Spam-Level:" and uses that to determine if the message is then delievered or if it is routed to another email address.

As of now, the mail is being checked, spam is being correctly flagged, but instead of routing to an alternate email address, it is still being delivered to the users mailbox (with a clearly mared "*******SPAM*******" in the subject line). I need to know as soon as possible how to remedy this as my clients are now getting a lot of spam.

Here is the script:

# Variables
SENDMAIL="/usr/sbin/sendmail.postfix -i"

# Directory to put high score spam into:
# (NOTE: Create this directory and give it same permissions as /var/tempfs)

# Exit codes from <sysexits.h>


# Number of *'s in X-Spam-level header needed to sideline message:
# (Eg. Score of 5.5 = "*****" )


# Clean up when done or when aborting.

trap "rm -f /var/tempfs/out.$$" 0 1 2 3 15

# Pipe message to spamc

cat | /usr/bin/spamc -u spamfilter > /var/tempfs/out.$$

if $EGREP -q "^X-Spam-Level: \*{$SPAMLIMIT,}" < /var/tempfs/out.$$


      # Option 1: Move high scoring messages to sideline dir so a human can look at them later:
      #cp /var/tempfs/out.$$ $SIDELINE_DIR/`date +%Y-%m-%d_%R`-$$

      # Option 2: Change the Email address where you want your spam to get fwd to
         $SENDMAIL spambox@example.com < /var/tempfs/out.$$

     $SENDMAIL "$@" < /var/tempfs/out.$$

# Postfix returns the exit status of the Postfix sendmail command.

exit $?

Here is my master.cf file from Postfix. I put comments on the lines which are important:

# ==========================================================================
# service type  private unpriv  chroot  wakeup  maxproc command + args
#               (yes)   (yes)   (yes)   (never) (100)
# ==========================================================================
smtp      inet  n       -       n       -       -       smtpd
 -o content_filter=spamfilter:dummy                    #<----------IMPORTANT
 -o smtpd_sasl_auth_enable=yes
#smtps    inet  n       -       n       -       -       smtpd
#  -o smtpd_tls_wrappermode=yes -o smtpd_sasl_auth_enable=yes
#submission   inet    n       -       n       -       -       smtpd
#  -o smtpd_enforce_tls=yes -o smtpd_sasl_auth_enable=yes -o smtpd_etrn_restrictions=reject
#628      inet  n       -       n       -       -       qmqpd
pickup    fifo  n       -       n       60      1       pickup
cleanup   unix  n       -       n       -       0       cleanup
qmgr      fifo  n       -       n       300     1       qmgr
#qmgr     fifo  n       -       n       300     1       oqmgr
#tlsmgr   fifo  -       -       n       300     1       tlsmgr
rewrite   unix  -       -       n       -       -       trivial-rewrite
bounce    unix  -       -       n       -       0       bounce
defer     unix  -       -       n       -       0       bounce
trace     unix  -       -       n       -       0       bounce
verify    unix  -       -       n       -       1       verify
flush     unix  n       -       n       1000?   0       flush
proxymap  unix  -       -       n       -       -       proxymap
smtp      unix  -       -       n       -       -       smtp
relay     unix  -       -       n       -       -       smtp
#       -o smtp_helo_timeout=5 -o smtp_connect_timeout=5
showq     unix  n       -       n       -       -       showq
error     unix  -       -       n       -       -       error
local     unix  -       n       n       -       -       local
virtual   unix  -       n       n       -       -       virtual
lmtp      unix  -       -       n       -       -       lmtp
anvil     unix  -       -       n       -       1       anvil
# Interfaces to non-Postfix software. Be sure to examine the manual
# pages of the non-Postfix software to find out what options it wants.
# maildrop. See the Postfix MAILDROP_README file for details.
maildrop  unix  -       n       n       -       -       pipe
  flags=DRhu user=vmail argv=/usr/local/bin/maildrop -d ${recipient}
# The Cyrus deliver program has changed incompatibly, multiple times.
old-cyrus unix  -       n       n       -       -       pipe
  flags=R user=cyrus argv=/cyrus/bin/deliver -e -m ${extension} ${user}
# Cyrus 2.1.5 (Amos Gouaux)
# Also specify in main.cf: cyrus_destination_recipient_limit=1
cyrus     unix  -       n       n       -       -       pipe
  user=cyrus argv=/cyrus/bin/deliver -e -r ${sender} -m ${extension} ${user}
uucp      unix  -       n       n       -       -       pipe
  flags=Fqhu user=uucp argv=uux -r -n -z -a$sender - $nexthop!rmail ($recipient)
ifmail    unix  -       n       n       -       -       pipe
  flags=F user=ftn argv=/usr/lib/ifmail/ifmail -r $nexthop ($recipient)
bsmtp     unix  -       n       n       -       -       pipe
  flags=Fq. user=foo argv=/usr/local/sbin/bsmtp -f $sender $nexthop $recipient
spamfilter unix - n n - - pipe                                                                                             #<----------IMPORTANT
        flags=Rq user=spamfilter argv=/usr/local/bin/spamfilter -f ${sender} -- ${recipient}   #<----------IMPORTANT
Question by:medium_grade
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 14

Accepted Solution

pablouruguay earned 1000 total points
ID: 18018333
is think you have the wrong solution in here, because the spammers change all every day.. and this script will be out of date nearly.

dont reinvent the weel, install spamassassin and milter-grey-list  and solve your problems...
LVL 40

Assisted Solution

noci earned 1000 total points
ID: 18020015
Or insert amavisd-new into the mail reception train.
It will also handle virus checking.

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have seen several blogs and forum entries elsewhere state that because NTFS volumes do not support linux ownership or permissions, they cannot be used for anonymous ftp upload through the vsftpd program.   IT can be done and here's how to get i…
Note: for this to work properly you need to use a Cross-Over network cable. 1. Connect both servers S1 and S2 on the second network slots respectively. Note that you can use the 1st slots but usually these would be occupied by the Service Provide…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question