Re: [exim] database-driven forwarding

Startseite
Nachricht löschen
Nachricht beantworten
Autor: Mike Richardson
Datum:  
To: exim-users
Betreff: Re: [exim] database-driven forwarding
On Fri, Sep 15, 2006 at 03:02:40PM -0700, Rick Toews wrote:
> What I want to do is provide email forwarding to user ID's found in a
> database table. Currently, emails are forwarded based on the contents of
> the text file /etc/valiases/{$domain}. I can run a script that will build
> this file using the information in the database, and this script can be
> set up as a cron job. Practically, this solution would, I think, work
> just fine for what I need.
>
> On the other hand, I would like to be able to configure Exim to forward
> emails based on the actual content of the database, not on the static file
> in the valiases directory. I use Exim under cPanel, so it's not
> configured for MySQL lookups; however, I had thought that I could still
> get a data from a MySQL database simply by using a perl subroutine. Is
> this possible? I've been experimenting with approaches as basic as simply
> trying to get Exim to use data from a forwarding file other than
> /etc/valiases/{$domain}, and the results have not been encouraging.


I've no experience with cPanel but forwarding based on database entry is
perfectly possible both with a straight DB query and using perl.

For the straight DB stuff I use a standard redirect router with this in:

driver = redirect
data = ${lookup mysql{select recipient from forward where username='$local_part' and active=1}}

where 'active' is a field set by the web interface I wrote (yep, yet another
web config tool for exim :-) and simply indicates if forwarding is enabled
or not. Multiple addresses can be entered into the DB and it forward to all
of them.

The nasty bit which I'm ashamed to post is:

  unseen =  \
        ${if    \
          ==    \
          {     \
                ${lookup mysql{select value from prefs where username='$local_part' and preference='forward_keep_copy'}{$value}{0}} \
          }     \
          {1}   \
          {true}        \
          {false}       \
         }


I'm sure it can be done more simply but I've not figured out how yet. This
decides whether or not the mail is delivered to the account or just
forwarded.

As for the perl stuff put something like this:

perl_startup = do '/etc/exim4/perl_exim.pl'

at the start of the config and a subroutine later something like this:

driver = redirect
data = ${perl{user_filter}{$local_part}{$home}}

where, in this case 'user_filter' is the name of the subroutine and
$local_part and $home are two parameters being passed.

Round it off with breakfast at Milliways.

Mike
--
Mike Richardson
Networks
IT Services, University of Manchester
Email: doctor@???
*Plain text only please - attachments stripped on arrival*