This article I will go over the installation and configuration of the e-mail server using Postfix, Postfix admin, MySQL, Squirrelmail, Dovecot, SSL on CentOS 64 bit, but it also works perfectly on 32 bit. Constructive criticism, information and questions are always welcome!
Installing needed packages and creating database in MySQL
First of all, do yum update:
# yum update -y
Then we will install the packages needed for smooth operation of the server:
# yum install gcc joe tcpdump dovecot iptraf nmap openssl* mysql mysql-server httpd squirrelmail php* -y
We will now install Postfix with MySQL support
Edit the file /etc/yum.repos.d/CentOS-Base.repo. In the fields and BASE UPDATES, add the following line:
exclude=postfix
After this, add in the field CENTOSPLUS:
includepkgs=postfix-*
Save the file and run:
# yum install postfix –y
To make sure thaty Postfix was installed with MySQL support, run the command:
# postconf -m
btree
cidr
environ
hash
ldap
mysql
nis
pcre
pgsql
proxy
regexp
static
unix
The next step is to set up the MySQL database. Let's set a password for the root user:
# mysqladmin -u root -p password 'newpassword'
Then, follow the steps in the MySQL shell:
mysql> CREATE DATABASE mail;
mysql> GRANT ALL PRIVILEGES ON mail.* TO 'mail'@'localhost' IDENTIFIED BY 'mail';
mysql> quit
Setting up Apache and Postfix
Let's create the aliases in httpd.conf so that we can use webmail and postfixadmin.
# joe /etc/httpd/conf/httpd.conf
At the end of the file, add the Following:
### WEBMAIL ###
Alias /squirrelmail /usr/share/squirrelmail/
<Directory /usr/share/squirrelmail/>
Options Indexes
AllowOverride none
DirectoryIndex index.php
Order allow,deny
allow from all
</Directory>
### POSTFIX ADMIN ###
Alias /postfixadmin /usr/share/postfixadmin/
<Directory /usr/share/postfixadmin/>
Options Indexes
AllowOverride none
DirectoryIndex index.php
Order allow,deny
allow from all
</Directory>
Save the file and restart Apache.
# service restart httpd
Now edit main.cf of Postfix, Leave the file as follows.
Change the fields as needed:
- · myhostname
- · mydomain
- · mynetworks
- · smtpd_banner
- · permit_mynetworks
myhostname = mail.exemple.com
mydomain = exemple.com.br
mynetworks = 127.0.0.0/8, 192.168.0.0/16
smtpd_banner = $myhostname ESMTP WELCOME!!
permit_mynetworks = 127.0.0.0/8, 192.168.0.0/16
Adding VMAIL users and MySQL files.
Let's create VMail, which will be responsible for the delivery:
# useradd vmail -r -u 150 -g mail -d /var/vmail -s /sbin/nologin
Now we will create the directory in which VMail will store the data:
# mkdir /var/vmail
# chmod 770 /var/vmail/
# chown vmail:mail /var/vmail/
To create the MySQL configuration files that Postfix can "communicate" with it, follow these steps:
# cd /etc/postfix
# joe mysql_virtual_alias_maps.cf
user = mail
password = mail
hosts = localhost
dbname = mail
table = alias
select_field = goto
where_field = address
additional_conditions = and active = '1'
#query = SELECT goto FROM alias WHERE address='%s' AND active = '1'
# joe mysql_virtual_domains_maps.cf
user = mail
password = mail
hosts = localhost
dbname = mail
table = domain
select_field = domain
where_field = domain
additional_conditions = and backupmx = '0' and active = '1'
#query = SELECT domain FROM domain WHERE domain='%s' AND backupmx = '0' AND active = '1'
joe mysql_virtual_mailbox_limit_maps.cf
user = mail
password = mail
hosts = localhost
dbname = mail
table = mailbox
select_field = quota
where_field = username
additional_conditions = and active = '1'
#query = SELECT quota FROM mailbox WHERE username='%s' AND active = '1'
joe mysql_virtual_mailbox_maps.cf
user = mail
password = mail
hosts = localhost
dbname = mail
table = mailbox
select_field = CONCAT(domain,'/',maildir)
where_field = username
additional_conditions = and active = '1'
#query = SELECT CONCAT(domain,'/',maildir) FROM mailbox WHERE username='%s' AND active = '1'
Edit /etc/postfix/master.cf and add the following
## DOVECOT ##
dovecot unix - n n - - pipe
flags=DRhu user=vmail:mail argv=/usr/libexec/dovecot/deliver -d $(recipient)
Configuring Dovecot is installing postfixadmin
Configuring your dovecot:
## Base Directory ##
base_dir = /var/run/dovecot/
## Protocols that he will run ##
protocols = imap imaps pop3 pop3s
log_timestamp = '%Y-%m-%d %H:%M:%S '
syslog_facility = mail
## SSL data ##
ssl_listen = localhost
ssl_cert_file = /etc/postfix/mail-cert.pem
ssl_key_file = /etc/postfix/mail-key.pem
ssl_parameters_regenerate = 168
verbose_ssl = no
mail_location = maildir:/var/vmail/%d/%u
mail_access_groups = mail
mail_debug = no
first_valid_uid = 150
last_valid_uid = 150
maildir_copy_with_hardlinks = yes
protocol imap {
}
protocol pop3 {
# Login executable location.
login_executable = /usr/libexec/dovecot/pop3-login
mail_executable = /usr/libexec/dovecot/pop3
pop3_uidl_format = %08Xu%08Xv
}
protocol lda {
sendmail_path = /usr/lib/sendmail
auth_socket_path = /var/run/dovecot/auth-master
}
auth_verbose = no
auth_debug = no
auth default {
mechanisms = plain
passdb pam {
}
passdb sql {
args = /etc/dovecot-sql.conf
}
userdb passwd {
}
userdb sql {
args = /etc/dovecot-sql.conf
}
socket listen {
master {
path = /var/run/dovecot/auth-master
mode = 0600
user = vmail
group = mail
}
client {
path = /var/run/dovecot/auth-client
mode = 0660
user = vmail
group = mail
}
}
}
dict {
}
plugin {
}
Now let's create the dovecot dovecot-sql.conf to communicate with MySQL
# joe /etc/dovecot-sql.conf
driver = mysql
connect = host=localhost dbname=mail user=mail password=mail
# The new name for MD5 is MD5-CRYPT so you might need to change this depending on version
default_pass_scheme = MD5
# Get the mailbox
user_query = SELECT '/var/vmail/%d/%n' as home, 'maildir:/var/vmail/%d/%n' as mail, 150 AS uid, 12 AS gid,
concat('dirsize:storage=', quota) AS quota FROM mailbox WHERE username = '%u' AND active = '1'
# Get the password
password_query = SELECT username as user, password, '/var/vmail/%d/%n' as userdb_home,
'maildir:/var/vmail/%d/%n' as userdb_mail, 150 as userdb_uid, 12 as userdb_gid FROM mailbox WHERE username
= '%u' AND active = '1'
# If using client certificates for authentication, comment the above
# chmod 600 /etc/dovecot.conf
# chmod 600 /etc/dovecot-sql.conf
# chown vmail /etc/dovecot.conf
# chown vmail /etc/dovecot-sql.conf
Let’s install the postfix admin:
# cd /root/
# wget http://ufpr.dl.sourceforge.net/project/postfixadmin/postfixadmin/postfixadmin-2.3.2/postfixadmin-2.3.2.tar.gz
# tar -zxvf postfixadmin-2.3.2.tar.gz
# mv postfixadmin-2.3.2.tar.gz postfixadmin
# mv postfixadmin /usr/share/
# cd /usr/share/postfixadmin
# joe config.inc.php
And change the following fields:
$CONF['database_type'] = 'mysql';
$CONF['database_host'] = 'localhost';
$CONF['database_user'] = 'mail';
$CONF['database_password'] = 'mail';
$CONF['database_name'] = 'mail';
$CONF['database_prefix'] = '';
Now go to http://localhost/postfixadmin/setup.php and configure it.
Configuring and Customizing SquirrelMail
Well , the time has come for our webmail. Squirrelmail is really cool, though there is other "competitors" such as RoundCubeMail.
The Squirrel lets you use many plugins, making it more robust. In addition, of course, it is compatible with MySQL and LDAP.
If you have not installed it, run the command:
# yum install squirrelmail –y
After that let’s run the configurator:
# /usr/share/squirrelmail/config/conf.pl
We will now include some data from our company to our webmail.
- Go to option 1 - Organization Preferences:
- There you can change the name of your organization, add logo, among other options.
- In option 2, Server Settings, you can modify your domain, and change the smtp to SMTP (option 3).
- The option 8 you have the plugins. Just take a look at SQUIRREL website and read about what each plugin does (http://squirrelmail.org/plugins.php).
- In Option 10 you can change the language.
- In sub-option 1, change the DEFAULT LANGUAGE to en_US.
- And finally, option D. Change to dovecot.
Made the changes, simply save by selecting "S " followed by "Q" to quit.
After the modifications, you can also go ahead and do further customizations in the login.php file.
For this, edit the file:
# joe /usr/share/squirrelmail/src/login.php
Generating SSL, tips and conclusion
Just now generate your SSL certificate and key
# cd /etc/postfix/
# openssl genrsa 1024 > mail-key.pem
# chmod 400 mail-key.pem
# openssl req -new -x509 -nodes -sha1 -days 365 -key mail-key.pem > mail-cert.pem
I tested and got into production everything was done here.
Packages used:
- postfix.i386 2:2.3.3-2.1.centos.mysql_pgsql
- dovecot.i386 1.0.7-7.el5
- mysql-server.i386 5.0.77-4.el5_5.4
- httpd.i386 2.2.3-43.el5.centos.3
- squirrelmail.noarch 1.4.8-5.el5.centos.10
- postfixadmin-2.3.2
Last Updated (Saturday, 08 January 2011 03:56)




Comments
in Postfix master.cf file, there MUST BE a white character preceding line "flags=DRhu user=vmail:mail (...). Otherwise Posftix will die on startup.
These two lines must look EXACTLY like that:
dovecot unix - n n - - pipe
flags=DRhu user=vmail:mail argv=/usr/libexec/dovecot/deliver -d $(recipient)
And there is a small mistake on page 4 in the first "mv" command. It should look like that:
mv postfixadmin-2.3.2 postfixadmin
Thank you for great tutorial! You did great job!
One more thing worth to note: in postifx master.cf file the line "flags=DRhu user=vmail:mail..." MUST BE PRECEDED WITH WHITE CHARACTER. Otherwise fetchmail will die on startup.
It needs to look eactly like this:
dovecot unix - n n - - pipe
flags=DRhu user=vmail:mail argv=/usr/libexec/dovecot/deliver -d $(recipient)
And there is a small mistake on page 4, in first "mv" command:
WRONG: #mv postfixadmin-2.3.2.tar.gz postfixadmin
GOOD: # mv postfixadmin-2.3.2 postfixadmin
Thank you once again for great tutorial!
NOTE on comment #3: when you copy&paste into config files, look out for new line characters in copied lines. Remove new line characters in mysql queries in dovecot-sql.conf
[root@centos55 etc]# service dovecot start
Starting Dovecot Imap: [ OK ]
[root@centos55 etc]# service dovecot status
dovecot dead but subsys locked.
Result in /var/log/maillog. I can't find anything about this by Google searching. Have been beating my head on it for days. Any guidance with this would be awsome.
Oct 10 12:57:10 centos55 dovecot: Dovecot v1.0.7 starting up
Oct 10 12:57:10 centos55 dovecot: Auth process died too early - shutting down
Oct 10 12:57:10 centos55 dovecot: auth(default): Error in configuration file /etc/dovecot-sql.conf line 9: Unknown setting: concat('dirsize:storage
Oct 10 12:57:10 centos55 dovecot: child 25999 (auth) returned error 89
/etc/dovecot-sql.conf
i got the output error as show below:
Jul 22 11:01:29 isptestmail dovecot: auth-worker(default) : plain_md5_verif y(extranho@ispt estmail.tl): Invalid password encoding
Jul 22 11:01:29 isptestmail dovecot: imap-login: Aborted login: user=, method=PLAIN, rip=::ffff:127.0.0.1, lip=::ffff:127.0.0.1, secured
what should I do now? i have change default_pass_sc heme to PLAIN, MD5 , but still got the same error...
thx before..
I am just wondering how do I create bulk email (about 100) at once? Is there any script to make this automated?
Thank you!
Jen
RSS feed for comments to this post.