Configuring Postfix With MySQL Virtual Domains
The next steps will create the neccesary configuration files enabling Postfix to talk to MySQL so that is able to lookup virtual domains, and email boxes. Be sure to replace “postfix_complex_password” with the password chosen earlier for the MySQL postfix administrator.
Create the File : /etc/postix/mysql_virtual_domain_maps.cf
user = postfix password = postfix_complex_password hosts = 127.0.0.1 dbname = postfix query = SELECT domain \ FROM domain \ WHERE domain='%s' AND active = '1'
This file contains the SQL to query the domain table so that postfix can look up virtual domains.
Create a virtual mailbox configuration file for Postfix called
/etc/postfix/mysql_virtual_mailbox_maps.cf with the following contents. Make sure that “postfix_complex_password” is replaced by the password thats was selected for the postfix administration account. This file will return the mail directory from passing the users email address.
user = postfix password = postfix_complex_password host = 127.0.0.1 dbname = postfix query = SELECT maildir FROM mailbox WHERE username = '%s' AND active = '1'
Create a virtual alias mapping file for Postfix called /etc/postfix/mysql_virtual_alias_maps.cf. Make sure that “postfix_complex_password” is replaced by the password thats was selected for the postfix administration account. This will return the email aliases for a given email address, it works across virtual domains.
File : /etc/postfix/mysql_virtual_alias_maps.cf
user = postfix password = postfix_complex_password dbname = postfix query = SELECT goto FROM alias WHERE address = '%s' AND active = '1'
Permissions and ownership for these configuration file need to be set so that postfix can read them.
chmod o= /etc/postfix/mysql_virtual_*.cf chgrp postfix /etc/postfix/mysql_virtual_*.cf
The next thing is to create a user and group which will contain all the virtual domains mailboxes all email will be stored in this users’ home directory.
groupadd -g 5000 vmail useradd -g vmail -u 5000 -d /home/vmail -m vmail
Issuing the following commands will complete the steps required for Postfix configuration. Entering the command via the postconf command ensures that the syntax is correct during this step. Please replace ‘myhosting.com’ with the fully qualified domain name that was selected for the system mail name.
postconf -e 'myhostname = myhostname.co.uk' postconf -e 'mydestination = myhostname.co.uk, localhost, localhost.localdomain' postconf -e 'mynetworks = 127.0.0.8/8 192.168.0.0/16' postconf -e 'message_size_limit = 30720000' postconf -e 'virtual_alias_domains =' postconf -e 'virtual_alias_maps = proxy:mysql:/etc/postfix/mysql_virtual_alias_maps.cf' postconf -e 'virtual_mailbox_domains = proxy:mysql:/etc/postfix/mysql_virtual_domain_maps.cf' postconf -e 'virtual_mailbox_maps = proxy:mysql:/etc/postfix/mysql_virtual_mailbox_maps.cf' postconf -e 'virtual_mailbox_base = /home/vmail' postconf -e 'virtual_uid_maps = 5000' postconf -e 'virtual_gid_maps = 5000' postconf -e 'smtpd_sasl_auth_enable = yes' postconf -e 'broken_sasl_auth_clients = yes' postconf -e 'smtpd_sasl_authenticated_header = yes' postconf -e 'smtpd_sasl_type = dovecot' postconf -e 'smtpd_sasl_sasl_path = private/auth' postconf -e 'smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination' postconf -e 'smtpd_use_tls = yes' postconf -e 'smtpd_tls_cert_file = /etc/postfix/smtpd.cert' postconf -e 'smtpd_tls_key_file = /etc/postfix/smtpd.key'
Creating an SSL Certificate for PostFix
The following will create a selfsigned SSL certificate to be used with Postfix. This will work well, however you may want to consider using a proper signed key to avoid untrusted certificate messages appearing to users when they try and send outgoing email, via SMTP AUTH.
cd /etc/postfix openssl req -new -outform PEM -out smtpd.cert -newkey rsa:2048 -nodes -keyout smtpd.key -keyform PEM -days 365 -x509
On issuing the above command the following will be shown. Make sure to enter the fully qualified domain name that was used in the system mail name options instead of “myhost.co.uk”.
Country Name (2 letter code) [AU]:GB State or Province Name (full name) [Some-State]:Middlesex Locality Name (eg, city) :Uxbridge Organisation Name (eg, company) [Internet Widgets Pty Ltd]:CompanyName Organisational Unit Name (eg, section) :Email Common Name (eg, YOUR Name) :myhosting.co.uk Email Address :email@example.com
The appropriate permissions need to be set on the smptd.key file :
chmod o= /etc/postfix/smtpd.key
This completes creating a self-signed SSL key for use with Postfix. Next, is to configure <quote>saslauthd</quote> to used MySQL for user authentication.