Skip to content

Cookie settings

Choose which kinds of cookies you allow. You can change your choice at any time via Cookie settings at the bottom of every page. Privacy statement

Necessary

Always on

Needed to log in, keep your cart and remember your choices. These are always on.

Which cookies?
  • weboke_sessie, weboke_klant, weboke_remember: your session and staying logged in
  • weboke_basket: your cart
  • wkBtwIncl: showing prices with or without VAT
  • wok_cookies: your cookie choice, 12 months

Measures which ad leads to a visit or order, so we do not pay for ads that do nothing.

Which cookies?
  • Google Ads via Google Tag Manager (_gcl_au, _gcl_aw), up to 90 days
  • OpenAI Ads, ads in ChatGPT
  • wok_aff: which partner referred you to us (affiliate programme), 60 days

4.6

Country and language

Each country has its own site, with prices and VAT for that country.

View

Module 6 · 6.2

Designing and testing filters

Module 6: Automatic: filters and out of office · Reading time: 9 minutes

Learning objective: After this lesson you can turn a wish into a filter that does exactly what you mean, avoid the well-known pitfalls and test your filter before you rely on it.

Key concepts: choosing a header, From, To, List-Id, Subject, too-broad filter, order, forwarding, Create filter, test email, Download

From wish to rule

A good filter starts with a sentence in plain language: "All mail from the wholesaler should go into the Suppliers folder." Then you ask three questions:

  1. How can you recognise that mail for certain? Not "it's usually about orders", but something that is always in the headers: an address, a domain, a header that only that mail has.
  2. What should happen? Move, copy, redirect, delete, and should the script stop afterwards?
  3. What must the filter not touch? Think of the mail that looks just like it. That is where filters go wrong.

Which header to filter on

The header you choose determines how reliable your filter is.

  • From for mail from a person or company. Filter on the address or on the domain: @example.net catches everyone at that company. Don't filter on the display name: anyone can fill in any name (lesson 2.2).
  • To for mail that arrives via another address. If the address info@example.com forwards to Sanne's mailbox, she recognises that mail by info@ in the To header. Note: mail that someone sent with Bcc doesn't have that address in To.
  • List-Id for newsletters and mailing lists. Well-behaved senders add this header (RFC 2919), with a fixed code per list. That is more reliable than the sender address, which sometimes changes for newsletters.
  • Subject only if the subject is fixed, such as automatic notifications from a system. Otherwise the subject is the least reliable choice: anyone can put anything in it.

A filter for newsletters from one wholesaler looks like this in Sieve:

# rule:[Groothandel]
if header :contains "List-Id" "nieuws.example.org"
{
	fileinto "INBOX.Leveranciers";
	stop;
}

Four pitfalls

1. Too broad. "Subject contains factuur" (invoice) seems handy, but it also catches phishing with "Uw openstaande factuur" (your outstanding invoice) that the spam filter just missed. It then sits neatly among your real invoices, where you look at it less critically. Make it narrower: "From contains @example.net and Subject contains factuur", with the scope "matching all of the following rules".

2. Order. Filters run from top to bottom (lesson 6.1). A broad filter with stop at the top can sideline a specific filter below it. Put the specific filter at the top: first "newsletter from the wholesaler", only then "everything from example.org".

3. Upper case and spaces. Contains ignores upper and lower case, so you don't need to think about that. One space too many or a typo in the text does make the filter fail. "factuur " with a space after it won't find "factuur.".

4. A folder that changes later. A filter refers to the full name of a folder. If you rename the folder or move it under another folder, the name in the filter is no longer correct. So check your filters after every change to your folders.

Redirecting to an external address

With the action Redirect message to you can send mail to another address, for example an address at Gmail. That has two drawbacks.

First, you also redirect spam that the spam filter didn't stop. The receiving service sees your mail server as the server delivering that spam. That can damage your server's reputation, and with it the delivery of all your normal mail.

Second, the sender checks no longer add up. A redirected email from ahmed@example.net arrives at Gmail from your server. The SPF record of example.net doesn't list your server, so the check fails. As a result, the message may end up in spam or be rejected. The Email in Order course explains SPF and DMARC in detail.

