How to Configure Postfix, Dovecot, Virtual Domains, Virtual Users in CentOS

Step 1: Install Postfix

Install postfix using yum command:

# yum install postfix

Step 2: Run Postfix on Multi-Levels

Make sure run the postfix on multilevels:

# chkconfig postfix on

Step 3: Modify /etc/postfix/ File

Make a copy of both these files &

# cd /etc/postfix
# cp
# cp

Edit and change the following values:

# vi /etc/postfix/
myhostname =
mydomain =
myorigin = $mydomain
inet_interfaces = all
home_mailbox = Maildir/

Step 4: Create Postfix User

Create postfix user “userpostfix” on server with login shell as /sbin/nologin

# useradd -s /sbin/nologin userpostfix

Check the UID:GUID for the userpostfix user in /etc/passwd file

# tail /etc/passwd

Step 5: Configure Virtual domain

Add the following lines at the end of and replace the UID:GUID under virtual_minimum_uid, virtual_maximum_uid, virtual_uid_maps and virtual_gid_maps

# vi /etc/postfix/
virtual_mailbox_domains = /etc/postfix/virtual_domains
virtual_mailbox_base = /var/mail/vhosts
virtual_mailbox_maps = hash:/etc/postfix/vmailbox
virtual_minimum_uid = 1001
virtual_maximum_uid = 1001
virtual_uid_maps = static:1001
virtual_gid_maps = static:1001
virtual_alias_maps = hash:/etc/postfix/virtual

Create /etc/postfix/virtual_domains. It contains all the domains that are pointed on server.

# vi /etc/postfix/virtual_domains

Step 6: Create Mail Directories

Create the mail directory, sub directory for the domains and assign the proper permissions.

# mkdir /var/mail/vhosts
# chgrp -R userpostfix /var/mail
# cd /var/mail/vhosts
# mkdir
# mkdir
# mkdir
# cd ..
# chown -R userpostfix:userpostfix vhosts

Note: Postfix will create the “Maildir” directories automatically and assign the proper permissions.

Step 7: Create /etc/postfix/vmailbox File

Create a file /etc/postfix/vmailbox and add all of the users that will receive e-mails.

# touch /etc/postfix/vmailbox
# vi /etc/postfix/vmailbox

Note: Make sure you end up each line with “/”.
Postfix will automatically create Maildir structure (cur, new, tmp).

Step 7: Execute postmap Command

Create the hashed file (.db) using postmap command.

# postmap /etc/postfix/virtual
# postmap /etc/postfix/vmailbox

Step 8: Check postfix Status

Make sure postfix service is running fine and port 25 is opened for postfix.

# ps -eaf | grep postfix
postfix   1219  1590  0 12:05 ?        00:00:00 pickup -l -t fifo -u
root      1353 30585  0 12:06 pts/0    00:00:00 grep postfix
root      1590     1  0 Mar05 ?        00:01:03 /usr/libexec/postfix/master
postfix  23181  1590  0 Apr13 ?        00:00:07 qmgr -l -t fifo -u
# netstat -an | grep :25
tcp        0      0        *                   LISTEN
tcp        0      0 :::25                       :::*                        LISTEN
tcp        0      0 ::ffff:      ::ffff:   TIME_WAIT

Step 9: Reload postfix

Now reload the postfix service:

# service postfix reload

Step 10: Test Postfix

Test the mail using telnet command:

# telnet localhost smtp
Connected to localhost.
Escape character is '^]'.
220 ESMTP Postfix
ehlo localhost
250-SIZE 10240000
250 DSN
250 2.1.0 Ok
250 2.1.5 Ok
354 End data with .
Test Mail
250 2.0.0 Ok: queued as E7E1F5A1F6
221 2.0.0 Bye
Connection closed by foreign host.

How to Configure Dovecot

Dovecot is an open-source POP and IMAP client.

Step 1: Install Dovecot

Install dovecot using yum command:

