<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xml:base="http://www.townx.org" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
 <title>townx - Simple Spamassassin setup with Postfix and Dovecot on Ubuntu Breezy - Comments</title>
 <link>http://www.townx.org/blog/elliot/simple_spamassassin_setup_with_postfix_and_dovecot_on_ubuntu_breezy</link>
 <description>Comments for &quot;Simple Spamassassin setup with Postfix and Dovecot on Ubuntu Breezy&quot;</description>
 <language>en</language>
<item>
 <title>&gt; apt-get install</title>
 <link>http://www.townx.org/blog/elliot/simple_spamassassin_setup_with_postfix_and_dovecot_on_ubuntu_breezy#comment-41619</link>
 <description>&lt;p&gt;&amp;gt; apt-get install spamassassin spamc&lt;br /&gt;
Seems like a misprint.&lt;/p&gt;</description>
 <pubDate>Fri, 04 Nov 2011 16:20:00 -0500</pubDate>
 <dc:creator>Guest</dc:creator>
 <guid isPermaLink="false">comment 41619 at http://www.townx.org</guid>
</item>
<item>
 <title>Crikey, I haven&#039;t got a clue</title>
 <link>http://www.townx.org/blog/elliot/simple_spamassassin_setup_with_postfix_and_dovecot_on_ubuntu_breezy#comment-41589</link>
 <description>&lt;p&gt;Crikey, I haven&#039;t got a clue I&#039;m afraid. It&#039;s been a long time since I did this. Apologies for not being able to help.&lt;/p&gt;</description>
 <pubDate>Wed, 19 Oct 2011 09:54:00 -0500</pubDate>
 <dc:creator>elliot</dc:creator>
 <guid isPermaLink="false">comment 41589 at http://www.townx.org</guid>
</item>
<item>
 <title>Help! i cannot start spamassassin</title>
 <link>http://www.townx.org/blog/elliot/simple_spamassassin_setup_with_postfix_and_dovecot_on_ubuntu_breezy#comment-41572</link>
 <description>&lt;p&gt;I tried to follow but i got this error instead. I cannot start the spam assassin&lt;/p&gt;

&lt;p&gt;Error as follow:&lt;/p&gt;

&lt;p&gt;warn: archive-iterator: no access to start: 2 at /usr/share/perl5/Mail/SpamAssassin/ArchiveIterator.pm line 771.&lt;/p&gt;

&lt;p&gt;Please help..&lt;/p&gt;</description>
 <pubDate>Thu, 06 Oct 2011 03:59:05 -0500</pubDate>
 <dc:creator>Serene</dc:creator>
 <guid isPermaLink="false">comment 41572 at http://www.townx.org</guid>
</item>
<item>
 <title>Thanks!</title>
 <link>http://www.townx.org/blog/elliot/simple_spamassassin_setup_with_postfix_and_dovecot_on_ubuntu_breezy#comment-41459</link>
 <description>&lt;p&gt;Very helpful indeed.&lt;/p&gt;</description>
 <pubDate>Sun, 07 Aug 2011 18:27:24 -0500</pubDate>
 <dc:creator>richard</dc:creator>
 <guid isPermaLink="false">comment 41459 at http://www.townx.org</guid>
</item>
<item>
 <title>Very useful</title>
 <link>http://www.townx.org/blog/elliot/simple_spamassassin_setup_with_postfix_and_dovecot_on_ubuntu_breezy#comment-41440</link>
 <description>&lt;p&gt;Thank you for this detailed guide, it works perfect in my Ubuntu Server 11.04.&lt;br /&gt;
Best regards!&lt;/p&gt;</description>
 <pubDate>Fri, 22 Jul 2011 16:31:48 -0500</pubDate>
 <dc:creator>Fer</dc:creator>
 <guid isPermaLink="false">comment 41440 at http://www.townx.org</guid>
</item>
<item>
 <title>Apologies, I intended my</title>
 <link>http://www.townx.org/blog/elliot/simple_spamassassin_setup_with_postfix_and_dovecot_on_ubuntu_breezy#comment-41437</link>
 <description>&lt;p&gt;Apologies, I intended my response in a light-hearted fashion. Should have done a smiley probably. :)&lt;/p&gt;</description>
 <pubDate>Tue, 19 Jul 2011 04:07:45 -0500</pubDate>
 <dc:creator>elliot</dc:creator>
 <guid isPermaLink="false">comment 41437 at http://www.townx.org</guid>