So only redirect to addresses you manage yourself, and preferably with a forwarder in the control panel rather than with a filter.

Creating a filter from a message

The quickest way to create a filter is from an email you want sorted. Open the message and choose More > Create filter. The webmail fills in the sender and the subject for you. Remove what you don't need: usually the sender alone is enough, and the subject actually makes the filter too narrow.

A new filter with Filter name, a rule Subject contains invoice and the action Move message to Customers
(1) Filter name, (2) where the filter looks, (3) the text, (4) the action, (5) the folder

Test before you rely on it

You only notice a filter that silently fails when you miss an important email. So always test:

  • A test email to yourself. Your own mail goes through the mail server to your mailbox, so the filters run. Put the word in the subject and check whether the message lands in the right folder.
  • Also test what must not match. Send an email without the word and check that it stays in the Inbox. Try upper case too.
  • Read the script. With Filters > Actions > Edit filter set you see what the webmail has actually saved. If it says if false, the filter is switched off.
  • Keep a copy. With Filters > Actions > Download you get the whole script as a file. Handy as a backup, and for comparing if something suddenly behaves differently.
Settings, Filters with the Actions menu: Edit filter set and Download
(1) Edit filter set: the script itself, (2) Download: the script as a text file

A filter per mailbox, or for the whole domain

Filters in the webmail apply to one mailbox. If you want to block a sender for all mailboxes on your domain, or make the spam filter stricter, you do that in your hosting control panel. At WebOké that is DirectAdmin, which includes the SPAM Filters section. Don't set the same thing in two places: later you won't know which rule stopped a message.

In practice: how it works in the webmail

You create filters under Settings > Filters with Create, or from a message with More > Create filter. You view the script under Filters > Actions > Edit filter set, and Download gives you a copy. The Roundcube manual has the steps and a table of useful filters. Other webmail works in a similar way: Gmail creates filters from a search, Outlook.com has rules with conditions and actions.

Summary

  • Start with a sentence in plain language and ask yourself how you can recognise the mail for certain and what the filter must not touch.
  • Filter on address, domain, To or List-Id; the subject is the least reliable.
  • Pitfalls: too broad, wrong order, typos and spaces, a renamed folder.
  • Redirecting to an external address also redirects spam and makes SPF fail; only do it to addresses you manage yourself.
  • Test with mail to yourself, including what the filter must not touch, and keep a copy with Download.

Quiz

1. You want newsletters from a club to go into a folder automatically. Which header is the most reliable?



2. Your filter "Subject contains factuur" also puts phishing into your Facturen folder. What is the best improvement?



3. You rename the folder Facturen to Accounting. What happens to the filter that moves mail to Facturen?



4. Why do we advise against using a filter to redirect all mail to an address at another service?



5. What is the best way to test whether your new filter works?



Exercise

Exercise A6.2: Get your own filter checked. In your own mailbox, create a filter that moves mail with a word of your choice in the subject to a folder of your choice. On the page, fill in the word and the folder name. Then paste your filter set (Settings > Filters > Actions > Edit filter set, select all and copy) or upload the file you get with Download. The program reads the Sieve script in memory (nothing is stored) and runs three test messages: a message with your word in the subject (must go to your folder), a message without the word (must stay in the Inbox) and a message with your word in capitals (must also go to your folder). Green if all three are correct. You get a warning if the filter is switched off, if the folder name in the script doesn't match what you filled in, or if the script redirects mail to an address outside your own domain.

Exercise A6.2: Get your own filter checked






Please upload a test file with fake data rather than your real data. The file only stays in memory while it's being checked; we don't store it.

What you enter and what we find isn't stored. Your browser remembers your answers and whether you've passed the exercise. If you're signed in, we only save that you got the exercise (almost) right in My courses; you can delete that there too.

Further reading

Where steps in the webmail are given, they apply to the WebOké webmail; other webmail works in a similar way.

One moment…

Set up your domains

For each domain, arrange the nameservers, the link to your hosting and who becomes the owner.

Loading your domains…