Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Postfix+Dovecot+mysql
#1

Ok.. so recently I moved photoblog.com off a old crappy server that had cpanel on a nice server that doesn't run cpanel. So I needed a system for virtual hosting for emails mainly. I've setup postfix+mysql+courier before and courier can be a GIANT bitch. So I looked into dovecot and was very happy.

 

So lets start off.. lets download PostfixAdmin. As of writting this you can use the following since its the current version

 



Code:
wget http://high5.net/postfixadmin/download.php?file=postfixadmin-2.1.0.tgz
tar zxfv download.php?file=postfixadmin-2.1.0.tgz
cd postfixadmin-2.1.0




 

ok my wget saved it as download.php.... your results may vary

 

Ok now once its installed we want to import the basic DB layout into mysql. Edit the file if you want to change the user/pass.. but you will have to change it in other files below.. so just take note if you edit it.

 



Code:
mysql -u root < DATABASE_MYSQL.TXT




 

So that command is the default install of mysql that you didn't set a root password on.. use the -p flag if you did

 

ok now that the layout is there lets get postfix and dovecot installed. Now the default version of postfix that ships with fedora/centos DOES NOT HAVE MYSQL FUNCTIONALITY BUILT IN. So this will be for centos or rhel you have to install the centos Plus version of it.

 



Code:
wget http://mirror.trouble-free.net/centos/4/centosplus/i386/RPMS/postfix-2.1.5-4.2.RHEL4.mysql.centos4.i386.rpm
rpm -ivh postfix-2.1.5-4.2.RHEL4.mysql.centos4.i386.rpm
yum -y install dovecot




 

Ok great all the needed stuff is installed. So lets add a vmail user to the system

 



Code:
groupadd -g 901 vmail
useradd -u 901 -g 901 vmail




 

Then you want to edit /etc/postfix/main.cf and add this to the bottom. Take a note of /vmail change that to the location you want to store all your email in.

 



Code:
virtual_alias_maps = mysql:/etc/postfix/mysql_virtual_alias_maps.cf
virtual_gid_maps = static:901
virtual_mailbox_base = /vmail
virtual_mailbox_domains = mysql:/etc/postfix/mysql_virtual_domains_maps.cf
virtual_mailbox_limit = 51200000
virtual_mailbox_maps = mysql:/etc/postfix/mysql_virtual_mailbox_maps.cf
virtual_minimum_uid = 901
virtual_transport = virtual
virtual_uid_maps = static:901




 

ok save the file and create a new file in /etc/postfix/mysql_virtual_alias_maps.cf and add the following

 



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




 

 

ok save the file and create a new file in /etc/postfix/mysql_virtual_domains_maps.cf and add the following

 



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




 

ok save the file and create a new file in /etc/postfix/mysql_virtual_mailbox_maps.cf and add the following

 



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




 

ok save the file and create a new file in /etc/postfix/mysql_virtual_mailbox_limit_maps.cf and add the following

 



Code:
user = postfix
password = postfix
hosts = localhost
dbname = postfix
table = mailbox
select_field = quota
where_field = username
#additional_conditions = and active = '1'




 

ok save the file and create a new file in /etc/postfix/mysql_relay_domains_maps.cf and add the following

 



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




 

now save that and lets chown them

 



Code:
chmod 640 /etc/postfix/mysql_*
chgrp postfix /etc/postfix/mysql_*




 

Now lets create the /vmail dir and give it the correct permissions

 



Code:
mkdir /vmail
chmod 771 /vmail
chown vmail:vmail /vmail




 

now lets restart or start postfix in this case we will start it

 



Code:
service postfix start




 

If you have sendmail on the machine already a nice little rpm to download is system-switch-mail once download run the command by the same name.. select postfix and it'll be running

 

Now go back to the place you untared postfixadmin and point our browser to that location like

 

