# Mail server with spam filtering how?

## drakonite

I am new to mail systems in linux. 

My goal is to be able to use squirrelmail (or something similar) to allow me to check mail using a web interface, and have the gotmail script (or something similar) being used to download mail from my hotmail account and forward it to the mail server on my local system, and have spam be removed.

Right now I have gotmail working and it forwards mail on to my system, and Squirrelmail is up and running.  But I can't get any spam filitering to work, and anytime I try to figure out how to set up and use any mail programs such as procmail, I am so quickly lost it isn't even funny.

How would I go about setting up my system to handle mail like that? I would like to also have mail filtered into different folders if possible (like hotmail and yahoo mail do) and I assume thats possible.. 

I'm about to rebuild my system from scratch so what I am using now doesn't matter as it won't be there for long...

Any tips, ideas, good links, good places to start, or complete walkthroughs  :Wink:  that I could use?

----------

## mooman

I'm building the same thing right now.

I'm using getmail to pull the email from my pop accounts

I'm using procmail to call the filtering code

I'm using courier for the mailboxes/webmail

The process is:

Pop account  :Arrow:  getmail  :Arrow:  | procmail  :Arrow:  maildir  :Arrow:  courier  :Arrow:  mail proggie

I'm almost at the point of adding the filtering in too.  I wanted to get the flow working from start to finish before adding the filtering part.  (Easier to troubleshoot the simple case before the complex one, I figure)

For spam filtering, I'd suggest starting with a canned package like spamassassin or razor before I'd add any procmail "recipes" into the mix.  Spamassassin is particularly popular so you'll find lots of examples of it around the net.  I think it actually includes razor's functionality so you might even get two for one there..

Both are available as ebuilds.(razor in net-mail, spamassassin in dev-perl)

And yes, promail can filter into different folders... It's very configurable.

Let me know how it goes.. I might bump into the same stumblers as you..  :Smile: 

----------

## drakonite

I had that general pattern down before... Unfortunatly I know nothing about setting up mail in linux. 

When I tried before I thought I halfway understood what it was saying to do to get spamassasin working... but it never did (its still installed on my current setup but has no effect)

Maybe I'm just being an idiot, but I can't seem to find any resources that help you get started setting it up when you don't know anything about it.

----------

## fyerk

I use a combination of Sendmail, MIMEDefang, and SpamAssassin for email filtering both privately and for work.  I've found that it scales fairly well, and does a good job of blocking nasty emails.  Along with MIMEDefang, I use Sophos Antivirus for virus scanning, but there are several other free solutions that are available as well.

Sendmail: http://www.sendmail.org

Sendmail is available in Portage, so a simple emerge is all you need to install it.

```

# emerge sendmail

```

You'll need to make sure that Milter support is enabled for MIMEDefang to work properly, so add a line like the following to your /etc/mail/sendmail.mc file.

```

INPUT_MAIL_FILTER(`mimedefang', `S=unix:/var/spool/MIMEDefang/mimedefang.sock, F=T, T=S:1m;R:1m;E:5m')

```

For other options in your sendmail.mc consult the reference guide at the URL above (or ask here  :Razz: )

SpamAssassin: http://www.spamassassin.org

SpamAssassin is a Perl module, but it's also available in Portage. You can install it either way.

The Portage way: 

```
 # emerge Mail-SpamAssassin
```

The CPAN way: 

```

# perl -MCPAN -e shell

cpan> install Mail::SpamAssassin

```

Both methods should install the necessary dependancies.

MIMEDefang: http://www.roaringpenguin.com/mimedefang

Unfortunately MIMEDefang is not yet installed in Portage, so you'll need to install it manually. Luckily, it's not that difficult.

Download the tarball from the above URL and extract it. If you want to use virus scanning, you'll need to install it first. MIMEDefang supports most of the major ones out of the box and detects them at configure.

```

% tar -xzvf mimedefang-2.26.tar.gz

% cd mimedefang-2.26

% ./configure

```

After configure has been run, you should see a report of what MIMEDefang will support (virus scanning, html cleaning, SpamAssassin, etc.). If it did not find something that you want available, you'll need to fix that. Usually it's just a path issue.

Create the defang user and compile and install MIMEDefang as root

```

# useradd defang

# make && make install

```

The last step is to configure the /etc/mail/mimedefang-filter file. It's pretty well documented, so read it carefully and configure as necessary.

Make sure you read the documentation provided with MIMEDefang before installing it as it's got some extra things you'll need to add to the Sendmail startup options (such as a client-queue runner). 

If you have questions after reading that though, please feel free to post them.

----------

## oddity

After hours of problems to get procmail to filter mail through getmail i have this solution, in getmailrc, be sure you have the path to your .procmailrc when you run procmail, otherwise procmail wont find it?

postmaster = "|/usr/bin/procmail /home/username/.procmailrc"

The error message i got when i didnt have the path to my .procmailrc was:

username@host username $ getmail -g ~/.maildir/

  Delivery error (command "/usr/bin/procmail" exited 0 but wrote to stderr (procmail: Suspicious rcfile "/home/username/.procmailrc"

procmail: Couldn't read "/home/username/.procmailrc"))

Resetting connection and aborting (Delivery error (command "/usr/bin/procmail" exited 0 but wrote to stderr (procmail: Suspicious rcfile "/home/username/.procmailrc"

procmail: Couldn't read "/home/username/.procmailrc")))

One funny thing was that when i used /etc/procmailrc it worked fine, BUT, all mail got owned by root (root:root).. Why? The command wasnt executed by root from the beginning..

Hope this will help someone..

Greetings from northern Sweden, its cold as HELL! :D (-25 degres celsius).

/oddity

----------

## col

If you use sendmail this works well. I have not received a single spam since adding it. They are all free spammer databases.

Add it to your sendmail.mc , rehash & restart sendmail. 

```

FEATURE(blacklist_recipients)dnl

FEATURE(`dnsbl', `relays.ordb.org', `"550 Mail from " $&{client_addr} " rejected - see http://www.ordb.org/faq/"')dnl

FEATURE(`dnsbl', `bl.spamcop.net', `"550 Mail from " $&{client_addr} " rejected - see http://spamcop.net/bl.shtml?"$&{client_addr}')dnl

FEATURE(`dnsbl', `relays.osirusoft.com', `"550 Mail from " $&{client_addr} " rejected - see http://relays.osirusoft.com')dnl

FEATURE(`dnsbl', `proxy.relays.monkeys.com',  `"550 Mail from " $&{client_addr} " rejected')dnl

FEATURE(`delay_checks')dnl

```

----------

