Sample Sieve Filters

The following Sieve filters are written using Sieve code. To learn more about how to set up your Sieve filters, see Getting Started with Sieve. You can also check out our Sieve tutorial to get a step-by-step explanation of how to write your own Sieve filters from scratch.

Note

Only one Sieve file can be active at a time, so it is important to include every filter you wish to use in the same file.

Send Gandi Renew Emails to Renew Folder

The following filter will send any emails that come from support-renew@gandi.net to a folder named “Renew” stored inside the inbox.

# Send emails from "support-renew@gandi.net" to my renew folder.
require "fileinto";
if address :is ["from", "sender"] "support-renew@gandi.net" {
  fileinto "Inbox/Renew";
  stop;
}

The name of the folder you use is relative to the root location. “Inbox/Renew” refers to a subfolder of Inbox called Renew.

The stop command will stop the filtering of this message, which means no other filters in the file will be applied to messages that meet this criteria after peforming this action.

Out of Office Auto Reply

The following is an example of an out of office reply using the vacation extension. It also uses the date and relational extensions to allow you to set the filter to run only during the specified dates.

# Let people know I will be on vacation next week.
require ["vacation","date","relational"];
# If the date the email is received is greater than or equal to
# August 1st, and less than or equal to August 15
if allof (currentdate :value "ge" "date" "2025-08-01", currentdate :value "le" "date" "2025-08-15") {
    vacation :subject "Gone fishing"
             "Hello, I have gone fishing and will return sometime next week. - Mr. Smith";
}

To learn more about how to use the vacation extension you can check out the proposed standard.

Filter by Subaddress

A subaddress is an email address you can create whenever you wish simply by adding “+tag” to the name portion of your email. For example, if I was setting up a new account on amazon I might give my address as “myaddress+amazon@example.com”. I will still receive the email as normal, but the “to” address will contain the tag, which makes it simple to sort into a specific folder.

# Put emails sent to my +amazon subaddress into the "amazon" folder.
require ["envelope", "subaddress", "fileinto"];
if envelope :detail "to" "amazon" {
        fileinto "INBOX/amazon";
    }

The :user comparator looks at the regular part of the email address. So, for “myaddress+amazon@example.com” it would look at “myaddress”. The :detail comparator looks at the added part of the address, or “amazon” in the example given above. You can learn more about the subaddress extension by looking at the proposed standard.

With the following filter, you can cause emails going to a subaddress to go into a folder of the same name.

require ["variables", "envelope", "fileinto", "subaddress"];

if envelope :is :user "to" "edvil" {
  if envelope :matches :detail "to" "*" {
    set :lower "name" "${1}";
  }

  if string :is "${name}" "" {
    fileinto "INBOX";
  } else {
    fileinto "INBOX/${name}";
  }
}

Flag Messages from a Particular Person

The following filter flags all messages coming from a specific email address.

# Flag all email I receive from "importantperson@example.com"
require ["imap4flags","envelope"];
if envelope "from" "importantperson@example.com" {
  setflag "\\Flagged";
  stop;
}