So I have a mail server that receives junk mail and I need to forward these junk emails towards the virtual users junk folder. I have a dovecot, postfix, and spamassassin all working together, but my problem is I can't seem to figure out a way to forward the junk mail (mail titled *****SPAM*****) towards the virtual users spam/junk folder. If anyone is able to help me here with this issue that would be wonderful. If you need any information/files feel free to message me.

The system is running Ubuntu 14.04 LTS (64-bit), with dovecot, postfix, and spamasssassin.


There is many ways to do what you desire, but I'm prefer the next approach.

spamassassin is launched as local service available at file socket instead of IP port. That is for performance. exim is compiled with content-scan option and configured to interact with spamassasin that rate messages and return the score. If score is higher than threshold (49 points in my case) some special headers will be added to the message:

spamd_address           = /tmp/spamd.sock

. . . . .

accept  hosts           =  : +relay_from_hosts
accept  condition       = ${if >{$message_size}{1M}}
warn    spam            = spamd
        condition       = ${if >{$spam_score_int}{49}}
        add_header      = X-Spam-Score: $spam_score_int
        add_header      = X-Spam-Ooops: Detected
        log_message     = SpamAssassin detected mesage

I haven't check for spam messages larger than 1 MiB as far as spam is usually way smaller. Then I've deliver the message to the user's mailbox. I do that via transport through dovecot's deliver:

        driver          = pipe
        user            = mailnull
        command         = /usr/local/libexec/dovecot/deliver -d $local_part@$domain -f $sender_address
        temp_errors     = 64 : 69 : 70: 71 : 72 : 73 : 74 : 75 : 78

dovecot have a pidgeonhole plugin that implement sieve functionality. All messages are proceeded through the global filter that look like that:

require "fileinto";
if exists "X-Spam-Ooops"
   fileinto "Junk";
   # Trigger to launch next script in sequence

The logic here is straightforward: if delivered message have the X-Spam-Ooops header (assigned by exim on the sa score), it will be delivered into the INBOX.Junk subfolder for each particular user. else branch with keep verb inside is needed for further proceeding the message through the custom user's filter(s) after global filter has been proceeded.

  • Okay I understand that information, but my problem is I can't seem to get sieve to successfully connect with dovecot/postfix/spamassassin. I have really no idea as what I should do to fix this. – tripps41 Nov 7 '16 at 23:32
  • You should explain what you have already done and how services are configured. – Kondybas Nov 8 '16 at 8:38
  • If you have dovecot setup correctly, dovecot itself executes the sieve filters. There's no "getting sieve to connect with whatever". – wurtel Nov 8 '16 at 14:45
  • Pidgeonhole is a dovecot's plugin invoked at delivery time for each message. – Kondybas Nov 9 '16 at 20:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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