Main Menu
Home
Search
Support
How To's
OpenWiki
Contact Us
Users Blogs
User HowTo's
Announcements
Google Translation

 

 

 

 

MySQL users, PostfixAdmin, Postfix, Dovecot & SquirrelMail with userprefs stored in mySQL PDF Print E-mail
User Rating: / 0
PoorBest 
Written by Paul Matthews   

MySQL users, Postfix, Dovecot & SquirrelMail with userprefs stored in mySQL

Name: MySQL
HomePage: http://www.mysql.com/
function: MySQL, the most popular Open Source SQL database

Name: Dovecot
HomePage: http://dovecot.org/
function: Dovecot is an open source IMAP and POP3 server for Linux/UNIX-like systems, written with security primarily in mind.

Name: Squirrel Mail
Homepage: http://www.squirrelmail.org/
function: Webmail client, used to check e-mails from anywhere in world, via the internet, like gmail or hotmail

Name: Postfix
HomePage: http://www.postfix.org/
Function: (message transfer agent) postfix is program responsible for receiving incoming e-mails and delivering the messages to individual users

Name: PostfixAdmin
HomePagehttp://high5.net/postfixadmin/
Function: Postfix Admin is a Web Based Management tool created for Postfix. It is a PHP based application that handles Postfix Style Virtual Domains and Users that are stored in MySQL.

 

1. First we need to start mysql

/etc/init.d/mysqld start

2. Now download postfixadmin from

http://high5.net/postfixadmin/

3. Once that is downloaded copy the postfixadmin-2.1.0.tgz file into the apache root directory and unzip it.

cp postfixadmin-2.1.0.tgz /var/www/html
tar -zxvf postfixadmin-2.1.0.tgz
mv postfixadmin-2.1.0 postfixadmin

4. Now import the mysql file into mysql

cd postfixadmin
nano DATABASE_MYSQL.TXT

5. comment out this line in the file DATABASE_MYSQL.TXT

 

DATABASE_MYSQL.TXT:
#INSERT INTO user (Host, User, Password) VALUES ('localhost','postfix',password('postfix'));


6. Now run this command to create the mysql database and tables

mysql -u root -p < DATABASE_MYSQL.TXT

7. Now setup the config.php.sample file

cp config.php.sample config.php

8. Create our mail repository

mkdir /var/spool/postfix/virtual
chown postfix:postfix /var/spool/postfix/virtual
chmod a+rwx /var/spool/postfix/virtual

9. Now add the following information to the postfix main.cf file

nano /etc/postfix/main.cf

 

main.cf:
# our settings
alias_database = hash:/etc/postfix/aliases
alias_maps = $alias_database
myhostname = <yourhostname>
mydomain = <your_domain>
myorigin = $myhostname
mydestination = $myhostname, localhost.$mydomain
mail_spool_directory = /var/spool/mail
home_mailbox = Mailbox
debug_peer_level = 2
debugger_command =
PATH=/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin
xxgdb = $daemon_directory/$process_name $process_id & sleep 5
disable_vrfy_command = yes
show_user_unknown_table_name = no

virtual_transport = virtual
virtual_maps = mysql:/etc/postfix/mysql_virtual_alias_maps.cf
virtual_minimum_uid = 12345
virtual_uid_maps = static:12345
virtual_gid_maps = static:54321
virtual_mailbox_base = /var/spool/postfix/virtual
virtual_mailbox_domains = mysql:/etc/postfix/mysql_virtual_domains_maps.cf
virtual_mailbox_maps = mysql:/etc/postfix/mysql_virtual_mailbox_maps.cf
virtual_mailbox_limit = 51200000

# Additional for quota support
virtual_create_maildirsize = yes
virtual_mailbox_extended = yes
virtual_mailbox_limit_maps = mysql:/etc/postfix/mysql_virtual_mailbox_limit_maps.cf
virtual_mailbox_limit_override = yes
virtual_maildir_limit_message = Sorry, the user's maildir has overdrawn his diskspace quota, please try again later.
virtual_overquota_bounce = yes


10. Now we need to make the mysql_virtual_alias_maps.cf

nano /etc/postfix/mysql_virtual_alias_maps.cf

 

mysql_virtual_alias_maps.cf:
user = postfix
password = postfix
hosts = localhost
dbname = postfix
table = alias
select_field = goto
where_field = address


11. Now we need to make the mysql_virtual_domains_maps.cf

nano /etc/postfix/mysql_virtual_domains_maps.cf

 

