Re: [exim] Configuring Exim4 with MySQL for VirtualDomains

Top Page
Delete this message
Reply to this message
Author: Magnus Holmgren
Date:  
To: exim-users
Subject: Re: [exim] Configuring Exim4 with MySQL for VirtualDomains
On Tuesday 21 November 2006 05:19, Emilio Martin Alvarado wrote:
> My goal is to set up a mail server to support multiple domains


Let's see...

> I do this:
> 1- Create a mysql database named maildb

OK.
> 2- grant select,insert,update,delete on maildb.* to mail@localhost

Maybe it only needs select if you're only going to look up things from Exim.
> 3-flush privileges

(Only necessary if you manipulate the grant tables directly (e.g. "UPDATE
user ...").)
> 4-create table users with this (CREATE TABLE users (
>     id                    char(128) DEFAULT '' NOT NULL,
>     crypt                 char(128) DEFAULT '' NOT NULL,
>     clear                 char(128) DEFAULT '' NOT NULL,
>     name                  char(128) DEFAULT '' NOT NULL,
>     uid                   int(10) unsigned DEFAULT '65534' NOT NULL,
>     gid                   int(10) unsigned DEFAULT '65534' NOT NULL,
>     home                  char(255) DEFAULT '' NOT NULL,
>     maildir               char(255) DEFAULT '' NOT NULL,
>     quota                 char(255) DEFAULT '' NOT NULL,
>     KEY id (id(128))
> );)


Are you going to use this table as a system user database, i.e. with pam_mysql
and libnss_mysql, giving customers shell access? If not, and if you're going
to calculate the locations of the maildirs from the domain and local part,
perhaps you can make the table simpler. Also, you might want to use varchars
with a little more varied lengths. Isn't quota a number?

> 5-Create maildir with this mkdir -m 0700 Maildir; mkdir -m 0700
> Maildir/{cur,new,tmp} in this
> folder /usr/local/vdomains/mail/prueba.com/users/prueba/Maildir
> 6-Create table domains with this (CREATE TABLE domains (
>    userid char(128) NOT NULL default '',
>    KEY userid (userid)
> );)
> 7-INSERT INTO domains (userid) VALUES ("prueba.com");


If the userid column is going to hold domain names, maybe it should be
called "domain" instead.

> 8-INSERT INTO users (id, crypt, clear, name, home, maildir) VALUES (
>    "prueba@???", encrypt('abcd'), "lrepsak", "prueba",
>    "/usr/local/vdomains/mail/prueba.com/users/prueba",
>    "/usr/local/vdomains/mail/prueba.com/users/prueba/Maildir");


It's not entirely clear, but it seems that each user belongs to a domain. In
that case the users table should probably contain a domain column. Then
unless you're going to store some more per-domain information in the domains
table it becomes pretty redundant.

> Here is the problem I need to include this
>
> local_delivery:
>    driver = appendfile
>    group = mail
>    mode = 0660
>    mode_fail_narrower = false
>    envelope_to_add = true
>    return_path_add = true
>    directory = /home/${local_part}/Maildir/
>    maildir_format

>
> somewhere in Exim configuration but I don't know where and why


Well, this is a transport; it goes in the transports section. But first you
need a router. It should probably contain various mysql lookups. Such as:

vdomains:
    driver = accept
    domains = mysql;SELECT 1 FROM domains WHERE userid = \
                      '${quote_mysql:$domain}';
    local_parts = 


Well, here I don't know. The "genteba.com" in your example confuses me. But if 
you add a domain column to your users table it makes more sense. Then you'd 
say:
    local_parts = mysql;SELECT 1 FROM users \
                        WHERE domain = '{quote_mysql:$domain}' 
                          AND name = '{quote_mysql:$local_part}';


A more efficient way would be to skip the domains and local_parts
preconditions completely, and just use

    address_data = ${lookup mysql{SELECT home, maildir, uid, gid, quota \
                                 FROM users \
                                 WHERE domain = '{quote_mysql:$domain}' \
                                   AND name = '{quote_mysql:$local_part}';} \
                            {$value} fail}


If the lookup fails, the router declines. If it succeeds, the extract
expansion item can be used to put the information in the right places.

You have to read the Exim specification thoroughly, especially chapters 3, 6,
9, 11, 15, 22, 24, and 26.

> and this too
> address_directory:
>    driver = appendfile
>    no_from_hack
>    prefix = ""
>    suffix = ""
>    maildir_format


This is a different transport. You can leave it alone.

-- 
Magnus Holmgren        holmgren@???
                       (No Cc of list mail needed, thanks)