Dovecot on the side please

by Stephen McGroarty 1/14/2010 2:04:00 PM
Quick and dirty web post for dovecot
 
So here we go with dovevot for checking that spiffy new mail server.
Since I have postfix encrypting the passwords so I dont have to worry about admins being trustworthy that presented a fun issue or two and here is how i got around them.

I did the default install of dovecot 
yum install dovecot 
and then edited the funk out of my /etc/dovecot.conf file

dont forget to make a backup of it before you edit it

#where to run it 
base_dir = /var/run/dovecot/

# Just the basics, no s protocols with it 
protocols = imap pop3 

#listen on all addresses and standard ports 
listen = [::]

#i wanted to seperate it from my maillog so that i could get a better reading of whats going on 
log_path = /var/log/dovecot 
log_timestamp = "%Y-%m-%d %H:%M:S "

# what directory should it "login to" 
login_dir = /var/run/dovecot/login

# most people have this as /var/vmail/%d/%n 
mail_location = maildir:/home/vmail/%d/%n/Maildir

# !! Turn this off before going to production!! 
mail_debug = yes

# this is my postfix user ID and group ID 
first_valid_uid = 89
last_valid_uid = 89

# how many connections at a time 
max_mail_processes = 50

#specify the protocols and anything special about them
protocol imap {
}

protocol pop3 {
}

protocol lda {
  postmaster_address = postmaster@yourdomain.com
  hostname = mail.yourdomain.com
}

#this is to enforce standard user names 
auth_username_chars = abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890.-_@

# Again turn these off before going to production 
auth_verbose = yes
auth_debug = yes
auth_debug_passwords = no

#how many worker processes per login (If needed) 
auth_worker_max_count = 20

# what type of authorization 
auth default {
   mechanisms = plain login digest-md5 cram-md5 
  passdb sql {
    #the location to your user and password information 
    args = /etc/dovecot-mysql.conf 
  }
  userdb sql {
     #the location to your database connection 
    args = /etc/dovecot-mysql.conf 
  }

#Tried a few things for this part, and this one finally worked for me 
  socket listen {
    client {
      path = /var/run/dovecot/auth-client
      mode = 0660
      user = postfix 
      group = postfix 
    }
  }
}

# Any special plugins you want to load up 
plugin {
}


That is simple enough, but it took a while to get everything dialed in, and now the killer, dovecot-mysql.conf. It was a pain getting this information straight so here it is 

#NOTHING i found mentioned the Driver =  anwhere .. it was a leap of faith to get it 
driver = mysql

# if you do not have encrypted password you do not need this part 
default_pass_scheme = CRYPT

# YOUR database connection string 
connect = host=localhost dbname=postfix user=postfixuser password=mySuperSecretPassword 

#get the password for the user name 
password_query = SELECT password FROM mailbox WHERE username = '%u'

# change to reflect your mail directories, your postfix user/group number and quotas 
user_query = SELECT '/home/vmail/%d/%nMaildir' as home, 'maildir:/home/vmail/%d/%n/Maildir' as mail, 89 AS uid, 89 AS gid, concat('dirsize:storage=',quota) AS quota FROM mailbox WHERE username ='%u' AND active ='1'

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , , ,

Super Duper Postfix!

by Stephen McGroarty 1/2/2010 6:24:00 PM
Postfix + MySQL on CentOS 
Some things might not be right, but this is what worked for me, so if it doesn't work for you, sorry but this is how I did it, and it works. There are many many many links to doing this, so if this doesnt work keep searching. 

For this I started with a clean CentOS install, it was CentOS 5.4. During the CentOS install I used the advanced package options and I selected squirrelmail, httpd(web server), mysql, and I unchoose sendmail, it still installed sendmail. 

After the machine is booted and updated we then want to setup the mysql database and user.

/etc/init.d/mysqld start

