Jump to content


We use cookies to log you in, for ads and for analytics. OK

Photo

Postfix+Dovecot+mysql


6 replies to this topic

#1 hijinks

hijinks

    touch /dev/booty

  • Members
  • PipPipPip
  • 292 posts

Posted 29 September 2006 - 06:50 PM

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

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.

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.

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

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.

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

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

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

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

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

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

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

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

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

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

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

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

cd admin

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

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

rm -rf .htpasswd
htpasswd -c .htpasswd username

Now edit the config.inc.php file

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

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

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

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

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

chkconfig dovecot on
chkconfig postfix on

Now I am pretty drunk now while doing this so there could be many errors.. deal with it
  • inetryconydot, BycleIlliny, Easerrors and 20 others like this

#2 anyweb

anyweb

    Administrator

  • Admin
  • PipPipPipPipPipPipPipPip
  • 3,692 posts

Posted 29 September 2006 - 06:54 PM

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
  • BycleIlliny, Wilfredlui, Ruperttln and 3 others like this
i do windows too

#3 MilligaN

MilligaN

    Noob

  • Members
  • Pip
  • 4 posts

Posted 30 September 2006 - 09:41 AM

Looks like an ace post!

Im going to try it right away. You should get drunk more often!
  • BycleIlliny and Ruperttln like this

#4 kosta

kosta

    Noob

  • Members
  • Pip
  • 1 posts

Posted 21 August 2007 - 09:48 PM

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

virtual_alias_maps = mysql:/etc/postfix/mysql_virtual_alias_maps.cf
virtual_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...
  • Ruperttln likes this

#5 speeddemon92

speeddemon92

    Noob

  • Members
  • Pip
  • 1 posts

Posted 07 March 2010 - 03:39 AM

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 <_< 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

"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:
hosts = localhost
to:
hosts = 127.0.0.1

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

#6 Chandana

Chandana

    Noob

  • Members
  • Pip
  • 1 posts

Posted 27 May 2010 - 09:21 AM

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


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?
  • Ruperttln likes this

#7 Dungeon-Dave

Dungeon-Dave

    Linux-Noob Frequent Member

  • Moderator
  • PipPipPipPipPipPipPip
  • 972 posts

Posted 27 May 2010 - 12:30 PM

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

Is dovecot actually running?
  • Ruperttln likes this



Reply to this topic



  

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users