</item>
<item>
 <title>Huh?</title>
 <link>http://www.townx.org/blog/elliot/simple_spamassassin_setup_with_postfix_and_dovecot_on_ubuntu_breezy#comment-41392</link>
 <description>&lt;p&gt;After writing &quot;There are probably spam corpuses (corpi?) you can use for this&quot;, you didn&#039;t expect anyone to comment with the correct form? Personally I couldn&#039;t care less which form people use, but it seemed like you actually wanted to know. Sorry if I offended you, that wasn&#039;t the intention.&lt;/p&gt;</description>
 <pubDate>Mon, 20 Jun 2011 17:32:56 -0500</pubDate>
 <dc:creator>Madsen</dc:creator>
 <guid isPermaLink="false">comment 41392 at http://www.townx.org</guid>
</item>
<item>
 <title>there&#039;s always one...</title>
 <link>http://www.townx.org/blog/elliot/simple_spamassassin_setup_with_postfix_and_dovecot_on_ubuntu_breezy#comment-40839</link>
 <description>&lt;p&gt;there&#039;s always one...&lt;/p&gt;</description>
 <pubDate>Thu, 29 Jul 2010 08:58:41 -0500</pubDate>
 <dc:creator>elliot</dc:creator>
 <guid isPermaLink="false">comment 40839 at http://www.townx.org</guid>
</item>
<item>
 <title>The plural of &#039;corpus&#039; ...</title>
 <link>http://www.townx.org/blog/elliot/simple_spamassassin_setup_with_postfix_and_dovecot_on_ubuntu_breezy#comment-40827</link>
 <description>&lt;p&gt;Is &#039;corpora&#039;. And thanks for the lil&#039; how-to. :)&lt;/p&gt;</description>
 <pubDate>Wed, 28 Jul 2010 04:25:21 -0500</pubDate>
 <dc:creator>Madsen</dc:creator>
 <guid isPermaLink="false">comment 40827 at http://www.townx.org</guid>
</item>
<item>
 <title>To be on the safe side, I&#039;d</title>
 <link>http://www.townx.org/blog/elliot/simple_spamassassin_setup_with_postfix_and_dovecot_on_ubuntu_breezy#comment-40679</link>
 <description>&lt;p&gt;To be on the safe side, I&#039;d probably copy the mail from that directory somewhere else, and train on the copy.&lt;/p&gt;</description>
 <pubDate>Sat, 29 May 2010 06:44:39 -0500</pubDate>
 <dc:creator>elliot</dc:creator>
 <guid isPermaLink="false">comment 40679 at http://www.townx.org</guid>
</item>
<item>
 <title>Training question</title>
 <link>http://www.townx.org/blog/elliot/simple_spamassassin_setup_with_postfix_and_dovecot_on_ubuntu_breezy#comment-40615</link>
 <description>&lt;p&gt;Im also using Maidir format.  But my setup differentiated from yours slightly.  It looks like the root of my Maildir/ directory IS my inbox.  That is to say I have no Maildir/.Inbox directory.  The Maildir/ directory does however have the rest  of the imap &quot;folders&quot; in it... Maildir/.Spam ,  Maildir/Trash for example.&lt;/p&gt;

