Virtual accounts with exim and dovecot
A few people commented on my last post asking for details about how I configured exim and dovecot to have the fake scott+canonical account and separate Maildir tree.
exim4 router configuration
The first key part of the configuration is to configure exim4 to split the local part into a user name and a suffix. This allows a local part such as “scott+canonical” to be split into the user name “scott” and the suffix “+canonical”.
This is configured by adding the following two options to the appropriate routers in your exim4.conf:
local_part_suffix = +*
local_part_suffix_optional
The first option defines the suffix; normal practice appears to be to use both “+” and “-”, but since I’d previously used “-” with qmail I opted to use “+” only so that I didn’t confuse myself during the transition.
The second option allows the suffix to be optional, so that mail to “scott” is still delivered normally.
Now mail to “scott+canonical” will be delivered to the “scott” user.
Forwarding configuration
The next task is to ensure that mail is actually forwarded to this address; for me this was a configuration performed by the Canonical sysadmins to ensure that my work e-mail is actually delivered to scott+canonical on my own mail server.
Filtering configuration
Since both personal and work e-mail are now both being delivered to the same user account on my home mail server, I need to filter the mail into separate folders.
This can be done by checking the $localpartsuffix variable in Exim filter .forward files, e.g.:
# Exim filter
if $local_part_suffix is "+canonical"
then
save Maildir/Canonical/
endif
Now incoming work e-mail is filtered into a different mail folder, while personal mail is delivered into the primary one.
I’ve used similar filter instructions for mailing lists, mailman messages, Launchpad mails, etc. to filter into appropriate folders.
Where the mail is personal, it is filtered into (e.g.) Maildir/.Lists/upstart-devel/
Where the mail is for work, I add /Canonical/ to the path, (e.g.) Maildir/Canonical/.Lists/linux-hotplug-devel/
This means that the Maildir/ directory is my personal INBOX, with sub-folders immediately under that and beginning with a period; and the Maildir/Canonical/ directory is my work INBOX, with sub-folders immediately under that and beginning with a period.
This defines two trees in a manner compatible with dovecot. There’s no particular reason that Maildir/Canonical/ has to be under Maildir/, it could have been Maildir-Canonical/ and this would still work. I simply wanted them in one place to ease backups.
Dovecot configuration
Now we need to configure dovecot to permit login by a fake (”virtual”) user, with a different Maildir tree, so that I can configure them as two separate accounts.
The first set of changes is to dovecot.conf to add an additional authentication source. Modify the “auth default” block to add a new “passwd-file” passdb in addition to the “pam” passdb (or whatever your system is using).
passdb passwd-file {
args = /etc/dovecot/passwd
}
This lets us authenticate virtual users, but we also want to set their attributes, so we can use the same file as a userdb in the same “auth” block.
userdb passwd-file {
args = /etc/dovecot/passwd
}
Dovecot will now check both PAM and this file for user information.
We now simply need to add a line to this file to specify the virtual user and set up the alternate Maildir tree.
scott+canonical:PASSWORD:1000:1000::/home/scott::userdb_mail=maildir:/home/scott/Maildir/Canonical
The format is that of an ordinary passwd file; the first two parts give the passdb authentication credentials and the rest give the userdb information.
I’ve set this user to have the same uid, gid and home directory as my real “scott” user.
The final part changes the mail environment for this virtual user, instead rooting it at Maildir/Canonical/
Client configuration
The mail client will need two accounts adding; one for “scott” and the other for “scott+canonical”. It will see two separate folder trees for each account.
An unexpected bonus is that the reply account is now automatically set for me, since I’m replying from the specific account rather than from a single general one.






Tarmo Toikkanen:
Hi. Thanks for the good info. However, at least version 1.0r.c15 did not like the “+” character in the user name, and failed authentication because of that. So replacing the plus sign with something else, like a hyphen, makes things go more smoothly.
23 March 2008, 12:33 pm