Re: [Exim] Question regarding pipe config

Top Page
Delete this message
Reply to this message
Author: Michael Scott Shappe
Date:  
To: exim-users
Subject: Re: [Exim] Question regarding pipe config
Ganbold,

First of all, I have to concur with Ruth -- you should read and understand
spec.txt (the Exim Specification), and probably several of the examples in
the FAQ as well. While they're not all directly pertinent to what you're
doing, you'll have a far easier time actually doing it if you fully
understand the how and why of Exim.

Also, depending on how much a hurry you're in, you may want to wait before
doing anything *really* fancy until the Exim Book, 2d Edition comes out, and
read and understand that as well.

That said:

> I'm new to Exim and having trouble configuring Exim 4.10. My final
> purpose is to configure Exim with mysql to support virtual users
> and domains as well as regular users.


This part is comparatively easy, actually, provided you know enough SQL. In
addition to the examples in the above-mentioned references, I recommend you
take a look at XAMS <http://www.xams.org/>, a relatively new but functional
project to provide a management interface to virtual domains. It includes
recipies for Exim routers and transports that use the database to verify
both domains and users.

> Messages will be inserted into mysql table.


Hrm...out of curiousity, why?

> saveemail.pl suppose to do above jobs.


Saveemail.pl should do nothing more than what it's name says: save e-mail.
You should use Exim routers and ACLs to determine how the mail is delivered,
and then use saveemail.pl solely as a transport, not as a router. An Exim
router can query a MySQL database quite handily (this is how XAMS+Exim
works, and I'm running that very configuration even now).

> I tried to use above but it said no such driver redirect0.


'redirect', not 'redirect0'. Dunno how the '0' got in there, but take it out :-)

> > 'all' will only get run if every other router fails.
>
> So it means that if I want to handle all messages I should put 'all' in
> first place, is that right?


You don't want it dead-first, because then it will override the routers that
determine which mail should actually be sent off-system. And you don't want
it before aliases or forwarding; you just want it before (or instead of)
localusers.

But really, you don't want a catch-all like this, at all, period. What you
want is to query the database to make sure the delivery should happen at
all. You want to do this here, not in the transport, because otherwise,
invalid addresses won't bounce from Exim, the way they ought to. So,
assuming for the moment that you have a table 'foo' that has a 'user' and a
'domain' column, something like:

zbtarouter:
  driver    = accept
  condition = ${if eq {}{${lookup mysql {SELECT user FROM foo WHERE user =
'$local_part' and domain = '$domain'}}}{no}{yes}}
  transport = zbtamail


What that rather bracket-heavy invocation says is that the router should
decline ('no') if the lookup of user and domain in the database is null. By
declining, the mail will fall through to any subsequent routers (localuser,
for example). If no useful router matches the address, the message will be
bounced.

This is basically how XAMS does it (altho' their invocation is more
convoluted, because they have multiple tables).

You then want your zbtamail transport to look like this:

zbtamail:
driver = pipe
command = ZBTAMAIL_SAVEEMAIL "$local_part" "$domain"

The PIPE driver *already* sends the message headers and body to the program
as Standard Input. Providing $local_part and $domain on the command line,
however, saves ZBTAMAIL_SAVEEMAIL the trouble of redundantly parsing the
headers (which is the wrong way to handle delivery, anyway -- delivery
should be based on *envelope*, not headers), when Exim already has the
envelope. At this point, ZBTAMAIL_SAVEEMAIL can *assume* that it's getting a
valid user and domain, and just worry about figuring out how to actually
save the e-mail.

--
Michael Scott Shappe <mikey@???>
Addicting the Unsuspecting to the Internet since 1987
Visit Radio Free Tomorrow at <http://www.radiofreetomorrow.org/>

-------------------------------------------------
This mail sent through IMP: http://horde.org/imp/