&lt;p&gt;My question is, would running:   &lt;br /&gt;
&lt;code&gt;sudo sa-learn --ham -u spamd --dir Maildir/* -D&lt;/code&gt;&lt;br /&gt;
also inadvertently drill into those .Spam, .Trash folders and improperly learn their contents as Ham?  Im guessing not, but I don&#039;t know whats under the hood of sa-learn to be sure.&lt;/p&gt;

&lt;p&gt;Thanks, John&lt;/p&gt;</description>
 <pubDate>Wed, 19 May 2010 07:12:50 -0500</pubDate>
 <dc:creator>John</dc:creator>
 <guid isPermaLink="false">comment 40615 at http://www.townx.org</guid>
</item>
<item>
 <title>I&#039;m pretty sure you&#039;re</title>
 <link>http://www.townx.org/blog/elliot/simple_spamassassin_setup_with_postfix_and_dovecot_on_ubuntu_breezy#comment-40539</link>
 <description>&lt;p&gt;I&#039;m pretty sure you&#039;re right: a bad choice of wording by me. I think at the time I wrote this I realised what was happening with the headers and Thunderbird, and that SpamAssassin wasn&#039;t actually dropping anything. I just didn&#039;t express it very well.&lt;/p&gt;</description>
 <pubDate>Fri, 23 Apr 2010 17:30:49 -0500</pubDate>
 <dc:creator>elliot</dc:creator>
 <guid isPermaLink="false">comment 40539 at http://www.townx.org</guid>
</item>
<item>
 <title>Glad it helped.</title>
 <link>http://www.townx.org/blog/elliot/simple_spamassassin_setup_with_postfix_and_dovecot_on_ubuntu_breezy#comment-40538</link>
 <description>&lt;p&gt;Glad it helped.&lt;/p&gt;</description>
 <pubDate>Fri, 23 Apr 2010 17:29:02 -0500</pubDate>
 <dc:creator>elliot</dc:creator>
 <guid isPermaLink="false">comment 40538 at http://www.townx.org</guid>
</item>
<item>
 <title>Thanks</title>
 <link>http://www.townx.org/blog/elliot/simple_spamassassin_setup_with_postfix_and_dovecot_on_ubuntu_breezy#comment-40510</link>
 <description>&lt;p&gt;Thanks for this, the magic Postfix config lines made it all work!&lt;/p&gt;</description>
 <pubDate>Mon, 12 Apr 2010 10:14:09 -0500</pubDate>
 <dc:creator>Andrew France</dc:creator>
 <guid isPermaLink="false">comment 40510 at http://www.townx.org</guid>
</item>
<item>
 <title>thanks</title>
 <link>http://www.townx.org/blog/elliot/simple_spamassassin_setup_with_postfix_and_dovecot_on_ubuntu_breezy#comment-40424</link>
 <description>&lt;p&gt;Just thanking you for the time you contributed to this article&lt;/p&gt;</description>
 <pubDate>Thu, 11 Mar 2010 05:17:22 -0600</pubDate>
 <dc:creator>dime</dc:creator>
 <guid isPermaLink="false">comment 40424 at http://www.townx.org</guid>
</item>
<item>
 <title>Simple Spamassassin setup with Postfix and Dovecot on Ubuntu Breezy</title>
 <link>http://www.townx.org/blog/elliot/simple_spamassassin_setup_with_postfix_and_dovecot_on_ubuntu_breezy</link>
 <description>&lt;p&gt;Below is a simple Spamassassin setup for use with Postfix; I also cover how to train Spamassassin on a Maildir mail box (I use Dovecot).&lt;/p&gt;

&lt;p&gt;Some of the below is cribbed from &lt;a href=&quot;http://www.debuntu.org/postfix-and-pamassassin-how-to-filter-spam&quot; title=&quot;http://www.debuntu.org/postfix-and-pamassassin-how-to-filter-spam&quot;&gt;http://www.debuntu.org/postfix-and-pamassassin-how-to-filter-spam&lt;/a&gt;. I&#039;ve simplified it and left more of the configuration at the defaults. You don&#039;t have to do this on a locally-hosted Postfix server: the instructions are the same for any email server which can receive email (it just so happens mine isn&#039;t open to the outside world and is just passed email by fetchmail). I&#039;m working on Ubuntu Breezy.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Disclaimer:&lt;/strong&gt; Use these instructions at your own risk. I am not an expert on spam filtering: this set of instructions just gave me what I needed to do my own local spam filtering. If you set it up and it loses you the email clinching a one million dollar contract, I assume no responsibility.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;By the way, you need to do all of the below as root.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;Install Spamassassin&lt;/h2&gt;



&lt;pre&gt;
apt-get install spamassassin spamc
&lt;/pre&gt;



&lt;h2&gt;Configure Spamassassin user and group&lt;/h2&gt;

&lt;p&gt;We want it to run as non-root, so add a &lt;strong&gt;spamd&lt;/strong&gt; user and group:&lt;/p&gt;



&lt;pre&gt;
# groupadd spamd
# useradd -g spamd -s /bin/false -d /var/log/spamassassin spamd
# mkdir /var/log/spamassassin
# chown spamd:spamd /var/log/spamassassin
&lt;/pre&gt;



&lt;p&gt;(This sets the spamd user&#039;s home directory as /var/log/spamassassin.)&lt;/p&gt;

&lt;h2&gt;Configure Spamassassin&lt;/h2&gt;

&lt;p&gt;Edit /etc/default/spamassassin so these options are set:&lt;/p&gt;



&lt;pre&gt;
ENABLED=1

SAHOME=&amp;quot;/var/log/spamassassin/&amp;quot;

OPTIONS=&amp;quot;--create-prefs --max-children 2 --username spamd \
-H ${SAHOME} -s ${SAHOME}spamd.log&amp;quot;
&lt;/pre&gt;



&lt;p&gt;--max-children spawns the specified number of child processes (you might need more on a busy server), --username specifies the username spamd runs under, -H sets the home directory, -s sets the log file.&lt;/p&gt;

&lt;p&gt;(I left the rest of the file alone, and didn&#039;t touch /etc/spamassassin/local.cf.)&lt;/p&gt;

&lt;h2&gt;Start the Spamassassin daemon (spamd)&lt;/h2&gt;



&lt;pre&gt;
/etc/init.d/spamassassin start
&lt;/pre&gt;



&lt;p&gt;(By default, spamassassin gets added to the startup scripts by Ubuntu, so it will start/stop with your system.)&lt;/p&gt;

&lt;h2&gt;Configure Postfix to use Spamassassin as a filter&lt;/h2&gt;

&lt;p&gt;This makes Postfix pipe email to Spamassassin once it&#039;s been received. Edit /etc/postfix/master.cf and add this line as the first line of the file:&lt;/p&gt;



&lt;pre&gt;
smtp      inet  n       -       -       -       -       smtpd
        -o content_filter=spamassassin
&lt;/pre&gt;



&lt;p&gt;Add this to the end of the same file:&lt;/p&gt;



&lt;pre&gt;
spamassassin unix -     n       n       -       -       pipe
        user=spamd argv=/usr/bin/spamc -f -e  
        /usr/sbin/sendmail -oi -f ${sender} ${recipient}
&lt;/pre&gt;



&lt;p&gt;I bet you&#039;re asking yourself &quot;What the hell?!&quot;. I know I was. As far as I can tell, this sets up an &lt;a href=&quot;http://www.postfix.org/FILTER_README.html&quot;&gt;after-queue content filter&lt;/a&gt;, and this config. does the following:&lt;/p&gt;


&lt;ol&gt;
&lt;li&gt;Sets up a content filter called &lt;em&gt;spamassassin&lt;/em&gt; with type &lt;em&gt;unix&lt;/em&gt; (i.e. listening on a Unix socket).&lt;/li&gt;
&lt;li&gt;&quot;- n n - -&quot; means the filter is private, privileged (any pipe daemon needs privileges), not chrooted (pipe daemons can&#039;t be chrooted), has no wakeup set, and uses the default for maximum processes spawned, respectively.&lt;/li&gt;
&lt;li&gt;&lt;em&gt;pipe&lt;/em&gt; sets the filter up using the pipe daemon: stuff gets passed into it by Postfix, then it either returns what was passed in, possibly changed (e.g. with headers added or the body sanitised), or a code indicating what the filter did.&lt;/li&gt;
&lt;li&gt;&lt;em&gt;userd&lt;/em&gt; specifies the user to run the filter as.&lt;/li&gt;
&lt;li&gt;&lt;em&gt;argv&lt;/em&gt; sets the command for the pipe daemon to run over messages (i.e. this is the actual filter command). In this case, the command is:&lt;br /&gt;
&lt;code&gt;/usr/bin/spamc -f -e /usr/sbin/sendmail -oi -f ${sender} ${recipient}&lt;/code&gt;&lt;br /&gt;
This runs spamc (the Spamassassin client program), piping its output into the sendmail command; spamc passes the email being filtered to the Spamassassin daemon (spamd) which is running in the background; spamc gets the email back with a few spam headers to show the email has been checked, and possibly with its content rewritten to show the standard Spamassassin &quot;Spam detection software, running on the system &#039;briar&#039;, has identified this incoming email as possible spam&quot; if the email is spam. The ${sender} and ${recipient} markers are interpolated by Postfix, so that sendmail can take the output from spamc and deliver the message with the correct from and to addresses.&lt;/li&gt;
&lt;/ol&gt;



&lt;p&gt;Reload Postfix for the configuration to take:&lt;/p&gt;



&lt;pre&gt;
/etc/init.d/postfix reload
&lt;/pre&gt;



&lt;h2&gt;Train the Spamassassin filter&lt;/h2&gt;

&lt;p&gt;This was the bit where I had to do the most research. I&#039;m using Maildir format for my email, under dovecot; email for localhost accounts goes in /home/user/Maildir.&lt;/p&gt;

&lt;p&gt;To do my training, I created a new Junk folder for my localhost Postfix account: I did this by adding the folder via Thunderbird. Next I got a load of existing spam from my Trash folder, and moved it to the Junk folder.&lt;/p&gt;

&lt;p&gt;Then, to train the filter on the Junk folder, I used sa-learn like this (you need to be root, which is why the sudo is there):&lt;/p&gt;



&lt;pre&gt;
sudo sa-learn --spam -u spamd --dir /home/ell/Maildir/.Junk/* -D
&lt;/pre&gt;



&lt;p&gt;You can also train it what the good stuff looks like, e.g. run it over a clean inbox (no spam):&lt;/p&gt;



&lt;pre&gt;
sudo sa-learn --ham -u spamd --dir /home/ell/Maildir/.INBOX/* -D
&lt;/pre&gt;



&lt;p&gt;There are probably spam corpuses (corpi?) you can use for this or some other smart method I missed, but this seems to work.&lt;/p&gt;

&lt;h2&gt;Testing&lt;/h2&gt;

&lt;p&gt;Get the content out of an existing spam, send it to an account on your protected server from a free email account (you could even set up a Hotmail account to get the most accurate spam scenario), and see if Spamassassin marks it. Check the logs (/var/log/spamassassin and /var/log/mail.log) to see what happened to the email. If Postfix is using Spamassassin properly, you should see something like this in the logs:&lt;/p&gt;



&lt;pre&gt;
Jan 26 14:56:10 localhost postfix/pipe[12139]: 9CBD5DA4BF: \
to=&amp;lt;ell@localhost&amp;gt;, relay=spamassassin, delay=17, status=sent (localhost)
&lt;/pre&gt;



&lt;p&gt;(Notice the mention of postfix/pipe.)&lt;/p&gt;

&lt;p&gt;Spamassassin might not mark the email, as it will be coming from a legitimate email address. The important thing is that the logs report that Spamassassin was applied.&lt;/p&gt;

&lt;h2&gt;Results&lt;/h2&gt;

&lt;p&gt;I now get very little spam delivered to my inbox: most of it gets marked as spam by the Postfix server using Spamassassin, and Thunderbird deletes any emails with a SpamAssassin spam header for me. I periodically train the filter to make it improve, using the stuff Thunderbird has decided is junk.&lt;/p&gt;

&lt;h2&gt;Why?&lt;/h2&gt;

&lt;p&gt;Originally, this was at the top of this post, but it&#039;s kind of irrelevant. I&#039;ve included it here so you know why I put myself through this lunacy.&lt;/p&gt;

&lt;p&gt;I have a couple of legacy email accounts which still get the occasional proper email, plus endless spam. I use the excellent fetchmail to download email from these moribund accounts and send it to my local Postfix server instead. I then read my local email account via the Dovecot imap server (setup to use Maildir layouts) in the Thunderbird email client. A fairly complex setup, but one which has worked well for me over the past three or four years.&lt;/p&gt;

&lt;p&gt;However, a vast amount of spam used to hit my old email accounts, and I&#039;d have to wait for Thunderbird to sort it out (which it does well) once fetchmail passed it to the local Postfix server. I got tired of having to teach the Thunderbird junk controls, so decided instead to setup my local Postfix server with Spamassassin: the stuff that fetchmail then pulls down and sends to my local Postfix server goes through Spamassassin before it hits Thunderbird. As you can tell Thunderbird to trust Spamassassin &lt;span class=&quot;caps&quot;&gt;SPAM &lt;/span&gt;headers, it will automatically delete anything which Spamassassin has already decided is spam. Which means I don&#039;t have to teach Thunderbird, and can just teach Spamassassin instead (which is an automatic process), and let it learn by itself too as it finds more spam.&lt;/p&gt;</description>
 <comments>http://www.townx.org/blog/elliot/simple_spamassassin_setup_with_postfix_and_dovecot_on_ubuntu_breezy#comments</comments>
 <category domain="http://www.townx.org/tech">tech</category>
 <category domain="http://www.townx.org/howtos">howtos</category>
 <pubDate>Fri, 26 Jan 2007 09:00:05 -0600</pubDate>
 <dc:creator>elliot</dc:creator>
 <guid isPermaLink="false">530 at http://www.townx.org</guid>
</item>
</channel>
</rss>

