Filter email and spam with Thunderbird - Featured Image

Filter email and spam with Thunderbird

In Applications, System Administration & Devops by Željko JaguštLeave a Comment

I've noticed the same pattern after 20 years in system administration and several companies behind me. Email as a service was always present and mandatory, but nobody took it seriously. And the same issues were always present, primarily cluttered mailboxes and constant problems with spam and malware.


Email is something we all take for granted. When it comes to our inbox, we read it (sometimes not even that), reply if there is a need, and then forget it. And it's all OK up until we get into trouble where we have several thousand emails in our inbox and spam starts hitting hard. Usually, we try to find a "quick" solution on the web in that situation, or we call someone who we think will be able to help us.

Now, let me tell you something. There is no quick solution. And since it is your email, it is your problem and not someone else's. So take a few deep breaths, calm yourself down, stop being a lazy bastard, and take some time to resolve the problem. Yeah, it may be boring, but if you don't fix it, the problem will not disappear, becoming even more prominent. You might as well start here.


Although the same logic will work with most major email clients, this guide focuses on a Thunderbird Mail client. If you're in doubt regarding installation, please be free and check our Thunderbird installation guide on the link below:

Thunderbird Junk Settings

Everything related to spam, malware, and similar are considered Junk email. If you have an email account on one of the major free email services like Gmail, Yahoo, Outlook Live, and similar, you don't have to pay much attention. Those services already have powerful spam filters in place which will filter junk email before it comes to your inbox. If you work for a big corporation with a mail server on-premises, you will (probably) not have to worry about that also. In any other case, you will have to resolve the "spam problem" within your email client. Now, it's pretty easy to do that with Thunderbird. Fire it up, and let's get started.

With Thunderbird up and running, click on a menu button in the upper-right corner, and once the drop-down menu pops up, click on Account Settings:

Filter email and spam with Thunderbird - Account Settings
Thunderbird Account Settings

In Account Setting, click on Junk Settings and enable the following options under the Selection section:

  • Enable adaptive junk mail controls for this account
  • Personal Address Book
  • Trust junk mail headers set by and select SpamAssassin from the drop-down list (optional)
Filter email and spam with Thunderbird - Junk Settings
Thunderbird Junk Settings
As for Destination and Retention, it's up to you will you enable moving junk messages to a specific folder or not. I have it set as seen on the picture below:
Filter email and spam with Thunderbird - Junk Settings
Thunderbird Junk Settings
Under the first option (Enable adaptive junk mail controls for this account), please notice the following text:
If enabled, you must first train Thunderbird to identify junk mail by using the Junk toolbar button to mark messages as junk or not. You need to identify both junk and non junk messages. After that Thunderbird will be able to mark junk automatically.
So yeah, to start, you will have to mark each mail in your inbox you consider spam as spam. As for the Junk toolbar, switch to your inbox tab. Pay attention to your received emails and you will notice a small flame/fire icon positioned on the left of each email:
Filter email and spam with Thunderbird - Junk Toolbar
Thunderbird Junk Toolbar

You will need to click on the flame icon for each mail you consider spam. If you consistently mark a specific type of email as junk, Thunderbird will learn that that type of email should be marked as spam in the future. Given time, the Thunderbird adaptive filter will improve as it watches how you sort your email, and eventually, it will reach nearly 100% classification accuracy. From there, it will start to filter spam automatically.

If Personal Address Book is enabled, when you receive a mail from a sender whose email address is in your address book, that mail will never be considered spam.

If Trust junk mail headers is set by option is enabled, it will automatically recognize mail that is marked by a separate junk mail filtering program. For this to work, your ISP/email provider needs to have a filtering program installed, and such a filtering program should support one of the options from the list. You can always check this with your provider.

With all the options enabled and configured, and a bit of persistence, you will get yourself rid of the spam problem once and forever.

Filter email with Thunderbird

Message filters in Thunderbird will allow you to organize your emails automatically. Once the filter is set, it will usually move the message to a specific folder, delete the message, forward the message to another email, and similar. There are quite a few options you can set for your incoming email, and I will go through a few most common examples in the rest of this guide.

Filter email per address

To filter email per address, you need to know the sender's email address. For example, let's say I want to move all messages sent by [email protected] to a specific folder. First, I will create a folder inside my mailbox. To do it, I will right-click on my mailbox and select New Folder... from a drop-down menu:
Filter email and spam with Thunderbird - New Folder
Create New Folder
I will name the folder Example. Now I can create a message filter. To do so, I will click on the main menu in the upper-right corner, and from there on Tools -> Message Filters:
Filter email and spam with Thunderbird - Message Filters
Message Filters
In the message filters window, I will click on New... to create a new filter:
Filter email and spam with Thunderbird - New Message Filter
Message Filters
Once the Filter Rules window opens, I will define my rule. I will give the filter a name and set it up to run every time I receive new messages. I will also check Manually Run, which will run the filter on manually triggered runs.
Next, I will set my rule conditions. As you can see in the picture below, I've set my filter to move every message coming from [email protected] to Example folder in my inbox. Simple as that.
Filter email and spam with Thunderbird - Example Filter
Filter Rules
Now I will confirm my filter rule by clicking on the OK button. Once the filter rule window closes, I will have the option of executing the filter manually. To do so, I can click on the Run Now button:
Filter email and spam with Thunderbird - Manual Run
Filter Rules
Once I execute the manual run, all the email messages I received from [email protected], which are currently in my inbox, will be moved to the Example folder. Also, in the future, every email from the same address will be automatically moved to the Example folder once I receive it. The filter will also trigger automatically every time I start the Thunderbird client.

