How to Setup a Complete Mail Server(Postfix) using SquirrelMail(Webmail) in CentOS 7


A mail server is a server that handles and delivers e-mail over a network or internet. A mail server can receive e-mails from client computers and deliver them to other mail servers. A mail server can also deliver e-mails to client computers. A client computer is normally the computer where you read your e-mails, for example your computer at home or in your office. Also an advanced mobile phone or Smartphone, with e-mail capabilities, can be regarded as a client computer in these circumstances.

Mail Server, there are two parts when it comes to dealing with mails:
1. Mail Transfer
2. Mail Deliver

On a very simple level:
Postfix (MTA, Mail Transfer Agent) transfers mails from your server to
other servers, on SMTP Protocol (Simple Mail Transfer Protocol).

Dovecot (MDA, Mail Deliver Agent) delivers mails from your server to
Thunderbird (MUA, Mail User Agent), on IMAP (Internet Message Access
Protocol) or POP3 Protocol (Post Office Protocol 3).

Basic Configuration:

Before configuring mail server need to setup basic configuration.

Set the hostname with FQDN:
[root@localhost ~]# hostnamectl   set-hostname

Hosts file entry:
[root@localhost ~]# vim  /etc/hosts    mail

[root@localhost ~]# vim  /etc/resolv.conf

[root@localhost ~]# setenforce 0
[root@localhost ~]# vim  /etc/sysconfig/selinux

[root@localhost ~]# reboot

DNS Entry Check:

Check the A record, PTR record and MX record in your dns server zone files. MX record specifies the mail server responsible for accepting email messages on behalf of a domain name. It is a resource record in the Domain Name System (DNS). I’v another post Primary DNS server configuration hope it will help you to configure your DNS server.

[root@dns ~]# vim  /var/named/example.fwd
IN      NS
IN      A
mail   IN    A
mail   IN   MX   10

[root@dns ~]# vim  /var/named/example.rev
IN     NS
IN     A
115   IN     PTR

Mail Server Configuration:

For full mail server, there are three Steps you need to complete.

  1. Postfix Installation (MTA) and Configuration
  2. Dovecot Installation (MDA) and Configuration
  3. Squirrelmail Installation (Web Access) and Configuration

Step 1. Postfix (MTA) Installation and Configuration:

Postfix is a free and open-source mail transfer agent. It routes and delivers electronic mail. Basically, postfix is a mail server that relays mail between different mail servers across the Internet. It attempts to be fast, easy to administer, and secure.

Login into your server and create two email user account (master and student) for email send/receive. Here /sbin/nologin means, the mail user can not login to the system.

[root@mail ~]# useradd  master  -s  /sbin/nologin
[root@mail ~]# passwd  master

[root@mail ~]# useradd student -s /sbin/nologin
[root@mail ~]# passwd student

If you are using rhel7 for your mail server configuration, need to configure yum server before any package installation. You can check Yum Server Configuration for installing of postfix and dovecot packages.

[root@mail ~]# yum install postfix -y

[root@mail ~]# systemctl enable postfix
[root@mail ~]# systemctl start postfix

Postfix use smtp protocol so need to enable smtp service in firewall.

[root@mail ~]# firewall-cmd  –permanent  –add-service=smtp
[root@mail ~]# firewall-cmd  –reload

Postfix have a configuration file named that need to modify/change the parameter with our requirements. Attention: Before any modification, always keep a backup of original conf file.

[root@mail ~]# vim  /etc/postfix/
myhostname =
mydomain =
myorigin = $mydomain
inet_interfaces = all
inet_protocols = ipv4
mydestination = $myhostname, localhost.$mydomain, localhost
mynetworks =,
relay_domains =
home_mailbox = Maildir/

:wq! (Save and Quit)

Restart the postfix after modifying the configuration file.

[root@mail ~]# systemctl  restart  postfix

Check postfix configuration by sending email to student from root user. Also check the log file for successful mail send.

[root@mail ~]# mail  -s  “Test Mail”
This is the test mail from root.

[root@mail ~]# tail  -f  /var/log/maillog

Step 2. Dovecot (MDA) Installation and Configuration:

Dovecot is an open-source IMAP and POP3 server for Linux/UNIX-like systems, written primarily with security in mind. Once Postfix is installed, mail can be sent to and from the server. Although without a mail server like Dovecot or Cyrus, you will only be able to see the email on the server.  It mean that if you want to read the email messages using your desktop email client software like outlook or webmail, this is absolutely required due to IMAP and POP3. So you need to install dovecot.

[root@mail ~]# yum  install  dovecot*  -y

[root@mail ~]# systemctl  enable  dovecot
[root@mail ~]# systemctl  start  dovecot

The main configuration file of dovecot is dovecot.conf which location is “/etc/dovecot/”. Keep a copy of original file before modify it. Here, i only shown the main line that need to change. Remove only “#” tag before the line start. Don’t touch other part of these configuration files.

[root@mail ~]# vim  /etc/dovecot/dovecot.conf
protocols = imap  pop3  lmtp

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

[root@mail ~]# systemctl  restart  dovecot

Step 3. Squirrelmail Installation and Configuration:

Squirrelmail is an open Source webmail project developed in PHP4. It includes built-in pure PHP support for the IMAP and SMTP protocols, and all pages render in pure HTML 4.0 (with no JavaScript required) for maximum compatibility across browsers. Any one can use this mail service to send and receive mails.

Install php with all dependency files for squirrelmail installation.

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

Download squirrelmail from their official page and upload it to the “/var/www/html/” location. or Direct download using “wget” command.

[root@mail ~]# cd  /var/www/html/

[root@mail html]# wget  https://squirrelmail-webmail-1.4.22.tar.gz
[root@mail html]# tar  -xvf  squirrelmail-webmail-1.4.22.tar.gz
[root@mail html]# mv  squirrelmail-webmail-1.4.22  webmail

Create two directory for squirrelmail:

[root@mail ~]# mkdir  -p  /var/local/squirrelmail/data
[root@mail ~]# mkdir  -p  /var/local/squirrelmail/attach

Give the ownership permission to apache to read/write access for webmail:

[root@mail ~]# chown  -R  apache:apache  /var/local/squirrelmail/data/
[root@mail ~]# chown  -R  apache:apache  /var/local/squirrelmail/attach/

Finally run the installation file ./ file and finish it step by step.

[root@mail ~]# cd  /var/www/html/webmail/config
[root@mail config]# ./
Command >> S
Command >> Q

Finally restart all the services that we start in the time of configuration.
[root@mail ~]# systemctl  restart  postfix
[root@mail ~]# systemctl  restart  dovecot
[root@mail ~]# systemctl  restart  httpd

Webmail Login:

Browse webmail using your FQDN (if your dns configured correctly):


Browse webmail using your IP Address (if have problem on name resolving):

Login with username (master/student) and password, send a successful mail to the other user.

Finished !!!

If you have any problem or question, please comment on comment section. I will reply back as soon as possible.