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:
- 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)
- Use ZCS as normal, and run procmail on your mailbox (through the procmailrc file), to do the sorting/filtering.
- 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'
- 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
- 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
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
PATH=$HOME/bin:/usr/bin:/bin:.
MAILDIR=/opt/zimbra/procmail/ # You better make sure it exists
DEFAULT=$MAILDIR
LOGFILE=.procmaillog
LOCKFILE=.procmaillock
VERBOSE=yes
:0
* !To:.*test-example\.com.*
* ! ^Content-Type:.*text/plain.*
{
:0B
* ^(Content-(Type|Disposition):.*|[ ]*(file)?)name=("[^"]*|[^]*)\..*
/dev/null
}
- 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.

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 amAs 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 pmHi,
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.
Matt
Posted by Matt | March 10, 2015, 6:39 pmHi,
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