Sieve examples

These examples are provided as a starting point for building up your own custom Sieve scripts.

If you're looking for information on how to set up Sieve in your account, please see our Using Sieve scripts in Fastmail help page.

Thank you to the Fastmail users who contributed these examples.

File all messages from a recipient into a folder

if address :is "From" "pal@mypals.org" {
  fileinto "INBOX.My Best Pal";
  stop;
}

File all messages from a domain into a folder

if address :domain :is "From" "mypals.org" {
  fileinto "INBOX.Pals";
  stop;
}

File messages into multiple labels

if address :is "From" "pal@mypals.org" {
  fileinto :copy "INBOX.My Best Pal";
  stop;
}

File all undefined addresses at a virtual domain into a folder

The below example is useful when:

  • You have a catch-all saved for your domain.
  • You only want to receive mail to a few addresses at this domain, and think the rest might be spam.
  • You would like to save all email that comes to your domain, just in case it is needed.

    if allof(
      address :domain :is "X-Delivered-To" "mydomain.info",
      not address :localpart :is "X-Delivered-To" ["address1", "address2", "address3"] # these are addresses at which you would like to receive email
    ) {
      fileinto "INBOX.Possible spam";
      stop;
    } 

File messages to some addresses into address-dependent folders

This example is useful for someone who has three addresses at which they would like to receive mail in their Fastmail account, and other addresses for which they would like mail to be redirected to another email account without being saved to their Fastmail mailbox.

One of these addresses, address2@sent.com, is used only for non-urgent email, for which we would like to mark it read immediately.

if address :is "X-Delivered-To" "address1@fastmail.fm" {
  fileinto "INBOX.address1";
  stop;
} elsif address :is "X-Delivered-To" "address2@sent.com" {
  setflag "\\Seen";
  fileinto "INBOX.address2";
  stop;
} elsif address :is "X-Delivered-To" "address3@eml.cc" {
  fileinto "INBOX.address3";
  stop;
}
redirect "another@account.net";

Backup

This Sieve script is useful for sending a backup copy of all email to a different email account, and keeping the rest on your Fastmail account.

redirect "backup@gee-mail.com";
keep;

Do not filter known senders

This example filters all mail except messages from your contacts or from domains you have decided are safe.

if not anyof(
  header :contains ["X-Spam-known-sender"] "yes",
  header :contains ["from"] ["amazon.co.uk", "myworkdomain.com"]
) {
  # ...filtering code goes here...
}
Was this article helpful?
35 out of 53 found this helpful