[ start | index | login ]
start > knowledgebase > linux > mail > postfixadmin on debian sarge

postfixadmin on debian sarge

Created by kron. Last edited by kron, one year and 265 days ago. Viewed 41,178 times. #16
[diff] [history] [edit] [rdf]
labels
attachments
>>Postfix Admin is a web-based GUI for setting up mail users for a Postfix+MySQL setup.

It will let you create users and aliases per domain.

This HOWTO goes over install Postfix Admin, Postfix with a MySQL backend and SMTP auth enabled, and Dovecot (for POP3/POP3/IMAP/IMAPS) with a MySQL backend.

While this HOWTO is based on Debian Sarge, the Postfix/MySQL setup is generic and should work fine on most distributions.

If you're after per-user spam and virus filtering for your virtual users, see the howto here: >>http://bliki.rimuhosting.com/space/knowledgebase/linux/mail/postfix+with+amavis+and+mysql

Grab the Postfix Admin tarball and unpack it:

wget "http://high5.net/page7_files/postfixadmin-2.1.0.tgz"
tar xvzf postfixadmin-2.1.0.tgz

Edit the database schema to how you want it (e.g. change the default passwords, database name, etc)

cd postfixadmin-2.1.0
vi DATABASE_MYSQL.TXT

Setup the datatabase:

mysql -u root -p < DATABASE_MYSQL.TXT

Setup Postfix Admin. Copy its files to your Document Root for Apache to serve, e.g. /var/www/apache2-default under a default Sarge setup

cd ..
cp -r postfixadmin-2.1.0 /var/www/
mv /var/www/apache2-default/postfixadmin-2.1.0 /var/www/postfixadmin
cd /var/www/postfixadmin/
mv config.inc.php.sample config.inc.php

Configure Postfix Admin to match your setup (e.g. to make the database passwords match, set your default domain, etc)

vi config.inc.php

Or to quickly change the default domain to your own:

replace "change-this-to-your.domain.tld" "yourdomain.com" -- config.inc.php

Also set these variables, to simplify things:

$CONF['domain_path'] = 'YES';
$CONF['domain_in_mailbox'] = 'NO';
$CONF['encrypt'] = 'cleartext';

Change the permissions on the postfixadmin directory if you don't want any local users accessing it:

chown -R www-data:www-data postfixadmin
chmod -R 700 postfixadmin

Then browse to >>http://yourdomain.com/postfixadmin/ or >>http://yourip/postfixadmin/. It will prompt you to run Setup. Make sure the Setup Checker says 'OK' for everything.

Remove the setup.php as it recommends.

Setup the .htaccess by changing the path of the .htpasswd file to /var/www/postfixadmin/admin/.htpasswd, and set an admin password

cd admin/
vi .htaccess
htpasswd .htpasswd admin

Then browse to >>http://yourdomain.com/postfixadmin/admin. You should get prompted. Login as 'admin' with your newly created password. From here you can add domains, mailboxes, etc. But Postfix won't see these yet. We need to install Postfix, and configure it.

Install Postfix, SASL2 with MySQL support

apt-get install postfix-mysql postfix-tls libsasl2-modules-sql libsasl2-modules

Add the following to /etc/postfix/main.cf

virtual_alias_maps = mysql:/etc/postfix/mysql_virtual_alias_maps.cf
virtual_gid_maps = static:106
virtual_mailbox_base = /home/vmail
virtual_mailbox_domains = mysql:/etc/postfix/mysql_virtual_domains_maps.cf
virtual_mailbox_maps = mysql:/etc/postfix/mysql_virtual_mailbox_maps.cf
virtual_minimum_uid = 106
virtual_transport = virtual
virtual_uid_maps = static:106

broken_sasl_auth_clients = yes smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_non_fqdn_hostname, reject_non_fqdn_sender, reject_non_fqdn_recipient, reject_unauth_destination, reject_unauth_pipelining, reject_invalid_hostname smtpd_sasl_auth_enable = yes smtpd_sasl_local_domain = $myhostname smtpd_sasl_security_options = noanonymous

Create the following files in /etc/postfix/:

mysql_virtual_alias_maps.cf

user = postfix
password = postfix
hosts = localhost
dbname = postfix
table = alias
select_field = goto
where_field = address

mysql_virtual_domains_maps.cf

user = postfix
password = postfix
hosts = localhost
dbname = postfix
table = domain
select_field = domain
where_field = domain
additional_conditions = and backupmx = '0' and active = '1'

mysql_virtual_mailbox_maps.cf

user = postfix
password = postfix
hosts = localhost
dbname = postfix
table = mailbox
select_field = maildir
where_field = username

If you want to be be able to relay mail through your server with SMTP AUTH, setup the following in /etc/postfix/sasl/smtpd.conf:

pwcheck_method: auxprop
mech_list: PLAIN LOGIN
auxprop_plugin: sql
sql_verbose: yes
sql_engine: mysql
sql_hostnames: localhost
sql_user: postfix
sql_passwd: postfix
sql_database: postfix
sql_select: select password from mailbox where username = '%u@%r'

Create the directory structure, including a directory for the first domain. You'll also want to go into PostfixAdmin and create a 'test' account for the yourdomain.com to match this.

mkdir -p /home/vmail/yourdomain.com/test
chmod -R 770 /home/vmail
chown -R postfix:postfix /home/vmail/

Install Dovecot with MySQL support

apt-get install dovecot dovecot-common dovecot-imapd dovecot-pop3d

Configure the Dovecot/MySQL setup in /etc/dovecot/dovecot-mysql.conf using these settings:

db_host = 127.0.0.1
db_port = 3306
db = postfix
db_user = postfix
db_passwd = postfix
db_client_flags = 0
default_pass_scheme = PLAIN
password_query = SELECT password FROM mailbox WHERE username = '%u'
user_query = SELECT maildir, 106 AS uid, 106 AS gid FROM mailbox WHERE username = '%u'

Then configure Dovecot to use MySQL by setting these options in /etc/dovecot/dovecot.conf:

auth_userdb = mysql /etc/dovecot/dovecot-mysql.conf
auth_passdb = mysql /etc/dovecot/dovecot-mysql.conf
first_valid_uid = 106
default_mail_env = maildir:/home/vmail/%d/%n

Also setup which protocols you want it to handle (you'll need regular IMAP for most webmail packages):

protocols =  imaps imap pop3s pop3

Restart Dovecot and Postfix and test it all out.

Note: UID/GID 106 may be different on your system. Check your postfix (or vmail) user in /etc/passwd and set accordingly.

At the end of it, you should be able to add new domains, mailboxes and aliases using PostfixAdmin and have it all work properly, including SMTP authentication. Note that you don't need saslauthd for SMTP authentication to work.

no comments | post comment
Powered by snipsnap.org Found a mistake in a howto? Let us know via an email to p.blikibugs at rimuhosting com.