Installation and Configuration of Postfix Server on Centos 6.5 Part-1/4

Installation and Configuration of Postfix Server on Centos 6.5 Part-1/4

by -
0 1770

Follow the steps to install and configure postfix server:

Make entry for hostname :

[root@pc1 ~]# vi /etc/hosts   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

[root@pc1 ~]# vim /etc/sysconfig/network


The /etc/nsswitch.conf file is used to configure which services are to be used to determine information such as hostnames etc.Edit the nsswitch.conf file vi /etc/nsswitch.conf and change the hosts line to read:

"hosts:      files dns"

Which means, for programs that want to resolve an address they should use the file feature first i.e. /etc/hosts file, and then DNS servers if file is not available or can’t resolve the address.

[root@pc1 ~]# vi /etc/nsswitch.conf | grep hosts

#hosts:     db files nisplus nis dns
hosts:      files dns

Change your MTA:

A Mail Transfer Agent (MTA) is a software that transfers electronic mail messages from one computer to another using a client server application architecture. An MTA is also called by a few other names such as – a Message Transfer Agent, Mail Relay, and Mail Transport Agent.
Some of the popular MTAs in use are Sendmail, Exim, and Postfix.

Switch Between MTA:

Method 1: By Using “alternatives” command:

you can change the default MTA by using the alternatives command.

To display which MTA alternative is in use:

[root@pc1 ~]# alternatives –display mta

To choose from the available MTA alternatives from the command line :

[root@pc1 ~]# alternatives –config mta

To setup Postfix as the default mail system

[root@pc1 ~]# alternatives –set mta /usr/sbin/sendmail.postfix

Method 2 : “system-switch-mail” command

Once you have download and installed the system-switch-mail package, you can run one of the corresponding tools to switch between the different MTAs installed in your system. When you run the system-switch-mail command, you will see a self-explanatory selection dialog that allows you to switch to another MTA installed in your system.

Download “system-switch-mail” rpm from website:

[root@pc1 ~]# wget

[root@pc1 ~]# rpm -ivh system-switch-mail-0.5.25-13.el5.noarch.rpm
warning: system-switch-mail-0.5.25-13.el5.noarch.rpm: Header V3 DSA/SHA1 Signature, key ID e8562897: NOKEY
Preparing…               ########################################### [100%]
1:system-switch-mail     ########################################### [100%]

Now, Install the following required packages:

[root@pc1 ~]# yum install php-* -y

[root@pc1 ~]# yum install mysql-server -y

[root@pc1 ~]# yum install dovecot dovecot-mysql -y

[root@pc1 ~]# yum -y install php-mysql php-imap php-ldap php-mbstring -y

Download squirrelmail package from internet:

[root@pc1 ~]# wget

We will install postfix through centosplus repository for this we need to make some changes in CentOS-Base.repo file.Add the following lines in CentOS-Base.repo file for CentosPlus repos for postfix:

[root@pc1 ~]# vim /etc/yum.repos.d/CentOS-Base.repo

#additional packages that extend functionality of existing packages
name=CentOS-$releasever – Plus

First remove postfix package which is default install:
[root@pc1 ~]# yum remove postfix

And then install postfix through centosplus repository:
[root@pc1 ~]# yum install -y –enablerepo=centosplus postfix

————————verify the postfix package installed————

[root@pc1 ~]# rpm -qa postfix
[root@pc1 ~]# rpm -qi postfix

Verify the postfix package support the mysql:

[root@pc1 ~]#  postconf -m
mysql   <– this means the postfix package support the mysql database

Run command “system-switch-mail” (please select postfix):

[root@pc1 ~]# system-switch-mail

Verify the setting of our new MTA:

