Featured resource
2025 Tech Upskilling Playbook
Tech Upskilling Playbook

Build future-ready tech teams and hit key business milestones with seven proven plays from industry leaders.

Check it out
  • Lab
    • Libraries: If you want this lab, consider one of these libraries.
    • Cloud
Google Cloud Platform icon
Labs

Email Services: Filter and Sort with Sieve

Filtering email will prevent you from having an Inbox with 700 messages all clamoring for your attention. Using a tool like Sieve, you can have your work emails sorted into a Work folder, spam emails automatically deleted, and personal emails sorted into a Personal folder for you to look at when you have time. This lab will let you practice how to install and configure Sieve to filter emails.

Google Cloud Platform icon
Lab platform
Lab Info
Level
Beginner
Last updated
Apr 06, 2025
Duration
10m

Contact sales

By filling out this form and clicking submit, you acknowledge our privacy policy.
Table of Contents
  1. Challenge

    Install and configure Sieve

    Our first step is to edit:

    vim /etc/dovecot/conf.d/15-lda.conf
    

    Find the protocol lda section and ensure it looks like this:

    protocol lda {
      # Space separated list of plugins to load (default is global mail_plugins).
      mail_plugins = sieve
    }
    

    Now configure postfix:

    vim /etc/postfix/main.cf 
    

    Find the mailbox_command setting and set it to use the dovecot specific delivery binary:

    mailbox_command = /usr/libexec/dovecot/deliver
    

    Install Sieve:

    yum install dovecot-pigeonhole -y
    
    vim /etc/dovecot/conf.d/90-plugin.conf
    

    Set the plugin up like so:

    plugin {
      # setting_name = value
        sieve=~/.dovecot.sieve
        sieve_dir = ~/sieve
        sieve_global_dir = /home/sieve
        sieve_max_script_size = 1M
    }
    

    Now we need to edit dovecot's config again:

    vim /etc/dovecot/dovecot.conf
    

    The protocols line should include the sieve plugin:

    protocols = imap sieve
    

    Edit the 20-managesieve.conf file and uncomment the following lines:

    vim /etc/dovecot/conf.d/20-managesieve.conf
    
    service managesieve-login {
      inet_listener sieve {
        port = 4190
      }
    

    Now we can build our Sieve script:

    vim /home/test_user/.dovecot.sieve
    

    Your script should look something like this:

    require "fileinto";
    
    if header :contains "Subject" "WORK" {
            fileinto "Work";
    }
    

    Restart postfix and dovecot:

    systemctl restart postfix
    systemctl restart dovecot
    

    Sieve is configured!

  2. Challenge

    Test your Sieve script
    1. To test your sieve script, you should send a test email.
    telnet localhost 25
    Trying ::1...
    Connected to localhost.
    Escape character is '^]'.
    220 server1.example.com ESMTP Postfix
    ehlo localhost
    250-server1.example.com
    250-PIPELINING
    250-SIZE 10240000
    250-VRFY
    250-ETRN
    250-ENHANCEDSTATUSCODES
    250-8BITMIME
    250 DSN
    mail from: [email protected]
    250 2.1.0 Ok
    rcpt to: [email protected]
    250 2.1.5 Ok
    data
    354 End data with <CR><LF>.<CR><LF>
    Subject: WORK
    .
    250 2.0.0 Ok: queued as 3CA4197CBF
    
    1. Once sent, copy the message ID (the number after "queued as" above) and use it to grep the mail log:
    [root@server1 test_user]# grep 3CA4197CBF /var/log/maillog
    Jun  8 06:22:53 server1 postfix/smtpd[12092]: 3CA4197CBF: client=localhost[::1]
    Jun  8 06:22:59 server1 postfix/cleanup[12096]: 3CA4197CBF: message-id=<[email protected]>
    Jun  8 06:22:59 server1 postfix/qmgr[1670]: 3CA4197CBF: from=<[email protected]>, size=323, nrcpt=1 (queue active)
    Jun  8 06:22:59 server1 dovecot: lda(test_user): sieve: msgid=<[email protected]>: stored mail into mailbox 'Work'
    Jun  8 06:22:59 server1 postfix/local[12097]: 3CA4197CBF: to=<[email protected]>, relay=local, delay=16, delays=16/0.01/0/0.08, dsn=2.0.0, status=sent (delivered to command: /usr/libexec/dovecot/deliver)
    Jun  8 06:22:59 server1 postfix/qmgr[1670]: 3CA4197CBF: removed
    

    As you can see, the 4th line indicates that Sieve sorted the email into the correct folder. Congratulations!

About the author

Pluralsight Skills gives leaders confidence they have the skills needed to execute technology strategy. Technology teams can benchmark expertise across roles, speed up release cycles and build reliable, secure products. By leveraging our expert content, skill assessments and one-of-a-kind analytics, keep up with the pace of change, put the right people on the right projects and boost productivity. It's the most effective path to developing tech skills at scale.

Real skill practice before real-world application

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Learn by doing

Engage hands-on with the tools and technologies you’re learning. You pick the skill, we provide the credentials and environment.

Follow your guide

All labs have detailed instructions and objectives, guiding you through the learning process and ensuring you understand every step.

Turn time into mastery

On average, you retain 75% more of your learning if you take time to practice. Hands-on labs set you up for success to make those skills stick.

Get started with Pluralsight