Home > English > Tutorials > How to install postfix, dovecot and squirrelmail on centos(web mail)

How to install postfix, dovecot and squirrelmail on centos(web mail)



1 parameter vps 





Install epel repository. Reference link here Click here

Install LAMP. Reference link here Click here Click here

Temporarily turn off iptables 

# service iptables stop

# chkconfig iptables off

Turn off selinux , edit the file selinux

# nano /etc/sysconfig/selinux 

Edit SELINUX=disabled

# reboot to restart the server 

Network configuration

# nano /etc/sysconfig/network-scripts/ifcfg-eth0

# Generated by SolusVM


# service network restart

Configure file /etc/hosts, /etc/resolv.conf and edit hostname content as follows

# nano /etc/hosts

# Generated by SolusVM       localhost   mail.maxserver.net mail

# nano /etc/resolv.conf

# Generated by SolusVM
search maxserver.net

Change hostname in  /etc/sysconfig/network

# nano /etc/sysconfig/network

# Generated by SolusVM

Reboot the server

# reboot

Configure DNS Server

Install needed calls

# yum -y install perl perl-core wget screenw3m elinks openssh-clients openssh-server bind bind-utils unzip nmap sednc sysstat libaio rsync telnet aspell

Edit the file named.conf

# nano /etc/named.conf

Add the word  'any'

