CentOS Linux Server Guide

Postfix Mail System - Step by Step Guide

Part 2:  Create Virtual User, Configure Postfix, Dovecot and Mysql

 

This is the Part2 of the Posft Mail System, we are going to configure the following:-

1. MySQL Server, create a postfixadmin database

2. Postfix Main.cf and create a virtual user file and virtual domain configuration files

3. Dovecot

 

Create Mysql Username, Password and Postfixadmin database

 

Step1:  Start your mysql

Let us start up the mysql now. Also,we want the service to be auto-startup for whenever the system is under Level 3,4,5

#service mysqld start

#chkconfig mysqld on

#chkconfig --list mysqld
mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off

 

 

Step2:  Create mysql root user password

First we need to create a password for our root access. I also perform a new test to ensure that no blank password is accepted.

 

#mysqladmin -u root password 'your password'

mysql -u root
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

mysql -u root -p
Enter password:
<test on blank password>
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
 

mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.0.77 Source distribution

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql>
 

 

Step3:  Create Postfixadmin database

Next,we create a database named postfix and the create a user called 'mail'. Then we will give full access rights for 'mail' on postfix database.

mysql> CREATE DATABASE postfix;
mysql>
CREATE USER mail@localhost IDENTIFIED BY 'your_password';
mysql>
GRANT ALL PRIVILEGES ON postfix.* TO mail;

mysql> show databases;
+--------------------+
| Database               |
+--------------------+
| information_schema |
| mysql                    |
| postfix                   |
| test                      |
+--------------------+
4 rows in set (0.00 sec)
 

 

Create Postfixadmin User

 

Step1: Create a non-root user for postfixadmin

Let us create a non-root user for our postfixa & pop administration purposes.

 

#useradd vmail  -s /sbin/nologin

 

Now, get a paper and write down the user id & group id of vmail.

 

#id vmail
uid=501(vmail) gid=501(vmail) groups=501(vmail)

 

 

Configure Postfix

Step1:  Configure the postfix main.cf file

First modify the /etc/postfix/main.cf. We change the following lines

Note: Number in blue are line numbers. You can active it using :set nu under vi command mode

93 myorigin = $mydomain

110 inet_interfaces = all

155 mydestination = $myhostname, localhost.$mydomain, localhost

255 mynetworks = 192.168.139.0/24, 127.0.0.0/8  <--this is the ip that can used to sent email

 

Next, Add in the following lines, this will tell the system to look for postfix configuration, its virtual domains, virtual users and aliases.

 

The virtual_uid_maps : static:501. This 501 is the id of my vmail. Change this if you have diffrent id for your uid and gid.

#vim /etc/postfix/main.cf

virtual_mailbox_domains = mysql:/etc/postfix/mysql-domains.cf
virtual_mailbox_maps
= mysql:/etc/postfix/mysql-users.cf
virtual_alias_maps
= mysql:/etc/postfix/mysql-aliases.cf
virtual_mailbox_base
= /home/vmail
virtual_uid_maps
= static:501
virtual_gid_maps
= static:501

 

Step2:  Configure the postfix mysql-domians.cf file

The following configuration will create mysql-domains.cf. This will enable postfixadmin to create virtual domain

 
 #vim /etc/postfix/mysql-domains.cf

host
= localhost
user
= mail
password
= <your-mysql-password-here>
dbname = postfix
table
= domain
select_field
= domain
where_field
= domain
additional_conditions
= and backupmx = '0' and active = '1'
 

Step3:  Configure the postfix mysql-users.cf file

The following configuration will create mysql-users.cf. This will enable postfixadmin create virtual users

 #vim /etc/postfix/mysql-users.cf

host = localhost
user =
mail
password =
<your-mysql-password-here>
dbname =
postfix
table = mailbox
select_field = maildir
where_field = username
additional_conditions = and active = '1'
result_format = %sMaildir/

 

 

Step2:  Configure the postfix mysql-alias.cf file

Great, the last part we should do now is to connect the postfixadmin to mysql

 

#vim /etc/postfix/mysql-aliases.cf

host = localhost
user = mail
password = <your-mysql-password-here> 
dbname = postfix
table = alias
select_field = goto
where_field = address
additional_conditions = and active = '1'

 

#service postfix start

#chkconfig postfix on

#chkconfig --level postfix

 

Configuring Dovecot

 

Step 1 Check if the dovecot packages installed

#rpm -qa dovecot

dovecot-1.0.7-7.el5

 

Step 2 Create mysql config file for postfixadmin

Create the file /etc/dovecot-mysql.conf containing the lines below. You might need to change your username, password and db user.

 
driver = mysql
connect = host=localhost dbname=
postfix user=mail password=<your-mysql-password-here>
default_pass_scheme = PLAIN
password_query = SELECT password FROM mailbox WHERE username = '%u'
 

 

Now, This is very import part, many users including me :p that make mistake on the setting. First di a backup!

 

cp /etc/dovecot.conf /etc/dovecot.ori

 

Next edit the file /etc/dovecot.conf and change the value of the following keys below. For line 917 please make sure that your uid and gid is the same as your vmail user. Make sure you remove # sign for all the following lines.  Also, comment out all passdb and userdb setting.  Then, make a dovecot.log to ease any dovecot troubleshooting.
 61 log_path = /var/log/dovecot.log

721  auth_username_format = %Lu

869  passdb sql {
870  args = /etc/dovecot-mysql.conf
871  }

913  userdb static {
917      args = uid=501 gid=501 home=/home/vmail/%d/%n
927  }
 

 

Step3 Start you dovecot services

Finally startup your dovecot services.

#service dovecot start

#service dovecot on

 

Back to Step by Step Guide on CentOS Linux Postfix Mail Server



Copyright 2011 http://www.1a-centosserver.com All Rights Reserved

All trademarks are the property of their respective owners.

Contact Us | Terms of Use | Privacy Policy