BSD Stuff


Postfix, Courier-IMAP, MySQL, SASL2 and PostfixAdmin

12 September 2006, 09:33

I made this howto so that when and if I have to set up another Email server I can follow some basic steps. This howto is made for FreeBSD systems but can easily be ported to any Unix type Operating Systems.
The idea behind this setup was to use Postfix, Courier-IMAP and MySQL with PostfixAdmin to administrate the email accounts on my server. I’m also using a virtual mail setup because I don’t feel there’s a need to create a users account for every email account I add. Of course when the user wants to use an email client like Mozilla Thunderbird then I have to create an user account other wise the client will not be able to send emails because it can’t authenticate.

I just want to thank the two poeple who created there own howtos which I used to make my own.

  1. Postfix+MySQL+Courier-IMAP by Phil Pereira and
  2. Postfix+MySQL+Courier-IMAP by Mischa Peters

So lets start

I will assume that we already have Apache, PHP MySQL installed and working.
Also make sure that your ports tree is up to date.

Installing PostfixAdmin

We will use PostfixAdmin to administrate our mail server. So we will install it first.

# cd /usr/ports/mail/postfixadmin/
# make install clean

Now we need to add the alias directory under apache.

# cd /usr/local/etc/apache22/extra/
# vim httpd-autoindex.conf
#Code
0001Alias /postfixadmin "/usr/local/www/postfixadmin/"
0002 
0003<Directory "/usr/local/www/postfixadmin">
0004Options Indexes
0005AllowOverride AuthConfig
0006Allow from all
0007</Directory>

Next we need to edit the config.inc.php file and change the following.

# cd /usr/local/www/postfixadmin/
# vim config.inc.php
#Code
0001// Postfix Admin Path
0002// Set the location to your Postfix Admin installation here.
0003$CONF['postfix_admin_url'] = 'http://www.example.com/postfixadmin/admin';
0004$CONF['postfix_admin_path'] = '/postfixadmin/admin';
0005 
0006// Database Config
0007// mysql = MySQL 3.23 and 4.0
0008// mysqli = MySQL 4.1
0009// pgsql = PostgreSQL
0010$CONF['database_type'] = 'mysqli';
0011$CONF['database_host'] = 'localhost';
0012$CONF['database_user'] = 'dbuser';
0013$CONF['database_password'] = 'passwd';
0014$CONF['database_name'] = 'postfix';
0015$CONF['database_prefix'] = '';
0016 
0017// Site Admin
0018// Define the Site Admins email address below.
0019// This will be used to send emails from to create mailboxes.
0020$CONF['admin_email'] = 'postmaster@';
0021 
0022// Default Aliases
0023// The default aliases that need to be created for all domains.
0024$CONF['default_aliases'] = array (
0025'abuse' => 'abuse@example.com',
0026'hostmaster' => 'hostmaster@example.com',
0027'postmaster' => 'postmaster@example.com',
0028'webmaster' => 'webmaster@example.com'
0029);
0030 
0031// Default Domain Values
0032// Specify your default values below. Quota in MB.
0033$CONF['aliases'] = '100';
0034$CONF['mailboxes'] = '100';
0035$CONF['maxquota'] = '100';
0036 
0037// Footer
0038// Below information will be on all pages.
0039// If you don't want the footer information to appear set this to 'NO'.
0040$CONF['show_footer_text'] = 'YES';
0041$CONF['footer_text'] = 'Return to example.com';
0042$CONF['footer_link'] = 'http://www.example.com';

Now we will add the database to MySQL and edit the DATABASE_MYSQL.TXT

# vim DATABASE_MYSQL.TXT
#Code
0001# Postfix user & password
0002INSERT INTO user (Host, User, Password) VALUES ('localhost','dbuser',password('passwd'));
0003INSERT INTO db (Host, Db, User, Select_priv) VALUES ('localhost','postfix','dbuser','Y');
0004 
0005# Postfix Admin user & password
0006INSERT INTO user (Host, User, Password) VALUES ('localhost','dbuseradmin',password('passwd'));
0007INSERT INTO db (Host, Db, User, Select_priv, Insert_priv, Update_priv, Delete_priv) VALUES ('localhost', 'postfix', 'dbuseradmin', 'Y', 'Y', 'Y', 'Y');
0008FLUSH PRIVILEGES;
0009GRANT USAGE ON postfix.* TO dbuser@localhost;
0010GRANT SELECT, INSERT, DELETE, UPDATE ON postfix.* TO dbuser@localhost;
0011GRANT USAGE ON postfix.* TO dbuseradmin@localhost;
0012GRANT SELECT, INSERT, DELETE, UPDATE ON postfix.* TO dbuseradmin@localhost;

Do not delete the setup.php file yet we will need to add the domains and mail boxes first.
Now we can create the database from the shell with the following command.

# mysql -u root -p < DATABASE_MYSQL.TXT
Enter password:

Now that we installed PostfixAdmin we can go and install Postfix.

Page 1 of 6