<!--
  canonical-url: https://www.avonture.be/blog/cpanel-spam
  published:     2024-01-23
  This is a static plain-Markdown mirror generated at build time.
  Visit the canonical URL above for the fully rendered page, with images and interactive components.
-->

# Exterminate them all, fight spam directly at your host company

> Stop email spam at the source! Discover how to use cPanel's SpamAssassin to blacklist and whitelist domains, including an advanced method for directly editing the user_prefs file via FTP.

---
![Exterminate them all, fight spam directly at your host company](/img/v2/fighting_against_spam.webp)

**TL;DR**

This article shows how to fight spam at the source using cPanel's SpamAssassin: defining blacklist and whitelist domain patterns through the web interface, or editing the `.spamassassin/user_prefs` file directly over FTP to manage `blacklist_from`/`whitelist_from` rules in bulk, sorted and deduplicated.

If your web host company offers you cPanel access, you will find a tool called *SpamAssassin* there.

There, you have two main options: the *Spam filter* and a *White list*.

Using the first one, you can define email patterns like `*@hair.com` which means: immediately kill those emails on the server. The second one is just the opposite, f.i. `*@my-own-company.com` saying that you trust that domain.

> **PlanetHoster - N0C:**
>
> If you're hosted by PlanetHoster on the N0C infrastructure, please read [Exterminate them all, fight spam directly at PlanetHoster - N0C](/blog/planethoster-n0c-spam) instead.

My personal use case: even if I don't like shortcuts on my desktop, I do have one for `https://(my_host_company)/xxxxx/mail/spam/index.html#/blacklist` i.e. direct access to the page where I can add my spam filters. And it works quite well.

*Clicking through a web interface doesn't scale, though. [Exterminate them all, kill spam using GitHub Actions](/blog/planethoster-n0c-spam-roundcube-action) generates the rules from a JSON list and deploys them automatically.*

![Spam filters](./images/spam_filters.webp)

But, did you know there is another way to do this?

Using your FTP client, go to your user's home directory. If your host has SpamAssassin enabled, you'll see a folder called `.spamassassin` and, in that folder, a file called `user_prefs`. Open that file.

That file can look like this:

**.spamassassin/user\_prefs**

```
blacklist_from *.hr
blacklist_from *.rest
blacklist_from *.ru
blacklist_from *.su

blacklist_from *@hair.com

whitelist_from *@avonture.be
whitelist_from *@my-own-company.com
```

As you can expect, you'll find two rules: `blacklist_from` and `whitelist_from` with the pattern you've filled in the SpamAssassin web interface of your hosting company:

> **Spam Filters location:**
>
> You can manipulate entries one by one using the web interface too. Go to your cPanel, search for `Spam Filters` and click on `Additional Configurations (For Advanced Users)`.

You can now manipulate the list with f.i. VSCode and sort it alphabetically, simplify rules, remove duplicated entries (after refactoring), ...

I really like fighting against spam directly at my host company because, otherwise, I get spam on all my machines (my different computers and my smartphone) and, on my smartphone, when I click on *This is spam*, I only ever teach my smartphone to delete this email, not my other machines... And I only identify that sender (like `<buy-it@hair.com>`); I'll continue to get spam from any other email account like `really-but-it@hair.com`.

The fight doesn't stop there — next up, [fighting spam directly at PlanetHoster - N0C](/blog/planethoster-n0c-spam).
