Dovecot – Filter Email To Folders

Dovecot logo

Dovecot Sieve is a powerful email filtering tool that allows you to automatically sort, move, or even delete emails based on predefined rules. Here’s how you can use Dovecot Sieve to filter emails based on specific criteria:

Step 1: Create a sieve script Create a new sieve script by opening a text editor and saving it as “.dovecot.sieve” in your home directory. In this script, you can define rules to filter incoming emails. In this example, we will move all emails from “[email protected]” to a folder called “INBOX.Example Folder” while keeping all other emails in the inbox.

Step 2: Define the filter criteria Using the example code provided, you can define the filter criteria as follows:

if envelope :is "from" "[email protected]" {
  fileinto "INBOX.Example\ Folder";
  stop;
} else {
  keep;
}

This code defines the criteria for filtering emails. If the envelope “from” field matches the email address “[email protected],” then the email will be moved to the “INBOX.Example Folder” and the filtering process will stop. Otherwise, the email will be kept in the inbox.

Step 3: Test the sieve script To test the sieve script, use the command:

sieve-filter -vv -C -u [email protected] .dovecot.sieve "INBOX"

This command will run the script and provide verbose output (-vv), check for syntax errors (-C), and apply the script to the inbox of the user “[email protected]” for the mailbox “INBOX.” If the script is successful, you should see the emails from “[email protected]” moved to the “INBOX.Example Folder.”

Step 4: Deploy the sieve script To deploy the sieve script, use the command:

sieve-filter -e -W -u [email protected] .dovecot.sieve "INBOX"

This command will enable the script (-e), watch for changes in the sieve script (-W), and apply the script to the inbox of the user “[email protected]” for the mailbox “INBOX.” The script will now be applied automatically to any new emails that come into the inbox.

Using Dovecot Sieve, you can create powerful filters that automatically sort and organize your emails based on specific criteria. With these simple steps, you can get started with Dovecot Sieve and take control of your inbox.

Leave a Reply

Your email address will not be published. Required fields are marked *