you're reading...


How to use Procmail with ZCS

This article will guide you through setting up Procmail along with Zimbra Collaboration Server (ZCS). For those who do not know about procmail, it is a mail delivery agent (MDA) capable of sorting incoming mail into various directories and filtering out spam messages. The important feature of procmail is its ability to filter out incoming/outgoing mails based on regular expression, and take action upon the sorted out mail (e.g. move to a different folder, mark as spam, forward it to another address, or discard/delete it).

ZCS does not natively support Procmail, and hence there are 3 ways to use procmail with ZCS:

  1. Use ZCS with a MTA set to a server/installation with procmail configured (e.g. ZCS has a MTA set to another machine which has postfix with procmail configured and all the filtering is done by that server)
  2. Use ZCS as normal, and run procmail on your mailbox (through the procmailrc file), to do the sorting/filtering.
  3. Use ZCS with procmail as a pipe for mail delivery. (This guide will discuss this way of using procmail.)

Let’s assume:

  • The mail server with ZCS has already been installed and configured. If not, check my ZCS installation guide and install ZCS.
  • We want to use procmail to filter all emails.
  • We want to discard emails with attachments that are destined for outside of our domain (i.e. test-example.com), but allow email with attachments for inside our domain.
  • We are using a CentOS 6 machine (works on Fedora, RHEL as well).
  • sudo is configured for the user or we are executing commands as root user.

Install Procmail

sudo yum -y install procmail

Set ZCS Transport Map

  • Login as zimbra user.
su - zimbra
  • Check the currently configured transport map for postfix:
cat /opt/zimbra/postfix/conf/main.cf | grep transport_maps

The output should look like:

transport_maps = proxy:ldap:/opt/zimbra/conf/ldap-transport.cf
  • Add the transport file to the zimbra configuration.
zmlocalconfig -e postfix_transport_maps=' hash:/opt/zimbra/postfix/conf/transport,proxy:ldap:/opt/zimbra/conf/ldap-transport.cf'
Note that the second part of the value of the postfix_transport_maps key (i.e. proxy:ldap:/opt/zimbra/conf/ldap-transport.cf) is the same as the output of the previous step/command.
  • Add procmail pipe to the transport file (requires to edit the file as root user).
su -
vim /opt/zimbra/postfix/conf/transport

Add the following content to the file:

*    procmail-pipe
The above configuration means to configure the pipe of every mail (hence *). For other configuration sets, please see Postfix Manualfor details.
  • Create the db file for the transport map.
su - zimbra
postmap /opt/zimbra/postfix/conf/transport
  • For the pipe to work, a corresponding set of configuration needs to be done in the postfix’s master.cf file. In this case master.cf.in file.
vim /opt/zimbra/postfix/conf/master.cf.in

Add the following text at the end of the file:

procmail-pipe    unix    -    n    n    -    -    pipe
flags=    user=zimbra    argv=/usr/bin/procmail /opt/zimbra/procmail/procmailrc
Note that the first line does not start with white space, the second line should be just below the first line and should start with a whitespace.

Create the Procmail Recipe

  • Create the Procmail recipe file (i.e. /opt/zimbra/procmail/procmailrc file that we have configured in the previous step).
mkdir /opt/zimbra/procmail/
cd /opt/zimbra/procmail/
touch procmailrc
chown -R zimbra:zimbra .
vim procmailrc

Add the following content to the file:

SHELL = /bin/sh
MAILDIR=/opt/zimbra/procmail/ # You better make sure it exists

* !To:.*test-example\.com.*
* ! ^Content-Type:.*text/plain.*
* ^(Content-(Type|Disposition):.*|[ ]*(file)?)name=("[^"]*|[^]*)\..*
You can add your own procmail recipe in the procmailrc file depending upon what you want procmail to do. In this case we are discarding outgoing mail with attachment destined for users outside our domain.
  • Restart Postfix.
zmmtactl stop
zmmtactl start

Thanks to the Zimbra forum entry and Zimbra Wiki on Configuring Postfix to work with piped scripts from where I adapted my installation and hence wrote this guide.

Further Reading


5 Responses to “How to use Procmail with ZCS”

  1. I’ve followed your instructions to the letter but am still having issues. Procmail appears to be running correctly when I test it from the command line. That said, postfix from ZCS does not appear to be calling procmail correctly. I do have the white spaces, etc. Any thoughts?

    Posted by Simon Smith | March 6, 2015, 3:15 am
    • As mentioned in the post, while editing master.cf.in file, the first line (that is mentioned to be added) should not have any whitespace at the beginning of the line. But the line immediately after should start with a blank space.

      Posted by Abhishek Singh | March 8, 2015, 4:09 pm
  2. Hi,

    Your description is clear but I can’t get it to pipe.

    Do you also add the mailbox/alias to zimbra ?

    Ldap is in the way when checking if the mailbox exists I think.

    I hope you can help out.


    Posted by Matt | March 10, 2015, 6:39 pm
  3. Hi,
    on ZCS 8.6 i can’t make it work.
    postfix_transport_maps is now a variable in Global Config, and hash: is not supported anymore, I had to use lmdb:
    It seems that the procmail-pipe is just ignored.

    Posted by gab | April 7, 2016, 6:35 pm


  1. […] not sure of what went wrong in the previous attempt. Now that I've jotted down the configuration at How to use Procmail with ZCS | asingh. Thanks for you […]

Post a Comment