mysql_virtual_domains_maps.cf:
user = postfix
password = postfix
hosts = localhost
dbname = postfix
table = domain
select_field = description
where_field = domain
#additional_conditions = and backupmx = '0' and active = '1'


12. Now we need to make the mysql_virtual_mailbox_maps.cf

nano /etc/postfix/mysql_virtual_mailbox_maps.cf

 

mysql_virtual_mailbox_maps.cf:
user = postfix
password = postfix
hosts = localhost
dbname = postfix
table = mailbox
select_field = maildir
where_field = username
#additional_conditions = and active = '1'


14. Now we need to make the mysql_relay_domains_maps.cf

nano /etc/postfix/mysql_relay_domains_maps.cf

 

mysql_relay_domains_maps.cf:
user = postfix
password = postfix
hosts = localhost
dbname = postfix
table = domain
select_field = domain
where_field = domain
additional_conditions = and backupmx = '1'


15. Now we need to start postfix

/etc/init.d/postfix start

16. Now were going to setup MySQL and squirrelmail to store userprefs and addresses, make sure there is support of mysql in php

rpm -qa | grep php-mysql

if not installed it

yum install php-mysql

17. Now setup mysql

mysql --password="password"

18. After you are in the mysql command line copy the following information in into it.

CREATE DATABASE squirrelmail;

GRANT select,insert,update,delete ON squirrelmail.*
TO Anonymous@localhost IDENTIFIED BY '';

USE squirrelmail;
CREATE TABLE address (
owner varchar(128) DEFAULT '' NOT NULL,
nickname varchar(16) DEFAULT '' NOT NULL,
firstname varchar(128) DEFAULT '' NOT NULL,
lastname varchar(128) DEFAULT '' NOT NULL,
email varchar(128) DEFAULT '' NOT NULL,
label varchar(255),
PRIMARY KEY (owner,nickname),
KEY firstname (firstname,lastname)
);

CREATE TABLE userprefs (
user varchar(128) DEFAULT '' NOT NULL,
prefkey varchar(64) DEFAULT '' NOT NULL,
prefval blob DEFAULT '' NOT NULL,
PRIMARY KEY (user,prefkey)
);

quit

19. Now that mysql is setup, it's time to setup squirrelmail to use mysql, run the following command.

/usr/share/squirrelmail/config/conf.pl

20. Choose ,'9' to enter the database section.

SquirrelMail Configuration : Read: config.php (1.4.0)
---------------------------------------------------------
Main Menu --
1.  Organization Preferences
2.  Server Settings
3.  Folder Defaults
4.  General Options
5.  Themes
6.  Address Books (LDAP)
7.  Message of the Day (MOTD)
8.  Plugins
9.  Database

D.  Set pre-defined settings for specific IMAP servers

C.  Turn color off
S   Save data
Q   Quit

Command >> 9

21. Choose the '1' & '3' options and add the following information

SquirrelMail Configuration : Read: config.php (1.4.0)
---------------------------------------------------------
Database
1.  DSN for Address Book   : mysql://root:password@localhost/squirrelmail
2.  Table for Address Book : address

3.  DSN for Preferences    : mysql://root:password@localhost/squirrelmail
4.  Table for Preferences  : userprefs
5.  Field for username     : user
6.  Field for prefs key    : prefkey
7.  Field for prefs value  : prefval

R   Return to Main Menu
C.  Turn color off
S   Save data
Q   Quit

Command >> 1

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

nano  /etc/dovecot-mysql.conf

 

Code.conf:
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'


23. Add the following lines to dovecot.conf

nano /etc/dovecot.conf (for version 0.9x)

 

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

nano /etc/dovecot.conf (for version 1.x)

protocols =  imaps imap pop3s pop3
userdb sql {
args = /etc/dovecot-sql.conf
}
passdb sql {
args = /etc/dovecot-sql.conf
}
first_valid_uid = 106
default_mail_env = maildir:/home/vmail/%d/%n


24.  comming soon ...

 


BookMarking:

 

cell1

cell3 Submit to del.icio.us
cell4
AddThis Social Bookmark Button

 


Trouble Shooting:


Go to the wiki page

Go to the 'Contact Us ' Forum

Go to the how-to's Support Forum


External Links:

 

http://bliki.rimuhosting.com/space/knowledgebase/linux/mail/postfixadmin+on+debian+sarge

http://johnny.chadda.se/2005/04/30/postfix-howto/

Last Updated ( Sunday, 03 June 2007 )
 
< Prev   Next >