[/url][url=http://jyiscool.com/postfixadmin/setup.php]http://jyiscool.com/postfixadmin/setup.php

 

Make sure you pass all points.. then you want to remove the setup.php file

 

Ok now in the postfixadmin dir do this

 



Code:
cd admin




 

You need to setup the .htaccess file. So edit .htaccess in that dir and it will look something like this

 



Code:
AuthUserFile /some/dir/to/go/mail/admin/.htpasswd
AuthGroupFile /dev/null
AuthName "Postfix Admin"
AuthType Basic

<limit GET POST>
require valid-user
</limit>




 

You want to change AuthUserFile to the path where that .htpasswd file is that you just put your postfixadmin app.

 

Once thats installed delete the file and we will create a new one since we don't want to use the same admin user that is in there by default

 



Code:
rm -rf .htpasswd
htpasswd -c .htpasswd username




 

Now edit the config.inc.php file

 



Code:
cd ..
mv config.inc.php-dist config.inc.php




 

Basically you just have to change some defaults to suit your needs.. From there you should be able to access the admin error by entering the user/pass you just made and create a new domain and create some new users..

 

Once you have done that you should be able to use the local mail command to send off a test email to make sure its in the /vmail dir

 



Code:
echo testing 1 2 3 | mail -s test user@jyiscool.com




 

if you see a /vmail/user@jyiscool.com directory then it worked.. yayaya

 

Now I like setting up new services like I like my women.. easy

 

So create a new file called /etc/dovecot-mysql.conf with the following contents

 



Code:
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, 901 AS uid, 901 AS gid FROM mailbox WHERE username = '%u'




 

Save that and edit the /etc/dovecot.conf file and add the following at the bottom

 



Code:
auth_userdb = mysql /etc/dovecot-mysql.conf
auth_passdb = mysql /etc/dovecot-mysql.conf
first_valid_uid = 501
default_mail_env = maildir:/vmail/%u




 

i also turned off ssl.. I might enable it in the future and append to this howto.. but for now in my dovecot.conf there is ssl_disable = yes

 

Now start dovecot

 



Code:
service dovecot start




 

You should not be able to grab that email you just sent that user via imap/pop3

 

Now make sure both get loaded on boot

 



Code:
chkconfig dovecot on
chkconfig postfix on




 

Now I am pretty drunk now while doing this so there could be many errors.. deal with it

Reply
#2

Quote:Now I am pretty drunk now while doing this so there could be many errors.. deal with it
 

heh, great post Jy

 

keep it up !

 

pinned :)

 

cheers

anyweb

Reply
#3

Looks like an ace post!

 

Im going to try it right away. You should get drunk more often!

Reply
#4

Hello friends... I'm new here and I have one question...

 

I followed the instructions above and everything in OK but quota doeasn't work... I entered YES for quota in postfixadmin, setup is 50MB for user mailboxes but I still can receive more then 50MB in mailboxes... When I enter #du in user maildir it is above 50MB...

 

Here is few lines from main.cf

 

Quote:virtual_alias_maps = mysql:/etc/postfix/mysql_virtual_alias_maps.cfvirtual_gid_maps = static:1001

virtual_mailbox_base = /opt/mail

virtual_mailbox_domains = mysql:/etc/postfix/mysql_virtual_domains_maps.cf

virtual_mailbox_limit = 51200000

virtual_mailbox_maps = mysql:/etc/postfix/mysql_virtual_mailbox_maps.cf

virtual_minimum_uid = 1001

virtual_transport = virtual

virtual_uid_maps = static:1001

# quota addon

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.
 

You will notice that some things in not the same like here but It works for me. Except Quota...

Reply
#5

Thanks man this is a life saver. I use Ubuntu and used their page which used courier and quickly found problems. I since found this page and have used it for the second time with success! (First time my server was hacked because I forgot to harden it [img]<___base_url___>/uploads/emoticons/default_dry.png[/img] Oh well, I learned better) I just set up my server for the second time just a few hours ago and is working now after looking at my error in the log. I just want to say thank you for this simple instruction page.

 

Also if anyone ever has problems with your server and your postfix log says something about the mysql sockets like this

Quote:"postfix/cleanup[4486]: warning: connect to mysql server localhost: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)"
there is a quick fix. 

change this line in your mysql_* files from:



Code:
hosts = localhost




to:



Code:
hosts = 127.0.0.1




 

this will help as linux sometimes forgets that it is localhost or if it is chrooted.

Reply
#6

When I'm sending mail from Telnet. In Mail log it log as Permission Denied Message

 

 



Code:
May 27 14:27:45 localhost pipe[21486]: fatal: pipe_command: execvp /usr/lib/dovecot/deliver: Permission denied
May 27 14:27:45 localhost pipe[21488]: fatal: pipe_command: execvp /usr/lib/dovecot/deliver: Permission denied
May 27 14:27:45 localhost postfix/pipe[21484]: 8763E900DA: to=<john@example.com>, relay=dovecot, delay=8491, delays=8491/0.05/0/0.03, dsn=4.3.0, status=deferred (temporary failure. Command output: pipe: fatal: pipe_command: execvp /usr/lib/dovecot/deliver: Permission denied )
May 27 14:27:45 localhost postfix/pipe[21485]: 96092900D9: to=<john@example.com>, relay=dovecot, delay=2567, delays=2567/0.03/0/0.03, dsn=4.3.0, status=deferred (temporary failure. Command output: pipe: fatal: pipe_command: execvp /usr/lib/dovecot/deliver: Permission denied )




 

Any one have idea of this issue? May I want to set permission for deliver folder?

Reply
#7

Looks like postfix can't pass the mail to dovecot.

 

Is dovecot actually running?

Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)