This article describes how to use a text file or static db file as the source for user accounts in Postfix and Dovecot. This is suitable for very simple mail account requirements. For larger implementations, check out the MySQL virtual accounts or Active Directory/LDAP virtual accounts.

Create the Virtual Mail User Account

Create user vmail1. Create a new user, we will call it vmail. Change the Login Shell to /sbin/nologin, this user account should not be used for logging in. Learn how to use the User Manager application here.
User Manager2. Take note of the User ID and Home Directory of vmail.
User Manager3. Click the Groups tab and now note down the Group ID of vmail. We’ll be needing all of them later.

Configure Postfix for Virtual User Accounts

Edit main.cf1. Edit the postfix configuration file /etc/postfix/main.cf and edit the line below
mydestination = $myhostname, localhost.$mydomain, localhost

and add the lines below

virtual_mailbox_domains = $mydomain
virtual_mailbox_base = /home/vmail/
virtual_mailbox_maps = hash:/etc/postfix/vmailbox
virtual_uid_maps = static:501
virtual_gid_maps = static:501

virtual_mailbox_base, virtual_uid_maps and virtual_gid_maps should contain the home directory, user id and group id of vmail respectively.

Edit main.cf2. Create the file /etc/postfix/vmailbox containing the mapping from an email address to a mailbox path relative to virtual_mailbox_base. See the example below.
johndoe@acme.local johndoe/Maildir/
janedoe@acme.local janedoe/Maildir/
postmap vmailbox
3. Type in the command below to generate the static db that will be used for the lookup.
postmap /etc/postfix/vmailbox
Service Configuration4. Restart the Postfix or MailScanner service if you have installed MailScanner. Learn how to start and stop services here.
Terminal5. Try sending an email. See Test Postfix using Telnet. New mails should now be stored under the path specified in virtual_mailbox_base.

Configure Dovecot Virtual User Accounts

Edit dovecot.conf1. Edit the file /etc/dovecot.conf and change the value of the following keys below
passdb static {
  args = /etc/dovecot-passdb
}

userdb static {
  args = uid=501 gid=501 home=/home/vmail/%u
}

uid, gid and home should contain the user id, group id and home directory respectively of the vmail user account.

NoteMake sure comment out all the other passdb and userdb sections to avoid any conflicts.
Edit dovecot-passdb2. Create the file /etc/dovecot-passdb containing the password of a user name. See the example below.
johndoe:{PLAIN}secret
janedoe:{HMAC-MD5}dd59f669267e9bb13d42a1ba57c972c5b13a4b2ae457c9ada803dc7d8bae4ab
NoteYou can generate a hash password using the dovecotpw command.
Service Configuration3. Restart the dovecot service. Learn how to start and stop services here.
Terminal4. Test Dovecot using Telnet. You should be able to read the recently sent mail which was stored in a new location.

Visit the forum to ask for help or to give a comment.

***
Posted on 5/29/2010 and last updated on 5/29/2010
Filed under Dovecot , Postfix