[root@pc1 ~]# alternatives –display mta
mta – status is manual.
link currently points to /usr/sbin/sendmail.postfix
/usr/sbin/sendmail.postfix – priority 30
slave mta-mailq: /usr/bin/mailq.postfix
slave mta-newaliases: /usr/bin/newaliases.postfix
slave mta-pam: /etc/pam.d/smtp.postfix
slave mta-rmail: /usr/bin/rmail.postfix
slave mta-sendmail: /usr/lib/sendmail.postfix
slave mta-mailqman: /usr/share/man/man1/mailq.postfix.1.gz
slave mta-newaliasesman: /usr/share/man/man1/newaliases.postfix.1.gz
slave mta-sendmailman: /usr/share/man/man1/sendmail.postfix.1.gz
slave mta-aliasesman: /usr/share/man/man5/aliases.postfix.5.gz
Current `best’ version is /usr/sbin/sendmail.postfix.

Check if our mailq, sendmail and aliases have the correct configured with postfix:

[root@pc1 ~]# ls -l  /etc/alternatives/mta-*
lrwxrwxrwx. 1 root root 40 Oct 18 19:31 /etc/alternatives/mta-aliasesman -> /usr/share/man/man5/aliases.postfix.5.gz
lrwxrwxrwx. 1 root root 22 Oct 18 19:31 /etc/alternatives/mta-mailq -> /usr/bin/mailq.postfix
lrwxrwxrwx. 1 root root 38 Oct 18 19:31 /etc/alternatives/mta-mailqman -> /usr/share/man/man1/mailq.postfix.1.gz
lrwxrwxrwx. 1 root root 27 Oct 18 19:31 /etc/alternatives/mta-newaliases -> /usr/bin/newaliases.postfix
lrwxrwxrwx. 1 root root 43 Oct 18 19:31 /etc/alternatives/mta-newaliasesman -> /usr/share/man/man1/newaliases.postfix.1.gz
lrwxrwxrwx. 1 root root 23 Oct 18 19:31 /etc/alternatives/mta-pam -> /etc/pam.d/smtp.postfix
lrwxrwxrwx. 1 root root 22 Oct 18 19:31 /etc/alternatives/mta-rmail -> /usr/bin/rmail.postfix
lrwxrwxrwx. 1 root root 25 Oct 18 19:31 /etc/alternatives/mta-sendmail -> /usr/lib/sendmail.postfix
lrwxrwxrwx. 1 root root 41 Oct 18 19:31 /etc/alternatives/mta-sendmailman -> /usr/share/man/man1/sendmail.postfix.1.gz

Remove Sendmail package if installed:
[root@pc1 ~]# yum remove sendmail

Create Mysql Username, Password and Postfixadmin database,for this first start the mysql service:
[root@pc1 ~]# service mysqld start
[root@pc1 ~]# chkconfig mysqld on

Now, Set root password for mysql:
[root@pc1 ~]# mysqladmin -u root password india@123

Login to mysql using root user:
[root@pc1 ~]# mysql -u root -p
Enter password:

##Now, Create Postfixadmin database:

mysql> CREATE DATABASE postfix;
Query OK, 1 row affected (0.00 sec)

##Create a new user “mail” having password “india@123”:

mysql> CREATE USER mail@localhost IDENTIFIED BY ‘india@123’;
Query OK, 0 rows affected (0.00 sec)

mysql> GRANT ALL PRIVILEGES ON postfix.* TO mail;
Query OK, 0 rows affected (0.00 sec)

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

Now, create a non-root user for Postfixadmin:
[root@pc1 ~]# useradd vmail  -s /sbin/nologin

Check id for user vmail:
[root@pc1 ~]# id vmail
uid=500(vmail) gid=500(vmail) groups=500(vmail)

Let’s, Configure the postfix file:

Open config file and change the following lines:

[root@pc1 ~]# vim /etc/postfix/
99 myorigin = $mydomain
116 inet_interfaces = all
164 mydestination = $myhostname, localhost.$mydomain, localhost
264 mynetworks =,                         <–this is the ip that can used to send email

Add the following lines at the end to file, this will tell the system to look for postfix configuration, its virtual domains, virtual users and aliases.
The virtual_uid_maps : static:500. This 500 is the id of my vmail. Change this if you have different id for your uid and gid.
[root@pc1 ~]# vim /etc/postfix/
At the end of the file add the following lines:

virtual_mailbox_domains = mysql:/etc/postfix/
virtual_mailbox_maps = mysql:/etc/postfix/
virtual_alias_maps = mysql:/etc/postfix/
virtual_mailbox_base = /home/vmail
virtual_uid_maps = static:500
virtual_gid_maps = static:500

Configure the postfix file:
The following configuration will create This will enable postfixadmin to create virtual domain.

[root@pc1 ~]# vim /etc/postfix/
host = localhost
user = mail
password = india@123
dbname = postfix
table = domain
select_field = domain
where_field = domain
additional_conditions = and backupmx = ‘0’ and active = ‘1’

:wq! (save&exit)

Configure the postfix file:
The following configuration will create This will enable postfixadmin create virtual users.

[root@pc1 ~]# vim /etc/postfix/
host = localhost
user = mail
password = india@123
dbname = postfix
table = mailbox
select_field = maildir
where_field = username
additional_conditions = and active = ‘1’
result_format = %sMaildir/

:wq! (save&exit)

Configure the postfix file:
The last part we should do now is to connect the postfixadmin to mysql.

[root@pc1 ~]# vim /etc/postfix/
host = localhost
user = mail
password = india@123
dbname = postfix
table = alias
select_field = goto
where_field = address
additional_conditions = and active = ‘1’

:wq! (save&exit)
[root@pc1 ~]# service postfix restart
Shutting down postfix:                                     [  OK  ]
Starting postfix:                                          [  OK  ]
[root@pc1 ~]# chkconfig postfix on

check for dovecot package:
[root@pc1 ~]# rpm -qa dovecot

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

[root@pc1 ~]# vim /etc/dovecot/dovecot-mysql.conf
driver = mysql
connect = host=localhost dbname=postfix user=mail password=india@123
default_pass_scheme = PLAIN
password_query = SELECT password FROM mailbox WHERE username = ‘%u’ AND active = ‘1’

Create a backup copy of dovecot.conf file and the edit the dovecot.conf file:
[root@pc1 ~]# cp /etc/dovecot/dovecot.conf /etc/dovecot/

[root@pc1 ~]# vim /etc/dovecot/dovecot.conf
(At the end of file add the following lines)
auth_username_format = %Lu

passdb {
driver = sql
args = /etc/dovecot/dovecot-mysql.conf
userdb {
driver = static
args = uid=500 gid=500 home=/home/vmail/%d/%n
mail_location = Maildir:~/Maildir

Edit 10-mail.conf file:
[root@pc1 ~]#  vim /etc/dovecot/conf.d/10-mail.conf
mail_location = Maildir:~/Maildir

Edit 10-auth.conf file:
[root@pc1 ~]#  vim /etc/dovecot/conf.d/10-auth.conf
disable_plaintext_auth = no
auth_mechanisms = plain login

Restart dovecot service:
[root@pc1 ~]# service dovecot restart
Stopping Dovecot Imap:                                     [  OK  ]
Starting Dovecot Imap:                                     [  OK  ]
[root@pc1 ~]# chkconfig dovecot on

Postfixadmin installation and configuration:
Postfix Admin is a web based interface used to manage mailboxes, virtual domains and aliases. It also features support for vacation/out-of-the-office messages.
It requires PHP, Postfix and one of MySQL or PostgreSQL.

Postfixadmin Installation:
Download postfixadmin package from internet:

[root@pc1 ~]# mkdir /software
[root@pc1 ~]# cd /software
[root@pc1 software]# wget

[root@pc1 software]# ls
[root@pc1 software]# tar -zxvf postfixadmin-2.3.3.tar.gz
[root@pc1 software]# mv postfixadmin-2.3.3 postfixadmin

Configure postfixadmin configuration file:

[root@pc1 ~]# cp /software/postfixadmin/ /software/postfixadmin/
[root@pc1 ~]# vim /software/postfixadmin/

26 $CONF[‘configured’] = true;
36 $CONF[‘postfix_admin_url’] = ‘/postfixadmin’;
49 $CONF[‘database_type’] = ‘mysqli’;
50 $CONF[‘database_host’] = ‘localhost’;
51 $CONF[‘database_user’] = ‘mail’;
52 $CONF[‘database_password’] = ‘change-your-new-password-here’; (MAIL USER PASS) india@123
53 $CONF[‘database_name’] = ‘postfix’;
100 $CONF[‘encrypt’] = ‘cleartext’;
144 $CONF[‘domain_path’] = ‘YES’;
150 $CONF[‘domain_in_mailbox’] = ‘NO’;
303 $CONF[’emailcheck_resolve_domain’]=’NO’;


Creating apache aliase for Postfixadmin:
[root@pc1 ~]# echo “Alias /postfixadmin /software/postfixadmin” > /etc/httpd/conf.d/postfixadmin.conf

[root@pc1 ~]# service httpd restart
Stopping httpd:                                            [  OK  ]
Starting httpd:                                            [  OK  ]
[root@pc1 ~]# chkconfig httpd on
[root@pc1 ~]# service postfix status




Enter setup password and click on Generate password hash.Now, copy the hash password and put into the file:

[root@pc1 ~]# vim  /software/postfixadmin/
Comment line 31:
31 #$CONF[‘setup_password’] = ‘changeme’;
And then next to line 31 add the following line:
32 $CONF[‘setup_password’] = ‘2651d038622ffdd436ceca52ae49e89a:002febb13f23bf632aa3609f083f500507cabce9’;


Enter your previous entered setup password and then add Admin user with password and then click on add button, like this and your admin user will be added:
Setup password: linux@123
Password: redhat


After this entry remove setup.php from /software/postfixadmin/setup.php:
and Open with:
and login with your user with password.


Now, you will notice this screen after login with Admin user:


Now, lets create Domain for this click on Domain List and then click New Domain:


After this enter your domain name which you want to add and then description and click on add domain button:
In Aliases and Mailbox filed enter “0” which means you can create unlimited number of aliases and mailbox for users.


Lets, add one more domain to the list:


Now as we added two domains, click on domain list will show us the added domain list:


Now click on Admin List and then click on New Admin:
Add new domain admin for domain
Password:  redhat
Then select domain from the list.
Then click add admin button.

Add another new domain admin for domain
Password:  redhat
Then select domain from the list.

Then click add admin button.10


After adding the two new admins for two domains, let’s check the list of the added admins by clicking on admin list:


Now logout from the admin panel and try to login to specific domain panel with the help of newly created admin of both domains, let’s for example try with

This will display panel only for domain Now, you can create users for domain
Let’s create mailbox for domain, click on virtual list and then click on add mailbox button:



Once we created user1 in domain, let’s login with squirrelmail.

Squirrelmail Installation:
Packages required to install squirrelmail are:
squirrelmail.noarch 0:1.4.22-4.el6
php-pear-DB.noarch 0:1.7.13-3.el6
[root@pc1 ~]# tar -zxvf squirrelmail-webmail-1.4.22.tar.gz
[root@pc1 ~]# cd squirrelmail-webmail-1.4.22/config
[root@pc1 config]# ./
Next, you will see the following screen. We can start to configure the squirrelmail’s server setting. Press <2> and press <Enter Button>.
Note: You can customize the squirrelmail to your organization preference such as logos, organization name etc. under Main Menu’s option 1.
SquirrelMail Configuration : Read: config.php (1.4.0)
Main Menu —
1. Organization Preferences
2. Server Settings
3. Folder Defaults
4. General Options
5. Themes
6. Address Books
7. Message of the Day (MOTD)
8. Plugins
9. Database
10. Languages

D. Set pre-defined settings for specific IMAP servers

C Turn color off
S Save data
Q Quit

Command >> 2
Next, press <1> to configure our domain name
SquirrelMail Configuration : Read: config.php (1.4.0)
Server Settings
1. Domain : localhost
2. Invert Time : false
3. Sendmail or SMTP : Sendmail

A. Update IMAP Settings : localhost:143 (uw)
B. Change Sendmail Config : /usr/sbin/sendmail

R Return to Main Menu
C Turn color off
S Save data
Q Quit

Command >> 1
The domain name is the suffix at the end of all email addresses. If
for example, your email address is, then your domain
would be
press S for save

In squirrelmail if you have not installed mod_ssl package then you have to comment out these lines in:

[root@pc1 ~]# vim /etc/httpd/conf.d/squirrelmail.conf

# this section makes squirrelmail use https connections only, for this you
# need to have mod_ssl installed. If you want to use unsecure http
# connections, just remove this section:
<Directory /usr/share/squirrelmail>
RewriteEngine on
RewriteCond %{HTTPS} !=on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

Verify the PostfixAdmin installation:

[root@pc1 ~]# postmap -q mysql:/etc/postfix/
[root@pc1 ~]# postmap -q mysql:/etc/postfix/

Verify virtual domains created by Postfixadmin:
[root@pc1 ~]# cd /home/vmail/
[root@pc1 vmail]# ls -l
total 8
drwx—— 4 vmail vmail 4096 Oct 23 21:59
drwx—— 4 vmail vmail 4096 Oct 23 22:00            <– 2 virtual domains created

Check inside the Mysql Database and Verify the virtual users’ password created by PostfixAdmin in Mysql:
[root@pc1 ~]# mysql -u root -p
Enter password:


The password created in not encrypted .This will ensure that our POP3 can verify the password. Else, go to /software/postfixadmin/ again check on line 100.

100 $CONF[‘encrypt’] = ‘cleartext’;


[root@pc1 ~]# telnet localhost 25
Trying ::1…
Connected to localhost.
Escape character is ‘^]’.
220 ESMTP Postfix
helo client
250 2.1.0 Ok
250 2.1.5 Ok
354 End data with <CR><LF>.<CR><LF>
hello how r u?
250 2.0.0 Ok: queued as 2EABA1FD3A
If the connection fail when performing smtp relay test on other pc. Please go to /etc/postfix/  then check on the following—-
Line 93 myorigin = $mydomain
Line 110 inet_interfaces = all  <– make sure this is not inet_interface=localhost
Line 155 mydestination = $myhostname, localhost.$mydomain, localhost
Line 255 mynetworks =, <–this is the ip that can used to sent email

——————————–Pop3 test————————————————
[root@kvit ~]# telnet localhost 110
Trying ::1…
Connected to localhost.
Escape character is ‘^]’.
+OK Dovecot ready.
pass 123
+OK Logged in.
+OK 6 messages:
1 775
2 617
3 617
+OK Logging out.

Download PDF


Leave a Reply

Required Captcha *