Full Mail Server Solution w/ Virtual Domains & Users - Page 04 (Postfix on the MX Servers - Virtual Users)

Want to support HowtoForge? Become a subscriber!
 
Submitted by Vecter (Contact Author) (Forums) on Wed, 2007-10-17 20:28. ::

B. Setting up Postfix for Virtual Users & Domains

Even though the mail exchangers won't be delivering mail to the virtual users and domains, they will be rejecting based on valid/invalid destinations. We therefore need the mx servers to be able to connect to the SQL server to verify destinaions. Go ahead and put the information into postconf:

# postconf -e 'virtual_alias_domains ='
# postconf -e 'virtual_alias_maps = proxy:mysql:$config_directory/mysql_virtual_alias_maps.cf'
# postconf -e 'virtual_mailbox_domains = proxy:mysql:$config_directory/mysql_virtual_domains_maps.cf'
# postconf -e 'virtual_mailbox_maps = proxy:mysql:$config_directory/mysql_virtual_mailbox_maps.cf'
# postconf -e 'virtual_mailbox_base = /vmail'
# postconf -e 'virtual_minimum_uid = 150'
# postconf -e 'virtual_uid_maps = static:150'
# postconf -e 'virtual_gid_maps = static:8'
# postconf -e 'virtual_create_maildirsize = yes'
# postconf -e 'virtual_mailbox_extended = yes'
# postconf -e 'virtual_mailbox_limit_maps = proxy:mysql:/etc/postfix/mysql_virtual_mailbox_limit_maps.cf'
# postconf -e 'virtual_mailbox_limit_override = yes'
# postconf -e 'virtual_maildir_limit_message = "The user you are trying to reach has exceeded their quota."'
# postconf -e 'virtual_overquota_bounce = yes'
# postconf -e 'transport_maps = proxy:mysql:/etc/postfix/mysql_virtual_transports.cf'

There are several 'gotchas' here. This configuration will host the virtual user mailboxes in /vmail. Should you need to store your mailboxes in another location, change the virtual_mailbox_base line accordingly.

The virtual_minimum_uid and virtual_uid_maps point to user id 150. This user id is for a specifically create "Virtual Mail" user. It uses the standard "mail" group, with the default (Debian) gid of 8. You can create the user and directory like this:

# useradd -r -u 150 -g mail -d /var/vmail -s /sbin/nologin -c "Virtual Mailbox" vmail
# mkdir /var/vmail
# chmod 770 /var/vmail/
# chown vmail:mail /var/vmail/

Now we need to install the NFS client tools:

# apt-get install nfs-common portmap

The directory then needs to be mounted to the NFS share. To do a simple test, run the following:

# mount files-1.internal.example.com:/vmail /vmail

You should now have access to the /vmail share from files-1. Try writing a file (It shouldn't work!):

# cd /vmail
# touch tmp

NOTE: You should get a read-only error!

Assuming everything is working, go ahead and unmount the NFS:

# cd /
umount /vmail

And then make the mount permanent by putting the following into your /etc/fstab:

[...]
files-1.internal.example.com:/vmail /vmail nfs ro,rsize=4096,hard,intr,tcp,noatime,nodev,async 0 0

Go ahead and mount the file system one last time:

# mount /vmail

... and you're good to go!

C. Postfix MySQL Configuration

Postfix was installed with MySQL support, but that doesn't mean it already knows how to use our database. It needs to be provided with various SQL-query information for each type of table in our database. This information is stored in the MySQL files defined in the main.cf file. Note that in the following files, the last line contains a single comment (Preceeded by #) with the full query. Recent versions of Postfix can use this instead of the other statements. If you're using a newer version, just comment out all of the other lines, and uncomment the query statement.

/etc/postfix/mysql_virtual_alias_maps.cf

user = vmail_user
password = vmail_user_password
hosts = sql-1.internal.example.com
dbname = virtual_mail
table = alias
select_field = goto
where_field = address
additional_conditions = and active = '1'
#query = SELECT goto FROM alias WHERE address='%s' AND active = '1'

/etc/postfix/mysql_virtual_domains_maps.cf

user = vmail_user
password = vmail_user_password
hosts = sql-1.internal.example.com
dbname = virtual_mail
table = domain
select_field = domain
where_field = domain
additional_conditions = and backupmx = ‘0′ and active = ‘1′
#query = SELECT domain FROM domain WHERE domain=’%s’ AND backupmx = ‘0′ AND active = ‘1′

/etc/postfix/mysql_virtual_mailbox_limit_maps.cf

user = vmail_user
password = vmail_user_password
hosts = sql-1.internal.example.com
dbname = virtual_mail
table = mailbox
select_field = quota
where_field = username
additional_conditions = and active = ‘1′
#query = SELECT quota FROM mailbox WHERE username=’%s’ AND active = ‘1′

/etc/postfix/mysql_virtual_mailbox_maps.cf

user = vmail_user
password = vmail_user_password
hosts = sql-1.internal.example.com
dbname = virtual_mail
table = mailbox
select_field = CONCAT(domain,’/',maildir)
where_field = username
additional_conditions = and active = ‘1′
#query = SELECT CONCAT(domain,’/',maildir) FROM mailbox WHERE username=’%s’ AND active = ‘1′

/etc/postfix/mysql_virtual_transports.cf

user = vmail_user
password = vmail_user_password
hosts = sql-1.internal.example.com
dbname = virtual_mail
table = domain
select_field = transport
where_field = domain
additional_conditions = and active = ‘1′
#query = SELECT transport FROM domain WHERE domain=’%s’ AND active = ‘1′

Please do not use the comment function to ask for help! If you need help, please use our forum.
Comments will be published after administrator approval.