options {
        listen-on port 53 {;
any; };
        listen-on-v6 port 53 { ::1; };
        directory       "/var/named";
        dump-file       "/var/named/data/cache_dump.db";
        statistics-file "/var/named/data/named_stats.txt";
        memstatistics-file "/var/named/data/named_mem_stats.txt";
        allow-query     { localhost;
any; };
        recursion yes;


Creat this part beneath file named.conf as follows

zone "maxserver.net" IN {
type master;
file "db.maxserver.net";
allow-update { none; };


Creat a folder and add group using permission

# touch /var/named/db.maxserver.net
# chgrp named /var/named/db.maxserver.net
# nano /var/named/db.maxserver.net

Creat this content Tạo nội dung như sau

@       IN SOA  ns1.maxserver.net. root.maxserver.net. (
                                        0       ; serial
                                        1D      ; refresh
                                        1H      ; retry
                                        1W      ; expire
                                        3H )    ; minimum
@       IN      NS      ns1.maxserver.net.
@       IN      MX      0 mail.maxserver.net.
ns1     IN      A
mail    IN      A


Restart the service and test the result configuration of DNS Server

# service named restart
# chkconfig named on

Use nslookup and dig commands to test

# nslookup mail.maxserver.net


Name:   mail.maxserver.net


# dig maxserver.net mx

; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.37.rc1.el6_7.6 <<>> maxserver.net mx
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 29090
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 2

;maxserver.net.             IN      MX

maxserver.net.      86400   IN      MX      0 mail.maxserver.net.

maxserver.net.      86400   IN      NS      ns1.maxserver.net.

mail.maxserver.net. 86400   IN      A
ns1.maxserver.net.  86400   IN      A

;; Query time: 0 msec
;; WHEN: Tue Mar 15 23:16:50 2016
;; MSG SIZE  rcvd: 106


1. Install  postfix

postfix is usually available. If you have none, use the command 

# yum install postfix -y

# nano /etc/postfix/main.cf

Press ctrl+w to find phrases 

Find 'myhostname' and add this line 

#myhostname = host.domain.tld
#myhostname = virtual.domain.tld

myhostname = mail.maxserver.net

Find 'mydomain' and add this line

#mydomain = domain.tld
mydomain = maxserver.net

Find Find'myoirgin' and remove the sign  '#' in the following line

#myorigin = $myhostname
myorigin = $mydomain

Find 'inet_interfaces' and edit lines as follows 

inet_interfaces = all
#inet_interfaces = $myhostname
#inet_interfaces = $myhostname, localhost
#inet_interfaces = localhost

# Enable IPv4, and IPv6 if supported
inet_protocols = all

Find 'mydestination' and add '#' and then remove #' as follows

#mydestination = $myhostname, localhost.$mydomain, localhost
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
#mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain,
#       mail.$mydomain, www.$mydomain, ftp.$mydomain

Find Find'mynetworks' and remove '#' and then edit the ip

mynetworks =,
#mynetworks = $config_directory/mynetworks
#mynetworks = hash:/etc/postfix/network_table

Find Find'home_mailbox' and remove bỏ dấu '#' 

#home_mailbox = Mailbox
home_mailbox = Maildir/

Restart  postfix and run it together with the system 

# service postfix restart
# chkconfig postfix on

Test postfix

Creat a  user and set a password for this user 

# useradd maxserver
# passwd maxserver

Use telnet command to test the connection 
# telnet localhost smtp

[root@mail ~]# telnet localhost smtp
Connected to localhost.
Escape character is '^]'.
220 mail.maxserver.net ESMTP Postfix

ehlo localhost    
250-SIZE 10240000
250 DSN

mail from:<maxserver>               
250 2.1.0 Ok

rcpt to:<maxserver>                 
250 2.1.5 Ok

354 End data with <CR><LF>.<CR><LF>

Successfully test                               (email content)
.                                                          (email message ends with '.' )
250 2.0.0 Ok: queued as EB82554E2

221 2.0.0 Bye

Connection closed by foreign host.

Navigate it to mail folder of the user 'maxserver' and check the new mail

# ls /home/maxserver/Maildir/new/

root@mail ~]# ls /home/maxserver/Maildir/new/

A new mail to "maxserver". To see the mail, enter this command

# cat /home/maxserver/Maildir/new/1459484457.Vfc01I209f3M150354.mail.maxserver.net.net

[root@mail ~]# cat /home/maxserver/Maildir/new/1459484457.Vfc01I209f3M150354.mail.maxserver.net.net
Return-Path: <maxserver@maxserver.net.net>
X-Original-To: maxserver
Delivered-To: maxserver@maxserver.net.net
Received: from localhost (localhost [])
        by mail.maxserver.net.net (Postfix) with ESMTP id EB82554E2
        for <maxserver>; Fri,  1 Apr 2016 00:19:24 -0400 (EDT)
Message-Id: <20160401041938.EB82554E2@mail.maxserver.net.net>
Date: Fri,  1 Apr 2016 00:19:24 -0400 (EDT)
From: maxserver@maxserver.net.net
To: undisclosed-recipients:;

Test successfully


2. Install Cài đặt dovecot

Dovecot is an open source IMAP and POP3 mail server for  Unix / Linux systems. To install 

# yum install dovecot -y

Edit dovecot configuration

# nano /etc/dovecot/dovecot.conf

Find Find'Protocols' and remove  '#' in the following line 

# Protocols we want to be serving.
protocols = imap pop3 lmtp

# nano /etc/dovecot/conf.d/10-mail.conf

Find Find'mail_location' and remove '#' in the following line 

# See doc/wiki/Variables.txt for full list. Some examples:
mail_location = maildir:~/Maildir
#   mail_location = mbox:~/mail:INBOX=/var/mail/%u
#   mail_location = mbox:/var/mail/%d/%1n/%n:INDEX=/var/indexes/%d/%1n/%n

 # nano /etc/dovecot/conf.d/10-auth.conf

Find Find'disable_plaintext_auth' and remove  '#'

# Disable LOGIN command and all other plaintext authentications unless
# SSL/TLS is used (LOGINDISABLED capability). Note that if the remote IP
# matches the local IP (ie. you're connecting from the same computer), the
# connection is considered secure and plaintext authentication is allowed.

disable_plaintext_auth = yes

Find 'auth_mechanisms' and add 'login' to that line 

# Space separated list of wanted authentication mechanisms:
#   plain login digest-md5 cram-md5 ntlm rpa apop anonymous gssapi otp skey
#   gss-spnego
# NOTE: See also disable_plaintext_auth setting.

auth_mechanisms = plain login

# nano /etc/dovecot/conf.d/10-master.conf

Find'mode = 0600' and remove '#' and add user = postfix , group = postfix

unix_listener auth-userdb {
    #mode = 0600
    user =
    group = postfix

Start dovecot and run it together with the system 

# service dovecot start
# chkconfig dovecot on

Test dovecot

# telnet localhost pop3

[root@mail ~]# telnet localhost pop3
Connected to localhost.
Escape character is '^]'.
+OK Dovecot ready.

user maxserver                     (Login: user maxserver)

pass password                        (password:password) 
+OK Logged in.

retr 1
+OK 475 octets
Return-Path: <maxserver@maxserver.net>
X-Original-To: maxserver
Delivered-To: maxserver@maxserver.net
Received: from localhost (localhost [])
        by mail.maxserver.net (Postfix) with ESMTP id EB82554E2
        for <maxserver>; Fri,  1 Apr 2016 00:19:24 -0400 (EDT)
Message-Id: <20160401041938.EB82554E2@mail.maxserver.net>
Date: Fri,  1 Apr 2016 00:19:24 -0400 (EDT)
From: maxserver@maxserver.net

To: undisclosed-recipients:;

Succesfully test

+OK Logging out.
Connection closed by foreign host.


3.Install squirrelmail

Install  SquirreMail by commanding 

# yum install squirrelmail -y

Navigate to the folder Điều hướng đến thư mục / usr / share / SquirreMail / config /  and use conf.pl command as follows

# cd /usr/share/squirrelmail/config/
# ./conf.pl

The following wizard will open. Enter "1" to set up your organization in detail 

[root@mail ~]# cd /usr/share/squirrelmail/config/
[root@mail config]# ./conf.pl
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 >> 1

This wizard will open.  Enter add "1" changing your organization details once again

SquirrelMail Configuration : Read: config.php (1.4.0)
Organization Preferences
1.  Organization Name      : SquirrelMail
2.  Organization Logo      : ../images/sm_logo.png
3.  Org. Logo Width/Height : (308/111)
4.  Organization Title     : SquirrelMail $version
5.  Signout Page           : 
6.  Top Frame              : _top
7.  Provider link          : http://squirrelmail.org/
8.  Provider name          : SquirrelMail

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

Command >> 1

Name your Organization and press Enter:

We have tried to make the name SquirrelMail as transparent as
possible.  If you set up an organization name, most places where
SquirrelMail would take credit will be credited to your organization.

If your Organization Name includes a '$', please precede it with a \.
Other '$' will be considered the beginning of a variable that
must be defined before the $org_name is printed.
$version, for example, is included by default, and will print the
string representing the current SquirrelMail version.

[SquirrelMail]: maxserver

In this way, setup all details about organization name,logo, the program's provider name. When you finish, type 'S' to save changes and type 'R' to back to your main menu 

SquirrelMail Configuration : Read: config.php (1.4.0)
Organization Preferences
1.  Organization Name      : maxserver
2.  Organization Logo      : ../images/sm_logo.png
3.  Org. Logo Width/Height : (308/111)
4.  Organization Title     : SquirrelMail $version
5.  Signout Page           :
6.  Top Frame              : _top
7.  Provider link          : http://squirrelmail.org/
8.  Provider name          : MaxserverMail

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

Command >> s

Enter "2" to set the mail server settings such as domain name and and email agent 

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

Type "1", Enter your mail's domain name and press Enter  

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.  Update SMTP Settings   : localhost:25

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 jdoe@example.com, then your domain
would be example.com.

[nguyenvietduc.net]: maxserver.net

Enter "3" and change sendmail to SMTP

SquirrelMail Configuration : Read: config.php (1.4.0)
Server Settings

1.  Domain                 : maxserver.net
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 >> 3

Type  "2" to transform

You now need to choose the method that you will use for sending
messages in SquirrelMail.  You can either connect to an SMTP server
or use sendmail directly.

  1.  Sendmail
  2.  SMTP
Your choice [1/2] [1]: 2

Now you enter "S" and then "Q" to save the configuration and quit SquirreMail.

4.httpd configuration

# nano /etc/httpd/conf/httpd.conf

Edit these lines 

DocumentRoot "/usr/share/squirrelmail"

# Each directory to which Apache has access can be configured with respect
# to which services and features are allowed and/or disabled in that
# directory (and its subdirectories).
# First, we configure the "default" to be a very restrictive set of
# features.

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


# Note that from this point forward you must specifically allow
# particular features to be enabled - so if something's not working as
# you might expect, make sure that you have specifically enabled it
# below.

# This should be changed to whatever you set DocumentRoot to.
<Directory "


Restart httpd

# service httpd restart

Now you can visit  http://ip-vps