mysql -u root -p 
Password: ***************************************** (not really my password, but you get the idea

mysql> create database postfix 
Query OK, 1 row affected (0.00 sec)

mysql> grant all on postfix.* to 'postfixuser'@'localhost' identified by 'MySuperSecurePassword!'; 
Query OK, 0 rows affected (0.00 sec)

now we want to add the postfix packages. 

/etc/init.d/sendmail stop 
yum remove sendmail 
yum install php-mysql spamassassin php php-mbstring postfix 

Postfix should now be installed, but it is missing some things. 
[root@localhost ~]# postconf -m
btree
cidr
environ
hash
ldap
nis
pcre
proxy
regexp
static
unix

If you notice, there is not MySQL support in there. That is in a special package in the CentOS Plus repo. 
wget http://mirror.centos.org/centos-5/5.4/centosplus/i386/RPMS/postfix-2.3.3-2.el5.centos.mysql_pgsql.i386.rpm 

When you do the rpm install it will tell you that you need postgressql, i just installed it and made sure it was off and the service was off.
yum install postgresql 

When you install postfix from the RPM it will tell you that you have a newer version on your system, and that is why we are using the --force 
rpm -U postfix-2.3.3-2.el5.centos.mysql_pgsql.i386.rpm --force  

Restart the server/service then run the postconf -m again to verify the MySQL support
[root@localhost ~]# postconf -m
btree
cidr
environ
hash
ldap
mysql
nis
pcre
pgsql
proxy
regexp
static
unix

Next we want to add Postfix Admin, there is no RPM for this, but it is a simple web application that will setup the tables in the database for you. 

http://sourceforge.net/projects/postfixadmin/
Because this is going to be a straight mail server, I just untared it in the /var/www/html directory and set it up from there. This is a nice utility for managing and maintaining users, and you can create admins per domain so that they can manage their own accounts. 

connect to the server at the postfix admin URL and configure that, it will allow you to configure the databases even though we haven't setup postfix to use the databases yet. 

After you have postfix admin configured it is time to add the magic to the postfix/main.cf file. 
You want to change it to allow users 
Be sure to find the corisponding lines here and comment them out or change them in the main.cf

#MySQL DB properties
# This is for the virtual users 
virtual_alias_maps = mysql:/etc/postfix/virtual_alias_maps.cf
# the group id that postfix runs as 
virtual_gid_maps = static:89
# Create this directory and chmod -R postfix:postfix /home/vmail 
virtual_mailbox_base = /home/vmail
# this will be the domains that are allowed to send/receive on the box 
virtual_mailbox_domains = mysql:/etc/postfix/virtual_domains_maps.cf
# mailboxes 
virtual_mailbox_maps = mysql:/etc/postfix/virtual_mailbox_maps.cf
# more user and groupIDs 
virtual_minimum_uid = 89
virtual_mailbox_uid = 89
# we want the transport type to be virtual instead of physical 
virtual_transport = virtual
virtual_uid_maps = static:89

And the Database connections

cat virtual_alias_maps.cf
user = postfixdatabaseuser
password = password
host = localhost
dbname = postfix
table = alias
select_field = goto
where_field = address

cat virtual_alias_maps.cf
user = postfixdatabaseuser
password = password
host = localhost
dbname = postfix
table = alias
select_field = goto
where_field = address

cat virtual_domains_maps.cf
user = postfixdatabaseuser
password = password
hosts = localhost
dbname = postfix
table = domain
select_field = description
where_field = domain

Restart the postfix server, add to local users with postfix admin, and use squirrelmail to verify that you can send and receive emails.

Again this is a general overview, email me if you have any questions.
Edits might be made to this as time goes on as well.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , , ,

Powered by BlogEngine.NET 1.4.5.0
Theme by Mads Kristensen
Hacked by Stephen McGroarty
Content © Stephen McGroarty


About the author

Stephen Mcgroarty - Avatar Stephen McGroarty

I am a Microsoft Certified Professional with Windows 2003 Server. I have a firm understanding of Linux, Windows, and everything needed for both workstation and servers.

E-mail me Send mail

Calendar

<<  September 2010  >>
SuMoTuWeThFrSa
2930311234
567891011
12131415161718
19202122232425
262728293012
3456789

View posts in large calendar

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2010