I created a mailserver using this

https://www.digitalocean.com/community/tutorials/how-to-configure-a-mail-server-using-postfix-dovecot-mysql-and-spamassassin

It works, but I get tons of e-mails with proper spamassassin I get prefixed Subject e-mails like

***** SPAM ***** 2.9 ***** Do not miss,the fullyQtum Main Network Launches September 13th, 2017

But I have no idea to use Sieve to move the spam e-mails to the spam folder.

Here is my dovecot config:

auth_mechanisms = plain login
mail_location = maildir:/var/mail/vhosts/%d/%n
mail_privileged_group = mail
managesieve_notify_capability = mailto
managesieve_sieve_capability = fileinto reject envelope encoded-character vacation subaddress comparator-i;ascii-numeric relational regex imap4flags copy include variables body enotify environment mailbox date index ihave duplicate mime foreverypart extracttext
namespace inbox {
  inbox = yes
  location = 
  mailbox Drafts {
    auto = subscribe
    special_use = \Drafts
  }
  mailbox Junk {
    auto = subscribe
    special_use = \Junk
  }
  mailbox Sent {
    auto = subscribe
    special_use = \Sent
  }
  mailbox Trash {
    auto = subscribe
    special_use = \Trash
  }
  prefix = 
}
passdb {
  args = /etc/dovecot/dovecot-sql.conf.ext
  driver = sql
}
plugin {
  sieve = /etc/dovecot/sieve.conf
}
protocols = imap lmtp pop3
service auth-worker {
  user = vmail
}
service auth {
  unix_listener /var/spool/postfix/private/auth {
    group = postfix
    mode = 0666
    user = postfix
  }
  unix_listener auth-userdb {
    mode = 0666
    user = vmail
  }
  user = dovecot
}
service imap-login {
  inet_listener imap {
    port = 0
  }
  inet_listener imaps {
    port = 993
    ssl = yes
  }
}
service lmtp {
  unix_listener /var/spool/postfix/private/dovecot-lmtp {
    group = postfix
    mode = 0600
    user = postfix
  }
}
service pop3-login {
  inet_listener pop3 {
    port = 0
  }
  inet_listener pop3s {
    port = 995
    ssl = yes
  }
}
ssl = required
ssl_ca = </etc/ssl/acme/patrikx3.com/ca.cer
ssl_cert = </etc/ssl/acme/patrikx3.com/fullchain.cer
ssl_key =  # hidden, use -P to show it
userdb {
  args = uid=vmail gid=vmail home=/var/mail/vhosts/%d/%n
  driver = static
}
protocol lmtp {
  auth_socket_path = /var/run/dovecot/auth-master
  mail_plugins = " sieve"
}
  • Please provide your Dovecot configuration (doveconf -n) and the original headers of a spam mail. – Jens Erat Sep 7 '17 at 19:41
  • thanks so much for helping, I added the config in the question. – Patrik Laszlo Sep 8 '17 at 4:16
up vote 2 down vote accepted

This is how is solved it (it took 7 months):

apt install dovecot-sieve dovecot-managesieved
nano /etc/dovecot/conf.d/90-plugin.conf

Add or set in:


protocol lmtp {
        mail_plugins = $mail_plugins sieve
        auth_socket_path = /var/run/dovecot/auth-master
    }  

nano /etc/dovecot/sieve.conf

Add in:

require ["fileinto", "mailbox"];
    if header :contains "X-Spam-Flag" "YES" {
        # move mail into Folder Spam, create folder if not exists
        fileinto :create "Spam";
        stop;
    }

Execute:

sievec /etc/dovecot/sieve.conf
nano /etc/spamassassin/local.cf

Add in or set it, it's like this ( I think you don't need everythign else):

    report_safe             0
    required_score          2.0
    use_bayes               1
    use_bayes_rules         1
    bayes_auto_learn        1
    skip_rbl_checks         0
    use_razor2              1
    use_pyzor               0

    add_header all Status _YESNO_, score=_SCORE_ required=_REQD_ version=_VERSION_
    bayes_ignore_header X-Bogosity
    bayes_ignore_header X-Spam-Flag
    bayes_ignore_header X-Spam-Status

Edit a new file again:

nano /etc/dovecot/conf.d/90-sieve.conf

Set this config, you don't need anything else:

plugin {
    sieve = /etc/dovecot/sieve.conf
}

Edit the mail boxes, so jo have Junk, I think jo just need add or uncomment the Junk setting:

nano /etc/dovecot/conf.d/15-mailboxes.conf 

Add in this config:

namespace inbox {
      mailbox Drafts {
        auto = subscribe
        special_use = \Drafts
      }
      mailbox Junk {
        auto = subscribe
        special_use = \Junk
      }
      mailbox Trash {
        auto = subscribe
        special_use = \Trash
      }
      mailbox Sent {
        auto = subscribe
        special_use = \Sent
      }
    }

My user for the e-mail server is vmail, so do like this:

chmod ug+w /etc/dovecot chmod ug+w /etc/dovecot/sieve.conf.svbin

chown -R vmail:vmail /etc/dovecot

Restart your mail server:

service postfix reload && service spamassassin restart && service dovecot restart

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.