A Basic Introduction to Sieve Filters¶
Sieve filters are mail filters that are run on the mail server, instead of in your mail application.
Advantages of Sieve Filters¶
Unlike message filters which operate in a single mail client (like Thunderbird or Outlook, for example), Sieve filters will affect all the email clients that you use, as well as any webmail applications. If you use Outlook at your work computer, for example, but sometimes use SOGo webmail at home, the filters will affect both locations.
There is nothing particular that you need to do to your domain name to get started. Your GandiMail address is ready to go with this feature.
Getting Started with Sieve¶
Sieve filters exist as a file on our mail server which contains all of the filters you have created. To manage these filters you will use a third party application to edit this file.
Step One: Choose a Sieve Application¶
Sieve filters are created using the Sieve language. There are some applications which allow you to use this code to write your filter from scratch. There are also filters which will provide an interface for you so you do not have to write any Sieve code. Both type of applications will work the same, the only difference is in how you create the filters. More advanced users or users with complex filters may prefer to write their own code. Beginning users would likely be happier using an interface.
For users looking for a user interface where no code is required, you can use either of our webmail clients, SOGo and Roundcube. Filters created on our webmail clients act as Sieve filters, and the actions taken by the filters there will be applied to all of your mail clients. Gandi’s SOGo and Roundcube servers are not currently configured to accept filters written in Sieve code, however, so filters must be created using the built in interface.
For users who wish to write their own Sieve filters, we would suggest the Sieve add on for Thunderbird by Thomas Schmid. You can also find a list of applications at Sieve.info.
Step Two: Connect Your Sieve Application with Your Account¶
Once you have chosen the Sieve application that you want to use, you will need to connect it to your email account. If you are using a Sieve application through an existing mail client, such as Thunderbird, SOGo, or Roudcube, you will likely be connected to your account automatically.
If you do need to provide connection information use the following:
Host: mail.gandi.net
Port: 4190
Login: Your full email address, such as yourname@example.com
Password: The password for the provided email address
Step Three: Create Filters¶
Some Sieve filter applications, such as SOGo and Roundcube, will allow you to create filters using their predetermined interface. This means you will select drop down options from the menu and fill out prompts as you create each filter.
Other Sieve applications will allow you to write the filter using code. This means you can write filters by hand, which may be preferable for more advanced users, or for users with complex filters. You can check out our tutorial on writing Sieve code if you wish to learn how to write your own filters.
Filter Spam with Gandi Headers¶
Every email consists of two parts: the body, and the headers. The body contains what you traditionally think of as the content of an email. The headers contain information such as who sent the email, where it was sent from, what time it was sent, and so on. Sometimes the mail servers that process email will add additional headers for processing purposes. For example, Gandi’s mail server will analyze the email and then create a header with the results of that analysis. You can use the headers added by Gandi’s mail servers to create your own spam filters.
X-GND-Status¶
The X-GND-Status is a mail header which categorizes types of email. The following table explains each status used by Gandi.
SPAM |
Emails determined likely to be SPAM. Can also be accompanied by the header X-GND-Score, which includes the score indicating how likely this message is to be spam. |
PCE |
Professional commercial email detected by the analysis of the signature: typically email campaigns from a known professional mailing platform (ESP) that adheres to rules governing email advertising, by describing unsubscribe links, list removal etc. |
MCE |
Commercial email that is detected and follows the rules governing email marketing, but that was not sent from a known platform. |
DCE |
Dirty Commercial Email detected by signature: Any other advertising campaign that does not comply with emailing rules by presenting poorly organized content, non-compliance with CAN-SPAM, no unsubscribe link, etc. |
SOCIAL |
Notifications and alerts from social networks |
PURCHASE |
Emails confirming purchase transactions via the internet |
ACCOUNT |
Emails sent to confirm the creation or update of a user account |
TRAVEL |
Emails that are sent concerning travel confirmations (car rental, travel tickets, hotel reservation) |
FINANCE |
Emails sent concerning financial information (bank transfer confirmations, account balance, etc.) |
ALERTING |
Emails concerning the subscription to an alert service (Google alerts, Yahoo alerts, real estate, etc.) |
BOUNCE |
Notification that a mail could not be delivered |
SUSPECT |
A message with a subject that could potentially be harmful (ex. emails with a content referring to to money transfer) |
PHISHING |
Emails determined likely to be a phishing attempt. |
SCAM |
Emails determined likely to be a scam. |
If you are creating a Sieve filter using an interface, like SOGo, you can filter by header by choosing “Header” as an option, giving the name of the header (X-GND-Status in this case) then the criteria for the filter.
The following filter created in SOGo will send all commercial emails to a folder called “Commercial Emails.”
The same filter created with Sieve code will also send all commercial emails to a folder called “Commercial Emails”.
# Filter emails categorized as MCE or PCE into the commercial emails folder.
require "fileinto";
if header :contains ["X-GND-Status"] ["MCE","PCE"] {
fileinto "Commercial Emails";
}
You can also use the following filter created with Sieve code to put any messages with a spam score higher than 200 into the junk folder.
# Filter emails with a spam score higher than 200 into the junk folder.
require ["fileinto","regex"];
if allof (header :contains ["X-GND-Status"] ["SPAM"], header :regex ["X-GND-Spam-Score"] ["[2-4][0-9][0-9]"] {
fileinto "Junk";
}