Filtering Email

Incoming email can be filtered on the mail server by specifying procmail rules for your Opalstack mail users. These rules will allow you to file or delete incoming email messages based on the sender, the spam score, or any other content of the message.

About Procmail Rules

A procmail rule generally consists of three lines:

  • :0: is a marker that indicates the beginning of a rule. The marker always begins with a colon : followed by a zero 0.

  • * condition is the criteria for the filter. Note that the condition line always begins with an asterisk *. The conditions themselves are regular expressions which typically start with a particular email header followed by whatever text you're attempting to match.

  • .destination/ is the folder for the messages that meet the filter criteria. Note that in procmail rules, mail folder paths are always preceded by a dot . and end with a slash /.

Your mail user can have multiple procmail rules. The rules are processed in the order that they are entered, and processing stops at the first matched rule.

Editing Procmail Rules


Click on Email in the control panel sidebar.

The Email section of the sidebar will expand to show more options.


Click on Mail Users in the expanded sidebar.


Click the Edit icon for the mail user whose procmail rules you want to edit. The Edit icon appears in the rightmost column of the user list.


Enter or edit your procmail rules in the space provided.


Click the Save button. Your changes will be applied after approximately 1-2 minutes.

Procmail Examples

Filtering messages from a specific sender

This basic example moves mail sent from into a folder named Bob:

* ^from:.*bob@domain\.com

Filtering messages to a specific recipient

Filtering by recipient is useful when you have multiple addresses attached to a single mail user.

The following example will move mail sent or cc'd to into a folder named Work:

* ^(to|cc|bcc):.*me@company\.com

Filtering messages with specific words in the subject

Sometimes it is useful to categorize incoming messages based on their subject.

In the next example, incoming mail that contains the word "invoice" in the subject will be moved into a folder named Invoices:

* ^subject:.*invoice

Filtering suspected junk email messages

The incoming mail servers on your Opalstack email service analyze incoming mail and assign to it extra headers indicating the likelihood that the message is junk email (aka "spam").

One of these headers is named X-Spam-Level and contains a series of asterisk characters can be used to filter suspected junk email.

For example, a message with a spam score of 6 will have a header that reads X-Spam-Level: ******. The six asterisk characters indicate that the spam score is 6.

If you decide that you want any message with a spam score of 5 or higher to be filtered into a folder named Junk, then you can use a procmail rule similar to this:

* ^x-spam-level: \*\*\*\*\*

As you can see, the x-spam-level filter expression contains 5 sequences of \* (escaped asterisks).You could increase the sensitivity of that rule by using fewer \* sequences, thus lowering the spam score that you use as your criteria for spam. This will result in less spam in your inbox, but with a higher probability of false positives being moved out of your inbox.

Conversely, you can use a higher number of \* sequences to filter on a higher spam score. This will leave more spam in your inbox, but with a reduced probability of false positives being moved out of your inbox.

Deleting messages

You can delete messages by using the special folder named /dev/null as the destination in your procmail rules.

As an example, here is an expanded version of the previous spam filter that includes an additional rule that deletes messages:

* ^x-spam-level: \*\*\*\*\*\*\*\*\*\*

* ^x-spam-level: \*\*\*\*\*

The first rule deletes messages with a spam score of 10 or higher, and the second rule moves any remaining messages with spam score of 5 or higher into the Junk folder.

This example also illustrates the importance of the order of your rules. Once a message has been matched in a rule, the action for that rule is run and all processing for that message stops. If the order of our two spam rules were reversed then all spam with a score of 5 or higher would be filtered into the Junk folder. No spam would be deleted because the processing would stop before the other rule could run.