Home > Articles > Security > Network Security

  • Print
  • + Share This
This chapter is from the book

SpamAssassin Configuration Files

SpamAssassin can be run with the as-shipped configuration files, requiring little or no change. Due to the large number of configuration parameters available, only highlights of the configuration files are presented here. A complete description of all configuration parameters is contained in Appendix E. "SpamAssassin Configuration File." Figures 3.73.15 and 3.17 are based on information from http://spamassassin.apache.org .

Configuration File Locations

The SpamAssassin configuration files live by default in /usr/share/spamassassin and /etc/mail/spamassassin. Note that all files with a .cf extension are read in alphabetically at spamassassin startup time. The site-wide configuration is by convention called local.cf and should be placed in /etc/mail/spamassassin. You should not place configuration files in /usr/share/spamassassin, as those files may get deleted during future SpamAssassin upgrades.

The individual user configuration file is called user_prefs and is normally located in the user's home directory in the .spamassassin subdirectory. The ability for individual users to have their own user_prefs is a tunable parameter. Also, with the virtual support available within spamd, user preferences can be located in a variable location, depending upon the mail account's domain and/or username. This makes integration with large mail systems easier.

Configuration File Precedence

You need to be aware that the SpamAssassin rule processing is "last touched wins." In other words, the last setting is the one that is used. So, it is important to know that the files are processed in this order:

  1. SpamAssassin default rules directory, in alphabetic order (defaults to /usr/share/spamassassin)
  2. Local rules directory, in alphabetic order (by default /etc/mail/spamassassin)
  3. Local user_prefs file (user's home directory, in a directory called .spamassassin)

Configuration settings come in different classes. The three classifications of keywords are as follows:

  • Those that can be changed globally, by the user and/or system-wide (in other words, both user_prefs and local.cf)
  • Options that are changeable with permission of the SpamAssassin administrator (if allow_user_rules is enabled)
  • Settings that can only be changed by the SpamAssassin administrator in local.cf

    The following classes of users are allowed to manipulate the privileged commands:

  • The administrator via the system-wide /etc/mail/spamassassin file
  • Users running spamassassin from their procmailrc or forward files

spamd users are not allowed to change the privileged files unless the administrator has set allow_user_rules to 1.

Please consult Appendix E for a complete list and description of available configuration options for all three classes of keywords (global, administrator permitted, and administrator only).

Unprivileged or Global Keywords

Under the unprivileged class of configuration keywords available to anyone, the available options can be broken down as follows:


The scoring keywords define what is to be considered spam and the scores assigned by rules (see Figure 3.7).

Table 3.7. Scoring options.

required_score n.nn (default: 5)
score SYMBOLIC_TEST_NAME n.nn [ n.nn n.nn n.nn ]

The required_score defines what SpamAssassin considers to be spam. This value can be adjusted higher or lower, depending upon the point at which you want SpamAssassin to consider a message to be spam. If you feel SpamAssassin is being too aggressive and creating lots of false positives, adjust the score threshold upward. If it is too conservative, letting a lot of spam get through, adjust it downward.

Whitelist and Blacklist

The settings in Figure 3.8 control how SpamAssassin processes and manages whitelists and blacklists as well as the auto-whitelisting feature.

Table 3.8. Whitelist and blacklist options.

whitelist_from add@ress.com
unwhitelist_from add@ress.com
whitelist_from_rcvd addr@lists.sourceforge.net sourceforge.net
def_whitelist_from_rcvd addr@lists.sourceforge.net sourceforge.net
whitelist_allows_relays add@ress.com
unwhitelist_from_rcvd add@ress.com
blacklist_from add@ress.com
unblacklist_from add@ress.com
whitelist_to add@ress.com
more_spam_to add@ress.com
all_spam_to add@ress.com
blacklist_to add@ress.com

These settings are a matter of personal preference and should be set as the user and administrator see fit.


The options in Figure 3.9 control how headers are added to spam messages and header processing.

Table 3.9. Message tagging and header processing options.

rewrite_header { subject | from | to } STRING
add_header { spam | ham | all } header_name string

Defaults to:
add_header spam Flag _YESNOCAPS_
add_header all Status _YESNO_, score=_SCORE__ required=_REQD_ tests=_TESTS_
 autolearn=_AUTOLEARN_ version=_VERSION_
add_header all Level _STARS(*)_
add_header all Checker-Version SpamAssassin _VERSION_ (_SUBVERSION_) on _HOSTNAME_

remove_header { spam | ham | all } header_name
report_safe { 0 | 1 | 2 } (default: 1)

The defaults here are reasonable. If you want to adjust the headers, use the add_header keyword. If you want to tell SpamAssassin not to send a separate email message for every message it has identified as spam, set report_safe to 0, and then only X-Spam- headers will be added to the message.


The keywords in Figure 3.10 define geographic locations and language.

Table 3.10. Location and language options.

ok_languages xx [ yy zz ... ] (default: all)
ok_locales xx [ yy zz ... ] (default: all)

The default is set to allow all locations and languages, which should be acceptable for most situations.

Network Test

These settings include Razor, Pyzor, DCC, RBL, trusted networks, and other related areas (see Figure 3.11).

Table 3.11. Network test options.

use_dcc ( 0 | 1 ) (default: 1)
dcc_timeout n (default: 10)
dcc_body_max NUMBER (default 999999)
dcc_fuz1_max NUMBER (default: 999999)
dcc_fuz2_max NUMBER (default: 999999)
use_pyzor ( 0 | 1 ) (default: 1)
pyzor_timeout n (default: 10)
pyzor_max NUMBER (default: 5)
pyzor_options [option ...] (default: none)
trusted_networks ip.add.re.ss[/mask] ... (default: none)
internal_networks ip.add.re.ss[/mask] ... (default: none)
use_razor2 ( 0 | 1 ) (default: 1)
razor_timeout n (default: 10)
skip_rbl_checks { 0 | 1 } (default: 0)
rbl_timeout n (default: 15)
check_mx_attempts n (default: 2)
check_mx_delay n (default: 5)
dns_available { yes | test[: name1 name2...] | no } (default: test)

These options control the parameters for various network checking and whether checks happen or not. Trusted networks are networks that you know never emit spam and are exempt from certain tests. This series of parameters also allows you to control timeouts and DNS checks. The defaults are reasonable for most installations.


The options in Figure 3.12 control the operation of the Bayesian analyzer and whitelisting integration with the Bayesian engine.

Most of the Bayesian learning options are acceptable as shipped and don't need to be adjusted. If there are issues with Bayesian scores, the thresholds can be adjusted via the bayes_auto_learn_threshold parameters. In case you want to turn off the Bayesian processing totally, set use_bayes to 0.

Table 3.12. Bayesian analysis engine options.

use_bayes ( 0 | 1 ) (default: 1)
use_bayes_rules ( 0 | 1 ) (default: 1)
auto_whitelist_factor n (default: 0.5, range [0..1])
auto_whitelist_db_modules Module ... (default: DB_File GDBM_File NDBM_File SDBM_File)
bayes_auto_learn ( 0 | 1 ) (default: 1)
bayes_auto_learn_threshold_nonspam n.nn (default: 0.1)
bayes_auto_learn_threshold_spam n.nn (default: 12.0)
bayes_ignore_header header_name
bayes_ignore_from add@ress.com
bayes_ignore_to add@ress.com
bayes_min_ham_num (Default: 200)
bayes_min_spam_num (Default: 200)
bayes_learn_during_report (Default: 1)
bayes_use_hapaxes (default: 1)
bayes_use_chi2_combining (default: 1)
bayes_journal_max_size (default: 102400)
bayes_expiry_max_db_size (default: 150000)
bayes_auto_expire (default: 1)
bayes_learn_to_journal (default: 0)


These keywords (Figure 3.13) define the templates for functions and other areas not defined previously.

Table 3.13. Miscellaneous options.

lock_method {nfssafe | flock | win32 } (default: no default)
fold_headers { 0 | 1 } (default: 1)
report_safe_copy_headers header_name ...
envelope_sender_header Name-Of-Header
describe SYMBOLIC_TEST_NAME description ...
report_charset CHARSET (default: unset)
report ...some text for a report...
report_contact ...text of contact address...
report_hostname ...hostname to use...
unsafe_report ...some text for a report...

In the miscellaneous category, fold_headers controls whether the headers that SpamAssassin adds are broken up (the default) or kept as one single long line. If a mail client has issues with divided headers, this parameter can be adjusted.

Privileged Parameters

The end user is allowed to create his or her own spam checking rules if certain conditions apply.

Table 3.14. Administrator enabled or privileged settings.

allow_user_rules { 0 | 1 } (default: 0)
header SYMBOLIC_TEST_NAME header op /pattern/modifiers [if-unset: STRING]
header SYMBOLIC_TEST_NAME exists:name_of_header
header SYMBOLIC_TEST_NAME eval:name_of_eval_method([arguments])
header SYMBOLIC_TEST_NAME eval:check_rbl('set', 'zone' [, 'sub-test'])
header SYMBOLIC_TEST_NAME eval:check_rbl_txt('set', 'zone')
header SYMBOLIC_TEST_NAME eval:check_rbl_sub('set', 'sub-test')
body SYMBOLIC_TEST_NAME /pattern/modifiers
body SYMBOLIC_TEST_NAME eval:name_of_eval_method([args])
uri SYMBOLIC_TEST_NAME /pattern/modifiers
rawbody SYMBOLIC_TEST_NAME /pattern/modifiers
rawbody SYMBOLIC_TEST_NAME eval:name_of_eval_method([args])
full SYMBOLIC_TEST_NAME /pattern/modifiers
full SYMBOLIC_TEST_NAME eval:name_of_eval_method([args])
meta SYMBOLIC_TEST_NAME boolean expression
meta SYMBOLIC_TEST_NAME boolean arithmetic expression
tflags SYMBOLIC_TEST_NAME [ {net|nice|learn|userconf|noautolearn} ]

A simple rule is shown in Figure 3.14 for illustrative purposes. More complex rules may require changes to configuration files and are beyond the scope of this book.

Example Rule

We want to create a simple rule that scans the message body and adds 10 points to the spam score if the phrase this is a test of spamassassin is present. Rules can be placed in the user's configuration file if allowed by the administrator. More commonly, they are placed in /etc/mail/spamassassin/local.cf by the administrator, which is the method we use here.

If you want to look at the default rules that are distributed with SpamAssassin, they are located by default in /usr/local/share/spamassassin. Although you can add or update the rules located here, this can cause problems when upgrading to future versions of SpamAssassin. The rules files that are distributed with SpamAssassin 2.63 are shown in Figure 3.15.

Table 3.15. SpamAssassin distributed rules.


We update the local.cf file in /etc/mail/spamassassin with our new rule. The rule we want to add in local.cf consists of the following three lines:

body MY_SPAMASSASSIN_RULE        /this is a test of spamassassin/is
describe MY_SPAMASSASSIN_RULE    Test of my spamassassin rule

The name of the rule is MY_SPAMASSASSIN_RULE. The line starting with body defines the test to run. In our case, the test is to match the pattern this is a test of spamassassin, ignoring the case of the string (indicated by i) and matching with embedded newlines (indicated by s). The pattern modifiers (our rule has one, is) are Perl regular expressions.

The second line gives a human-readable description to our rule—in our case Test of my spamassassin rule. Finally, the number of points to be added to the score is indicated by score—in our case 10. Note that the score can be any positive, negative, whole, or fractional value.

If SpamAssassin is configured to run this test, and a message is processed by the server that contains the string this is a test of spamassassin, a message similar to that in Figure 3.16 should be sent to the recipient. Sending a message like this is the default method of spam notification under SpamAssassin. The original message is included at the bottom of the message from SpamAssassin.

Table 3.16. Example of SpamAssassin notification message.

Subject: Spamassassin rule test
From: somebody@example.com
Date: Tue, 20 Jul 2004 11:07:27 -0400
To: dale@woody.cushman.avacoda.com

Spam detection software, running on the system "woody.cushman.avacoda.com", has identified this incoming email as possible spam. The original message has been attached to this so you can view it (if it isn't spam) or block similar future email. If you have any questions, see the administrator of that system for details.

Content preview: This is a test of spamassassin. This message should be marked as spam. [...]

Content analysis details: (15.0 points, 5.0 required)

pts rule name         description
---- -----------          --------------------------------------------------
0.3 NO_REAL_NAME          From: does not include a real name
10 MY_SPAMASSASSIN_RULE   BODY: Test of my spamassassin rule
3.3 MSGID_FROM_MTA_SHORT  Message-Id was added by a relay
1.4 DNS_FROM_RFCI_DSN     RBL: From: sender listed in dsn.rfc-ignorant.org

Subject: Spamassassin rule test
From: somebody@example.com
Date: Tue, 20 Jul 2004 11:07:27 -0400
To: dale@woody.cushman.avacoda.com

This is a test of spamassassin. This message should be marked as spam.

SpamAssassin assigned this message a score of 15.0 points, activating the following rules and associated scores:











The tests were activated due to the lack of a name in the From: header, the test rule we built containing the test phrase, the fact that a header was generated by a mail relay, and the fact that the From: sender is listed in a BLS blacklist.

  • + Share This
  • 🔖 Save To Your Account

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information

To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.


Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites, develop new products and services, conduct educational research and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.


If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email information@informit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information

Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.


This site is not directed to children under the age of 13.


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information

If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.


Users can always make an informed choice as to whether they should proceed with certain services offered by InformIT. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.informit.com/u.aspx.

Sale of Personal Information

Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents

California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure

Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact

Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice

We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020