Sieve Scripts

What is sieve?

Sieve is a programming language for filtering incoming emails. FastMail's flexible rules system provides most users with filtering functionality, but advanced users may choose to write Sieve scripts for complicated filtering (such as time-based rules, or access to our notify extension).

A sieve script consists of a number of tests which are applied to incoming mail; if a mail matches a test, then the actions associated with that test are performed.

Sieve scripts can be used to automatically delete or forward messages; to send autoreplies; to sort them in folders; to mark messages as read or flagged; to test messages for spam or viruses; or to reject messages at or after delivery. has more information on sieve and its uses.

To create sieve scripts, go to the Advanced → Rules screen and click the "Edit custom sieve code" link. The rules system creates a sieve script behind the scenes, and the advanced rule editing functionality allows you to write additional filtering actions to supplement your existing rules.

Sieve is a powerful language. Only use it if you know what you're doing. It is possible to create a rule which permanently discards mail without the protection of our backup system.

If you're not familiar with sieve, we have a basic sieve guide, including details on how to test your sieve script.

The notify extension

Notify is a custom action available for FastMail sieve scripts, used for forwarding a small portion of a message to your phone or to another email address.

We support the following notification destinations:

The notify command has the following syntax:

notify :method <method> :options [<destination>, <options>] :message <text>;

The parameters are as follows:


if address :contains ["to"] "+alert@" {
    notify :method "sms"
       :options ["1-555-555-5555", "Squeeze", "High", "Length", "50"]
       :message "$from$ / $subject$ / $text$";

Notification loop checking

If you set up a notification to generate an email back to the same account (or even one that will eventually forward back to it), you may end up creating an infinite loop of notifications.

To help prevent this, we try to detect loops. This works by looking for a [Notify …] section in the message subject and replacing it with [Notify*2 ...], and so on, until it reaches *5, at which point an error is generated and the notification is cancelled.

However, since this depends on the subject of the notification message, you still run the risk of loops if you use a custom <text> string. You should exercise caution if you use a custom <text> string to avoid this possibility.

Special use folders

Some mail clients allow you to rename the system folders, such as Archive and Trash. This can make sieve scripts break if they are using folder names explicitly. Fortunately such folders have a special use flag, allowing you to access them from sieve without needing to know their current titles.

Modifying the sieve script

Many (but not all) of the choices you make in the Settings screens change the your sieve script, not just the Rules screen.

The sieve editing screen prevents you from changing the automatically generated script based on your rules and settings, but leaves you with editable blocks that you may insert your script elements at the right place within the script.

Sieve supported extensions

Sieve has a lot of extensions. FastMail supports a subset of these, as given below:

Note that the final RFCs of these last sieve extensions have significant changes that are not currently supported.