Home » Configs » Fetchmail and Procmail with Spamassassin and ClamAV

Fetchmail and Procmail with Spamassassin and ClamAV

I need to pull mail from my internet hosting provider into my internal IMAP server. This formula requires an IMAP server (in my case Dovecot), and running fetchmail (to get the mail from the hosting server), procmail (to move the process the mail, then get it to the proper Maildir). Procmail will also need to have Spamassassin, ClamAV and Clamassassin installed.

Fetchmail and Procmail with Spamassassin and ClamAV

Need to pull email from my hosting server to my internal IMAP server for archival.

This formula requires an IMAP server (in my case Dovecot), and running fetchmail (to get the mail from the hosting server), procmail (to move and process the mail, then get it into my IMAP Maildir). Procmail will also need to have Spamassassin, ClamAV and Clamassassin installed to remove the icky email SPAM and Malware!

BASH
# sudo apt-get install fetchmail procmail spamassassin clamav clamassassin

Configure Fetchmail

/home/john/.fetchmailrc

BASH
poll mail.server.com
protocol pop3
timeout 300
port 995
username john password P@$$w0rd
keep
ssl
sslcertck
sslproto TLS1
mda “/usr/bin/procmail -m ‘/home/john/.procmailrc'”

Procmail

/home/john/.procmailrc

BASH

LOGFILE=$HOME/.procmail.log
MAILDIR=/home/john/Maildir
DEFAULT=/home/john/Maildir/
VERBOSE=yes

:0

# Pipe the mail through spamassassin (replace ‘spamassassin’ with ‘spamc’
# if you use the spamc/spamd combination)
#
# The condition line ensures that only messages smaller than 250 kB
# (250 * 1024 = 256000 bytes) are processed by SpamAssassin. Most spam
# isn’t bigger than a few k and working with big messages can bring
# SpamAssassin to its knees.
#
# The lock file ensures that only 1 spamassassin invocation happens
# at 1 time, to keep the load down.
#
:0fw: spamassassin.lock
* < 256000
| /usr/bin/spamassassin

# Mails with a score of 15 or higher are almost certainly spam (with 0.05%
# false positives according to rules/STATISTICS.txt). Let’s put them in a
# different mbox. (This one is optional.)
:0:
* ^X-Spam-Level: \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
# almost-certainly-spam
/home/john/Maildir/.Junk/

 

# All mail tagged as spam (eg. with a score higher than the set threshold)
# is moved to “probably-spam”.
:0:
* ^X-Spam-Status: Yes
# probably-spam
/home/john/Maildir/.Junk/

# Work around procmail bug: any output on stderr will cause the “F” in “From”
# to be dropped. This will re-add it.
:0
* ^^rom[ ] {
LOG=”*** Dropped F off From_ header! Fixing up. ”

:0 fhw
| sed -e ‘1s/^/F/’
}

#####################
# Scan for Virusses #
#####################

########## clamassassin ##########
#

:0fw
| /usr/bin/clamassassin

:0:
* ^X-Virus-Status: Yes
/home/john/Maildir/.Malware/
# mail.virus

########## clamassassin ##########

Check email every 5 minutes

Modify your crontab (crontab -e)

BASH
# */5 * * * * /usr/bin/fetchmail &> /dev/null

Fine tuning Spam Detection

sa-learn –spam Path-TO-Junk-Folder #or location you store your spam for learning

sa-learn –ham Path-TO-Folder #or location you store your messages that are NOT SPAM, but get detected as SPAM incorrectly.

Was this helpful?
If you found my posts interesting, or I helped you figure something out, please consider tossing me a tiny gratuity for my time, research, to help offset the web hosting/development costs or to buy me a cup of coffee.

* This post may contain affiliate links. This means that I “might” receive a tiny amount of money, if you make a purchase using one of our links. It does not cost you anything extra, and helps us defray the costs of hosting and maintaining this site.

Leave a Reply