Wow! After a lot of work, Exim is finally configured exactly how I want it to handle multiple domains. Well, not exactly. I haven't implemented the MySQL portions yet. However, I've written them, and I'm pretty sure they work. I decided that I wanted mail to be able to function with or without MySQL, with a preference to the MySQL information. This way, if you're like me and like editing configuration files by hand, you can. Here's how it works.
Every domain that can receive mail must have a directory in /var/sites/ named the same thing as the mail domain. This is because, due to the virtual nature of all of the mail functions, each domain needs it's own spool directory. Inside of /var/sites/domain.com/ there must exist a directory called mail as this is where the mail spool goes. /var/sites/users holds domain to system user information. This allows exim to be the right user when it delivers mail for each user. This makes the system more secure… I think. It also provides a user to become when performing pipe operations and the like. Each user account that exists for a domain must have a directory with the name of that user in /var/sites/domain.com/mail/. This is because I choose to use MailDir for message delivery and it needs a directory to store mail in. In actuality, the users Inbox will be at /var/sites/domain.com/mail/username/INBOX/, allowing IMAP users to store other folders in the same location. If a /var/sites/domain.com/aliases file exists, it can be used to look up forwards, pipes, and mailing lists. If /var/sites/domain.com/mail/username/filters exists, exim will process it like a .forward file, or an Exim filter file. If /var/sites/domain.com/mail/username/.procmailrc exists, procmail will process the mail (I'm not sure if this part works or not… it's untested). If mail is addressed with a prefix of real- to ANY address, it bypasses any filters or procmail files. This allows the mail system to inform the user of an error in those files without those messages being processed by the offending files.
When I uncomment the MySQL lines, it should allow me to have a MySQL database with two tables. One will be called "domains" with two fields: owner and domain. It will serve the purpose of the /var/sites/users file. Another table called "aliases" will have three fields: user, domain, and alias. It will serve the purpose of the /var/sites/domain.com/aliases file.
This setup shold provide the ultimate in security, flexibility, and features. Take a look at my exim.conf file if you're interested in how it was done.
Even though it was a lot of work (as I didn't really know much about Exim before today), I really like Exim. Once you get used to it, it just makes sense. Their ${lookup style notation is a little… hard to read, but you get used to it after a while.
Next step… set up courier to read these directories. Isn't this fun?