Sort [SPAM] mail into a Spam folder (Postfix, Dovecot & procmail)

Quickly wanted to stop mail tagged by spamassasin as [SPAM] being delivered into my inbox. I did this using procmail and the following was configured on a Centos 6 server.

Install procmail

yum install procmail

Next create a procmailrc file in the users home dir along (this can be done globally by adding this to /etc/procmailrc rather than a user home). We also create a procmail directory to keep logs in and change the owner and permissions.

 mkdir /home/myuser/.procmail
 touch /home/myuser/.procmailrc
 chmod 600 /home/myuser/.procmailrc
 chown -R myuser:myuser /home/myuser/procmail*

Now add the following to /home/myuser/.procmailrc

# Some custom procmail stuff :D
# Change to on for logging
# Location of things
# Use the following if you get "destination user parameter (-d user) not given":
# the directory that holds the mail!
:0 w
* ^X-Spam-Status: Yes
| $DELIVER -m Spam
:0 w

Next we change the mailbox_command in /etc/postfix/ to the following

mailbox_command = /usr/bin/procmail -a $DOMAIN

Restart postfix

service postfix restart

Now we finally test by sending some spam using the gtube template to our mailbox.

Subject: Test spam mail (GTUBE)
Message-ID: <>
Date: Wed, 23 Jul 2003 23:30:00 +0200
From: Sender <>
To: Recipient <>
Precedence: junk
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

This is the GTUBE, the
	Test for

If your spam filter supports it, the GTUBE provides a test by which you
can verify that the filter is installed correctly and is detecting incoming
spam. You can send yourself a test mail containing the following string of
characters (in upper case and with no white spaces and line breaks):


You should send this test mail from an account outside of your network.

If you tail the maillog file you should see something similar to the following ๐Ÿ™‚

Nov 30 06:54:16 dovecot: lda(m00nie): msgid=<>: saved mail to Spam

m00nie ๐Ÿ˜€

Leave a Reply