4

I've been searching for a resource on how to do this but not having much luck.

I am running a working MTA/MUA that is based on Postfix and Courier with MySQL as a backend for virtual users. I based my system on the following article:

https://help.ubuntu.com/community/PostfixCompleteVirtualMailSystemHowto

It was great up until the empty sections! My SMTP/IMAP setup is working great, and I managed to get SpamAssassin and ClamAV installed as well with some separate documentation I found online.

What I need help with is setting up Postfix to use Procmail as the mailbox_command so that it will work with virtual users. I want to be able to define different Procmail rules for each virtual user separately. I've read the Postfix documentation, and as I understand it the default functionality for mailbox_command will only work for local (non-virtual) users.

Thanks in advance!

UPDATE:

Since this post, I've come to realize that mailbox_command is not tenable. Instead I found a way to do this using transport_maps. Read my own answer below.

AJ.
  • 332
  • 4
  • 14

2 Answers2

0

Create one global procmailrc, and for each user make a rule like this:

:0
^TOsomeuser@yourdomain.com
| /usr/bin/procmail -m /etc/procmailrcs/someuser

The usual final rule of each file in /etc/procmailrcs/ should then be to pipe the message to deliver(8).

If you have many users and don't want to maintain a file of this nature, then instead consider writing a script that parses the mail headers to figure out which file in /etc/procmailrcs/ is wanted and executes procmail accordingly, and setting that script as your mailbox_command.

dfranke
  • 379
  • 1
  • 7
  • Thanks, but this is not a "virtual" solution. If you didn't already, please click through the link I provided in the original post. It describes a system architecture based on MySQL as a backend storage engine. All domain-specific, user-specific, and alias-specific settings are stored in this database. The ideal solution for my system would take advantage of this existing architecture. What you propose here is more of a quick-and-dirty approach. I appreciate your consideration though! – AJ. Nov 12 '10 at 01:55
  • If you're determined to stick with procmail, what I've suggested is the best you're going to do. You're asking about a piece of software that hasn't been maintained in almost 10 years. It's inherently filesystem oriented. It can run arbitrary shell commands, which means you need some real user to run them as. A more modern replacement for procmail-like functionality, readily supporting virtual-user setups, is sieve. I'm not sure of the status of Courier's support for it, though. Though if you're not wedded to Courier, consider switching to Dovecot (my choice) or Cyrus. – dfranke Nov 12 '10 at 03:03
  • Thanks for the recommendation to look at other software. I definitely intend to pursue this over the long term. – AJ. Nov 14 '10 at 17:43
0

This article was of help: http://www.linuxbackups.org/virtual-procmail.

There were two problems I had to overcome. First, the solution calls for a static file to hold the user/transport map. I need a virtual solution. So instead of creating /etc/postfix/transport, my main.cf says:

transport_maps = mysql:/etc/postfix/mysql_virtual_transport_maps.cf

Here is my mysql_virtual_transport_maps.cf:

user = ******
password = ******
hosts = 127.0.0.1
dbname = postfix
table = mailbox
select_field = transport
where_field = username

So that solved the "virtual" requirement. The other problem is my directory structure is different than the procmailrc.common example. Here is my procmailrc.common:

:0
* RECIPIENT ?? .*@\/.*$
{ DOMAIN = "$MATCH" }
#added RECIPIENT variable and we extract domain name
MAILDIR="$HOME/$DOMAIN/$USER@$DOMAIN"
DEFAULT="$MAILDIR/"
LOGFILE="./procmail.log"
VERBOSE=YES
#each user will set his own log file
NL="
"
WS=" "
SWITCHRC="$HOME/$DOMAIN/$USER@$DOMAIN/.procmail"

Hope this helps others that might be trying to do something similar.

-aj

AJ.
  • 332
  • 4
  • 14