Debian 4.0 linode vps server and procmail success with smtp virtual users

After a few days of tinkering, I have finally configured things on the linode vps account so it works and does pretty everything I need.

I am using Debian 4.0. Had thought about using Ubuntu, but decided to stick with Debian as I have used it previously in the same capacity, without it failing me.

On a previous setup where I had smtp virtual accounts in the usual directory structure of;

/home/vmail/${domain}/${user}/Maildir

I was always looking for a way to have a .procmailrc for the smtp virtual accounts, and finally after a bit of research I have managed to put something together that works. I cannot give much technical details apart from the fact I can now have procmail rules for smtp virtual mail users, and also have those users even have a custom .procmailrc file that will be honoured.

I have a procmail entry in /etc/postfix/masters.cf like so below;

procmail    unix    -    n    n    -    -    pipe    flags=DRhu user=vmail argv=/usr/bin/procmail -t -m /etc/vmail-procmailrc ${recipient}

We then have the /etc/vmail-procmailrc file as below;

SHELL=/bin/sh
VERBOSE=yes
UMASK=007
ADRES=$1
ADRES=`echo $ADRES | /usr/bin/tr A-Z a-z` # force lowercase username
DOMAIN=`echo "${ADRES}" | cut -d @ -f 2 | cut -d "<" -f 2| cut -d">" -f 1| cut -d @ -f 1`
USER=`echo "${ADRES}" | cut -d @ -f 1 | cut -d "<" -f 2| cut -d">" -f1| cut -d @ -f 1` # get username for local delivery
LOGFILE=/home/procmailnew.log  # for testing & troubleshooting
INCLUDERC=/home/vmail/${DOMAIN}/${USER}/.procmailrc  # allow users to create their own recipes
#LOGNAME: ${LOGNAME}"
MAILDIR=/home/vmail/${DOMAIN}/${USER}/Maildir/

Then we have the following two lines in /etc/postfix/main.cf

procmail_destination_recipient_limit = 1
virtual_transport = procmail

And then you just drop an .procmailrc into each of the smtp virtual users home directory, one level above where the Maildir/ folder is. Since I don’t put mail into the directory based on the users name directly, I created a Maildir/ folder below it for mail.

/home/vmail/subdomain.heimic.net/username/.procmailrc

This was one problem that I never fixed when I was tinkering with this type of setup sometime back, finally I got a solution that works.

If anyone would like assistance, feel free to contact me. Always happy to help another fellow Debian/GNU Linux user.

Comments

2 responses to “Debian 4.0 linode vps server and procmail success with smtp virtual users”

  1. granroth Avatar
    granroth

    This example was absolutely invaluable. My sanity is restored again. Thank you!

    I do have a few suggestions, though:
    1. It would be handy to attach an example file or use verbatim or such. Copying the text as-is results in a number of invalid chars according to bash
    2. The USER doesn’t handle recipient_delimiter correctly since that’s not considered an alias and is thus not expanded. I got around that by using this:

    USER=`echo “${ADRES}” | cut -d @ -f 1 | cut -d “” -f 1 | cut -d @ -f 1 | cut -d . -f 1 | cut -d + -f 1`

    I use both . and + as delimiters

    3. INCLUDERC should come after MAILDIR is set so that user rc file can use that as a target

    4. A number of example recipes floating around the ‘net assume that HOME and/or DEFAULT are defined. I define them before INCLUDERC as well

    5. It’s best to put a default rule to deliver to MAILDIR at the end of this file. All of my mail sent to users without their own rc was bounced without it.

    Here’s my working copy with two “global” rules for spam:

    SHELL=/bin/sh
    VERBOSE=yes
    UMASK=007
    ADRES=$1
    ADRES=`echo $ADRES | /usr/bin/tr A-Z a-z` # force lowercase username
    DOMAIN=`echo “${ADRES}” | /bin/cut -d @ -f 2 | /bin/cut -d “” -f 1 | /bin/cut -d @ -f 1`
    USER=`echo “${ADRES}” | cut -d @ -f 1 | cut -d “” -f 1 | cut -d @ -f 1 | cut -d . -f 1 | cut -d + -f 1`
    LOGFILE=/home/vmail/filters/log
    MAILDIR=/home/vmail/${DOMAIN}/${USER}/
    HOME=/home/vmail/${DOMAIN}/${USER}
    DEFAULT=$MAILDIR
    INCLUDERC=/home/vmail/filters/${DOMAIN}/${USER}.procmailrc # allow users to create their own recipes

    :0:
    * ^X-Spam-Level: ***********
    /home/vmail/ultraspam/

    :0:
    * ^X-Spam-Flag: YES
    $HOME/.Junk/

    :0:
    $MAILDIR

    Again, thanks for your work on this!

  2. michaelf Avatar

    Thanks for the feedback/comment. In future such posts will supply examples. Unfortunately I no longer have the files associated with this configuration, as the host has since had SMTP removed. However posted about it so that I remember for next time. As it took me ages to get it working in the first place the way I wanted.

    Thanks once again for the feedback/comment.

Leave a Reply

Your email address will not be published. Required fields are marked *