Filter email per domain

Email domain is part of the email address after the "@" character. So, if you are receiving email from the [email protected] address, is the domain of that email address. To filter such messages, you will also need to create a folder in your inbox where such messages will be moved after filtering. Once you create a folder, click on the main menu in the upper-right corner, and from there, click on Tools -> Message Filters. Once the message filter window opens, click the New button and create a domain-based rule:
Filter email and spam with Thunderbird - Domain Filter
Filter per Domain
As you may notice in the picture above, the matching rule needs to be changed from "is" to "contains." In the previous example, where messages were filtered specifically per full address, here we are matching only the part of the email address (only the domain part). This way, our filter will match all messages sent from anyone on the domain email.

Filter email per subject

We can call the email subject the email message's title. An example where you would filter such messages is if you subscribed to a newsletter on some website you like, and now you are receiving weekly or monthly email messages. The subject of such a message would usually be something like "Newsletter from the website - topic" or something similar, and part of it would always be the same, let's say Newsletter from the website. Now, we can use that part (tag) to create our filter. The procedure of creating such a filter is the same as for the previous two examples, with the following filter rule:
Filter email and spam with Thunderbird - Subject Filter
Filter per Subject
As you can see in the picture above, we are matching a Subject that contains a [TAG], where the tag can be "Newsletter from the website -." By creating such a rule, all messages containing that tag will be moved to a folder you specifically created for such messages.

Filter combination

Options for combining the filter rules are virtually limitless in Thunderbird. You can define a combination of rules in a single filter. Below, I will give a simple example where I will combine address and domain rules into a single filter:
Filter email and spam with Thunderbird - Filter Combination
Filter rules combination

As shown in the picture above, when you have multiple rules, you need to tell your filter to match any of the rules specified. To do so, select Match any of the following option.

With some time and common sense, you can get to a point where all your incoming messages are finely filtered, and each message is moved to a specific folder (or deleted, forwarded to another email, etc.). It may take some time and effort on your side, but the benefit of having a well-organized mailbox is something I consider well worth it.

Email Retention (optional)

Let's go back to our "Newsletter from a website" subject filter example above. Again let's presume you're receiving email messages every week from a website newsletter to which you subscribed. You created a filter for such messages, which will be moved to a specific folder once they arrive in your inbox.

Now, let's also presume you don't need two or more years' worth of such newsletter messages. You don't need them because such an old newsletter is probably irrelevant and may be deleted. You can delete those messages manually or define a retention policy on the folder where such messages are stored. To do so, right-click on the folder in question and click on Properties:

Filter email and spam with Thunderbird - Folder Properties
Folder Properties
Once the folder properties window opens, click on the Retention Policy tab:
Filter email and spam with Thunderbird - Folder Properties Window
Select Retention Policy
First, uncheck Use my account settings in the retention policy tab, so other options become available. Here, you can either specify how many most recent messages you want to keep or delete all messages older than the specified amount of time. If you consider specific messages essential and don't want them deleted, you can select Always keep starred messages. This will prevent the retention policy in place from deleting such messages.
Filter email and spam with Thunderbird - Retention Policy Settings
Define Retention Policy
To "star" a message, you need to click on a "star" symbol next to the message in your inbox or folder which contains your messages:
Filter email and spam with Thunderbird - Star Messages
Star Messages
With a well-defined retention policy, you will never have to delete a single email message ever again, leaving you with only relevant messages in your mailbox.

Sending Emails (optional)

There are specific rules that need to be satisfied when sending emails. For instance, I receive a bunch of email messages that don't have a subject or emails with files attached and no message. Both will end up in my Spam/Junk folder. All the major email services like Gmail, Yahoo, and similar have filters that will classify such messages as spam. If you have a habit of sending such emails, please stop now. Eventually, your email address will be classified as a spam email address, and all messages you send will be classified as spam on the receiving end. To avoid this, please respect the following rules when sending emails:

  • Use CC and BCC when sending emails to multiple recipients
  • Always specify the subject of the message
  • Always write a message, even if you are replying to or forwarding a message
Filter email and spam with Thunderbird - Required Email Elements
Sending emails
With all this in place, you should never again have to worry about your emails and you can focus on more important tasks. Thank you for reading!

Share if you like. Thank you in advance!

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.