Qmail + Procmail Mini HowTo

First of all, we need a small wrapper script to convert procmail's exit codes to ones understood by Qmail:

/var/qmail/bin/preline /usr/bin/procmail && exit 0
# check if procmail returned EX_TEMPFAIL (75)
[ $? -eq 75 ] && exit 111
# do we want to discard the message?
[ $? -eq 99 ] && exit 99
# otherwise return a permanent error
exit 100

I'd recommend to put this wrapper to ~/bin/ and name it, say, procmail-wrapper.sh. Don't forget to make it executable :).

Now, it's time to create your ~/.procmailrc. In the example below procmail will forward any messages arriving on mailing lists from lists.server.tld or on other@role.address to my dedicated e-mail box (my.mailbox@for.urgent.messages) if message contains URGENT in its Subject line or if it was explicitly designated to me. Since the dedicated e-mail box is bound to my mobile I'll get notifications when my attention is urgently needed at some of the mailing lists:

:0 H
* ^Subject:.*(URGENT|[Aa][Ss][Aa][Pp])
! my.mailbox@for.urgent.messages
:0 H
* ^TO_(@lists\.server\.tld|other@role\.address)
* ^TO_galaxy@
! my.mailbox@for.urgent.messages
# deliver the message normally

NOTE: in this configuration procmail does NOT return messages back to Qmail and it should not! If we want to discard a message we need to return EXITCODE=99 to Qmail, and if we want to bounce messages back, then EXITCODE should be 100.

OK, our ~/.procmailrc is ready and we need to insert the procmail-wrapper.sh script into the desirable .qmail-* file:

server!galaxy:~$ cat .qmail-galaxy

The first line here is just for illustration purposes that we can filter mail with some other scripts before our procmail-wrapper.sh is called. The last line is the default mailbox where Qmail will deliver messages if procmail-wrapper.sh returns 0.

internal/email/qmail-procmail.txt · Last modified: 2009/10/22 00:42 by galaxy
Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Noncommercial-Share Alike 3.0 Unported
Recent changes RSS feed Donate to DokuWiki Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki Powered by OpenVZ Powered by Openwall GNU/*/Linux