Installing and Configuring Spamassassin to work with Postfix SMTP server

spamassassin

Email spam, which is also know as junk email, are identical email messages sent to several email recipients. This could be emails sent by companies for marketing purposes, email sent bring user to phishing web sites, etc.

Usually these emails are sent using some scripts to a huge number of recipients.

Plain SMTP servers by default is not meant to analyze the emails and categorize them. They receive any email that comes it based on the basic checks. We make use of other applications such as spamassasins that filters spam mails based on content-matching rules

Follow the steps mentioned in my previous posts to install postfix

Install spamassassin, which is available ini common repositories

  • ]# yum install spamassassin

Edit the spamassasin’s configuration file as follows:

  • ]# vi /etc/mail/spamassassin/local.cf
  • required_hits 5.0
  • report_safe 0
  • required_score 5
  • rewrite_header Subject ***SPAM***

Add a new user to manage the spamd service

  • groupadd spamd
  • useradd -g spamd -s /bin/false -d /var/log/spamassassin spamd
  • chown spamd:spamd /var/log/spamassassin

Configure postfix configuration file

  • ]# vi /etc/postfix/master.cf

Find the line that starts with “smtp        inet” and edit it to looks as below:

  • # ====================================================================
  • # service type  private unpriv  chroot  wakeup  maxproc command + args
  • #                      (yes)   (yes)     (yes)    (never)   (100)
  • # ====================================================================
  • smtp        inet   n           --           n          --             --              smtpd -o content_filter=spamassassin

Add the following line at the end of master.cf

  • spamassassin unix -- n n -- -- pipe flags=R user=spamd argv=/usr/bin/spamc -e /usr/sbin/sendmail -oi -f ${sender} ${recipient}

Verify the following file:

  • cat /etc/sysconfig/spamassassin
  • Ensure that the -D flag is enabled in the vaariable SPAMDOPTIONS

Issue the following commands:

  • ]#  sa-update
  • ]# service spamassassin stop
  • ]# service spam assassin start

Add the following commands in a cron job to do it regularly

Restart the mail services

  • ]# service postfix restart
  • ]# service spamassassin restart

Test

Send a mail to user balbox with the below subject. This will be marked as spam:

XJS*C4JDBQADN1.NSBN3*2IDNEN*GTUBE-STANDARD-ANTI-UBE-TEST-EMAIL*C.34X

Be the first to comment on "Installing and Configuring Spamassassin to work with Postfix SMTP server"

Leave a comment