Skip to content

Contact sales

By filling out this form and clicking submit, you acknowledge our privacy policy.
  • Labs icon Lab
  • A Cloud Guru
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
Labs

Path Info

Level
Clock icon Beginner
Duration
Clock icon 10m
Published
Clock icon Sep 18, 2020

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!

The Cloud Content team comprises subject matter experts hyper focused on services offered by the leading cloud vendors (AWS, GCP, and Azure), as well as cloud-related technologies such as Linux and DevOps. The team is thrilled to share their knowledge to help you build modern tech solutions from the ground up, secure and optimize your environments, and so much more!

What's a lab?

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.

Provided environment for hands-on practice

We will provide the credentials and environment necessary for you to practice right within your browser.

Guided walkthrough

Follow along with the author’s guided walkthrough and build something new in your provided environment!

Did you know?

On average, you retain 75% more of your learning if you get time for practice.

Start learning by doing today

View Plans