# yum install dovecot

Step 2: Configure Dovecot on Multi-Levels

To Configure dovecot on multilevels:

# chkconfig dovecot on

Step 3: Configure Dovecot Files

Then, go to conf.d folder and change the following lines in the following files.

# cd /etc/dovecot/
# vi dovecot.conf
protocols = imap pop3
# cd /etc/dovecot/conf.d/
# vi 10-auth.conf
disable_plaintext_auth = no
#!include auth-system.conf.ext
!include auth-passwdfile.conf.ext
# vi 10-logging.conf
log_path = /var/log/dovecot.log
auth_verbose = no
auth_debug = no
verbose_ssl = no
# vi 10-mail.conf
mail_location = maildir:/var/mail/vhosts/%d/%n
mail_uid = 1001
mail_gid = 1001
mail_privileged_group = userpostfix
# vi 10-master.conf
unix_listener auth-userdb {
  mode = 0600
  user = postfix
  group =  postfix
# Postfix smtp-auth
unix_listener /var/spool/postfix/private/auth {
  mode = 0666
  user = postfix
  group = postfix

Step 4: Reload Dovecot

Now reload the dovecot service:

 # service dovecot reload

Step 5: Test Dovecot

# telnet localhost pop3
Connected to localhost.
Escape character is '^]'.
+OK Dovecot ready.
pass Test123
+OK Logged in.
+OK 1 messages:
1 3845
retr 1
+OK 3845 octets
Return-Path: <>
X-Original-To: user1
Received: from localhost (localhost [IPv6:::1])
by (Postfix) with ESMTP id 117113FF18
for ; Thu, 7 Feb 2013 17:05:32 +0530 (IST)
Message-Id: <>
Date: Thu, 7 Feb 2013 17:05:32 +0530 (IST)
To: undisclosed-recipients:;

+OK Logging out.
Connection closed by foreign host.

How to Configure Squirrelmail

Step 1: Prerequisites

Step 2: Install Squirrelmail

Install EPEL repository and install SquirrelMail package from EPEL repository.

# wget
# rpm -ivh epel-release-6-8.noarch.rpm 
# yum install squirrelmail
# service httpd restart
Stopping httpd:                                            [  OK  ]
Starting httpd:                                            [  OK  ]

Step 3: Configure Squirrelmail

Configure according to the server as following:

# cd /usr/share/squirrelmail/config/
# ./ 
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

SquirrelMail Configuration : Read: config.php (1.4.0)
Server Settings
1.  Domain                 :
2.  Invert Time            : false
3.  Sendmail or SMTP       : SMTP
A.  Update IMAP Settings   : localhost:143 (uw)
B.  Update SMTP Settings   : localhost:25
R   Return to Main Menu
C   Turn color off
S   Save data
Q   Quit
Command >> S

Press S to save datas and press Q to exit.

Step 4: Configure Squirrelmail with httpd.conf

Add the following lines in the httpd.conf file at the end.

# vi /etc/httpd/conf/httpd.conf
Alias /squirrelmail /usr/share/squirrelmail
<Directory /usr/share/squirrelmail>
    Options Indexes FollowSymLinks
    RewriteEngine On
    AllowOverride All
    DirectoryIndex index.php
    Order allow,deny
    Allow from all

Restart the httpd service.

# service httpd restart
Stopping httpd:                                            [  OK  ]
Starting httpd:                                            [  OK  ]
6 replies
  1. Francis Carayol
    Francis Carayol says:

    This is a great write-up. I followed your tutorial and installed Postfix and Dovecot, Thank you. I just have one question, how do you create passwords for the email accounts? I noticed you have a password on the telnet test but I seem to have missed how you created the password.

  2. Elijah
    Elijah says:

    You can definitely see your enthusiasm in the article
    you write. The world hopes for even more
    passionate writers like you who aren’t afraid to say how they believe.
    All the time follow your heart.


Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *