Email delivery with procmail

From Zarafa wiki

Revision as of 09:17, 24 November 2010 by Ddebyttere (Talk | contribs)
Jump to: navigation, search

To deliver emails from the MTA to the Zarafa-server the delivery agent Procmail can be used. With Procmail extra serverside filtering can be done before the email is actually delivered to ZCP.

Delivery via Procmail

Create a file called .procmailrc in the users home directory. If there are virtual users present, a global +/etc/procmailrc+ file should be created.

A simple procmailrc file should contain the following lines:

:0 w
| /usr/bin/zarafa-dagent <user name>

The w after the :0 tells procmail to wait for the zarafa-dagent to finish. Typing the c flag will make a `carbon copy' of the email. This way, the email will be delivered to Zarafa as well as the normal Mailbox or Maildir. Again, <user name> needs to be replaced with the name of the user.

If there is a system wide /etc/procmailrc file and unix login names are the same as Zarafa user names, <user name> can be replaced with +$LOGNAME+.

Modify the /etc/postfix/ file, and set the +mailbox_transport+ to:

mailbox_transport = procmail:
procmail_destination_recipient_limit = 1

Add the following line to the /etc/postfix/ file:

procmail  unix  -       n       n       -       10       pipe
flags= user=vmail argv=/usr/bin/procmail -a ${user}

The vmail user should be added as a local user to the Linux system:

adduser vmail

Change the following option in the +/etc/zarafa/server.cfg+ file:

local_admin_users = root vmail

Restart the Zarafa server to activate this change.

Email delivery options

The zarafa-dagent has a lot of options when it comes to controlling the delivery location. However, in the configuration of the SMTP server, it is likely to have only one type of delivery command, without being able to set any options for special email accounts or when specific headers are present in the email.

This is where tools like procmail step in. This document uses procmail as an example. A lot of examples and documentation about procmail can be found on the internet. It also may be wise to read the procmail manual pages:

man procmail
man procmailrc
man procmailex

The procmail manual is about procmail itself. The procmailrc manual is about the config file layout and options, and the procmailex is about regular expressions which can be used in the rules to match headers.

For each zarafa-dagent option we will give an example with a procmail rule of how to use the option.

When the Zarafa users are present on the system in +/etc/passwd+, and have a home directory, a file called .procmailrc can be created in the users home directory. If there are virtual users, a global file called +procmailrc+ can be created in the +/etc+ directory.

A normal procmailrc file contains atleast the following rule:

:0 w
| /usr/bin/zarafa-dagent $1

The line starting with :0 tells procmail a new rule is starting. It also has the +w+ flag, which tells procmail when this rule is executed, it should wait for the delivery to finish before continuing. This is required to return exit codes to the MTA in case of a delivery failure of the zarafa-dagent to.

The rule has no condition, so it will always be executed. The +$USER+ variable will be replaced with the username of the user. When the zarafa-dagent has delivered the email, its exit code will be placed in the EXITCODE variable of procmail. This value will be returned to the SMTP server when procmail is done.

Junk mail delivery with Procmail

A filter for spam mail can be easily created, using the -j option of the zarafa-dagent. When this option is set the email will be delivered in the Junk mail folder instead of the Inbox. Let us set up a rule to find a spam header:

:0 w
* ^X-Spam-Status: Yes
| /usr/bin/zarafa-dagent -j $1

When the spamfilter adds the header +X-Spam-Status: Yes ... procmail will match this rule, and start the zarafa-dagent using the -j option.

The zarafa-dagent can also deliver mail into a specific folder or into a folder of the public store. For example, this can be used when email is sent to a specific email address.

:0 w
* ^TO_(info)
| /usr/bin/zarafa-dagent --public 'info mail' -C info

When an email is sent to the info address, it will be placed in the public store. The Public folders string is language dependent, so replace it if the language used is other than English. The -C flag tells the zarafa-dagent it should create the folder if it could not find it.

Personal tools