Mail filter and rules

You can filter your incoming mails with Sieve. Sieve scripts can be used to automatically delete or forward messages, to send autoreplies, to sort emails into folders as they arrive, to mark messages as read or flagged or to reject messages at or after delivery.

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


The spamfolder needs to be enabled to use Sieve filtering.


To create and manage scripts, you can use any tool speaking the ManageSieve protocol. Many E-Mail clients support the protocol, you can find a list of tools and plugins at You can edit your scripts in the webmailer.


We recommend the Sieve Script Editor which has a GUI to drag and drop the rules and is available for many platforms and apps.


If you need to provide access data you can use the following:


your Hostname (<something>




Your email address, including the domain


Your password for the email address


You can store as many Sieve scripts as you like but only one can be active at a time. There’s a good Sieve reference online which describes the components which make up a script.


Sort mails into folder

In this example we sort mails from a mailinglist into a folder, sort mails to *@allcolorsarebeautiful.example into another folder and lower the maximum spam score to 4.

require ["fileinto", "reject", "relational", "comparator-i;ascii-numeric"];

# Mails with a spam score greater than 4 are probably SPAM, sort them and stop
if allof (
  not header :matches "X-Rspamd-Score" "-*",
  header :value "ge" :comparator "i;ascii-numeric" "X-Rspamd-Score" "4")
    fileinto "Spam";

# Sort mails from mailinglist into folder mailinglist
if address :is "from" ["mailinglist@allcolorsarebeautiful.example", "anothermailinglist@allcolorsarebeautiful.example" ]
    fileinto "mailinglist";

# Sort mails to *@allcolorsarebeautiful.example into a special folder
if address :is :domain "to" "allcolorsarebeautiful.example"
    fileinto "important";

# Forward all incoming mails to multiple recipients
redirect "";
redirect "";

# The command "keep" is executed automatically, if no other action is taken.


stop; tells the Sieve engine to stop here, without checking for more rules.

Vacation auto reply

require ["variables", "vacation"];

if header :matches "Subject" "*" {
  set "subjwas" "${1}";


  # Reply at most once a week to a same sender
  :days 7
  :subject "Out of office ${subjwas}"
"I'm not in the office from 20 May until 31 May.

Best regards
Jane Doe";
# The command "keep" is executed automatically, if no other action is taken.

Send notification about new mails to another mail address

require ["enotify", "variables"];

# Set notification address
set "notify_address" "";

# Set from address for notification
set "notify_from" "";

# Store From and Subject in variables
if address :matches "from" "*" {
    set "from_address" "${1}";
if header :matches "subject" "*" {
    set "subject" "${1}";

# Send notification mail
notify :from "${notify_from}" :message "New mail received from: ${from_address} Subject: ${subject}" "${notify_address}";

You can find many more examples in the Dovecot Wiki.



If something does not work check the logs at ~/users/$MAILBOX/.dovecot.sieve.log. You can also use Fastmail’s Sieve Tester to test the syntax of scripts and checks what actions a script causes to the provided email message.

Mailaddress with dots


In some cases Sieve may not work with mail addresses with a dot in the local part like

Existing maildirs with a dot in the local part have a path like ~/users/my:address but Sieve expects a double colon like ~/users/my::address. The simple workaround for existing maildirs is to set a symlink:

[isabell@stardust ~/users]$ ln -s my\:address my\:\:address

Sieve will then store and read the scripts from the linked folder. For newly created mailboxes, this problem is already fixed and you dont need a workaround.


Sieve scripts are stored in the corresponding mailbox folder ~/users/$MAILBOX/sieve/. The active script is symlinked from ~/users/$MAILBOX/.dovecot.sieve:

[isabell@stardust ~/users/anna]$ readlink -f .dovecot.sieve

Dovecot will compile a ~/users/$MAILBOX/.dovecot.svbin from this script for the first mail delivered to the mailbox. It will also recompile for each new mail if the symlink or the script has been changed and the timestamp is updated. You can also trigger this by using sievec /path/to/script.sieve and check if it compiles correctly.


When using ManageSieve the scripts are compiled and validated before they are uploaded and installed by symlinking. This can prevent you from inadvertently installing a broken Sieve script.