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 2667

Follow the steps to install and configure postfix server:

Make entry for hostname :

[[email protected] ~]# vi /etc/hosts   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

[[email protected] ~]# 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.

[[email protected] ~]# 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:

[[email protected] ~]# alternatives –display mta

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

[[email protected] ~]# alternatives –config mta

To setup Postfix as the default mail system

[[email protected] ~]# 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:

[[email protected] ~]# wget

[[email protected] ~]# 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:

[[email protected] ~]# yum install php-* -y

[[email protected] ~]# yum install mysql-server -y

[[email protected] ~]# yum install dovecot dovecot-mysql -y

[[email protected] ~]# yum -y install php-mysql php-imap php-ldap php-mbstring -y

Download squirrelmail package from internet:

[[email protected] ~]# 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:

[[email protected] ~]# 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:
[[email protected] ~]# yum remove postfix

And then install postfix through centosplus repository:
[[email protected] ~]# yum install -y –enablerepo=centosplus postfix

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

[[email protected] ~]# rpm -qa postfix
[[email protected] ~]# rpm -qi postfix

Verify the postfix package support the mysql:

[[email protected] ~]#  postconf -m
mysql   <– this means the postfix package support the mysql database

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

[[email protected] ~]# system-switch-mail

Verify the setting of our new MTA:

[[email protected] ~]# 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:

[[email protected] ~]# 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:
[[email protected] ~]# yum remove sendmail

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

Now, Set root password for mysql:
[[email protected] ~]# mysqladmin -u root password [email protected]

Login to mysql using root user:
[[email protected] ~]# 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 “[email protected]”:

mysql> CREATE USER [email protected] IDENTIFIED BY ‘[email protected]’;
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:
[[email protected] ~]# useradd vmail  -s /sbin/nologin

Check id for user vmail:
[[email protected] ~]# 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:

[[email protected] ~]# 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.
[[email protected] ~]# 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.

[[email protected] ~]# vim /etc/postfix/
host = localhost
user = mail
password = [email protected]
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.

[[email protected] ~]# vim /etc/postfix/
host = localhost
user = mail
password = [email protected]
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.

[[email protected] ~]# vim /etc/postfix/
host = localhost
user = mail
password = [email protected]
dbname = postfix
table = alias
select_field = goto
where_field = address
additional_conditions = and active = ‘1’

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

check for dovecot package:
[[email protected] ~]# 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:

[[email protected] ~]# vim /etc/dovecot/dovecot-mysql.conf
driver = mysql
connect = host=localhost dbname=postfix user=mail [email protected]
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:
[[email protected] ~]# cp /etc/dovecot/dovecot.conf /etc/dovecot/

[[email protected] ~]# 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:
[[email protected] ~]#  vim /etc/dovecot/conf.d/10-mail.conf
mail_location = Maildir:~/Maildir

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

Restart dovecot service:
[[email protected] ~]# service dovecot restart
Stopping Dovecot Imap:                                     [  OK  ]
Starting Dovecot Imap:                                     [  OK  ]
[[email protected] ~]# 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:

[[email protected] ~]# mkdir /software
[[email protected] ~]# cd /software
[[email protected] software]# wget

[[email protected] software]# ls
[[email protected] software]# tar -zxvf postfixadmin-2.3.3.tar.gz
[[email protected] software]# mv postfixadmin-2.3.3 postfixadmin

Configure postfixadmin configuration file:

[[email protected] ~]# cp /software/postfixadmin/ /software/postfixadmin/
[[email protected] ~]# 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) [email protected]
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:
[[email protected] ~]# echo “Alias /postfixadmin /software/postfixadmin” > /etc/httpd/conf.d/postfixadmin.conf

[[email protected] ~]# service httpd restart
Stopping httpd:                                            [  OK  ]
Starting httpd:                                            [  OK  ]
[[email protected] ~]# chkconfig httpd on
[[email protected] ~]# service postfix status




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

[[email protected] ~]# 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: [email protected]
Admin: [email protected]
Password: redhat


After this entry remove setup.php from /software/postfixadmin/setup.php:
and Open with:
and login with your [email protected] 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

Admin:[email protected]
Password:  redhat
Then select domain from the list.
Then click add admin button.

Add another new domain admin for domain
Admin:[email protected]
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 [email protected]:

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
[[email protected] ~]# tar -zxvf squirrelmail-webmail-1.4.22.tar.gz
[[email protected] ~]# cd squirrelmail-webmail-1.4.22/config
[[email protected] 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 [email protected], 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:

[[email protected] ~]# 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:

[[email protected] ~]# postmap -q mysql:/etc/postfix/
[[email protected] ~]# postmap -q mysql:/etc/postfix/

Verify virtual domains created by Postfixadmin:
[[email protected] ~]# cd /home/vmail/
[[email protected] 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:
[[email protected] ~]# 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’;


[[email protected] ~]# telnet localhost 25
Trying ::1…
Connected to localhost.
Escape character is ‘^]’.
220 ESMTP Postfix
helo client
MAIL FROM:[email protected]
250 2.1.0 Ok
rcpt to:[email protected]
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————————————————
[[email protected] ~]# telnet localhost 110
Trying ::1…
Connected to localhost.
Escape character is ‘^]’.
+OK Dovecot ready.
user [email protected]
pass 123
+OK Logged in.
+OK 6 messages:
1 775
2 617
3 617
+OK Logging out.

Download PDF

CEO, KV IT-Solutions Pvt. Ltd. | [email protected] | 9810028374|
Linux Professional and an Industrial Trainer | 20 + years Experience in IT Industry

” We are born free, No Gate and Windows can snatch our freedom “


0 1700

0 1355

0 1218


Leave a Reply