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

0
395

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   mail.example.com

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

[root@localhost ~]# vim  /etc/resolv.conf
search example.com
nameserver   192.168.20.115

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

[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    mail.example.com.
IN      A      192.168.20.115
mail   IN    A     192.168.20.115
mail   IN   MX   10  mail.example.com.

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

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 main.cf 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/main.cf
myhostname = mail.example.com
mydomain = example.com
myorigin = $mydomain
inet_interfaces = all
inet_protocols = ipv4
mydestination = $myhostname, localhost.$mydomain, localhost
mynetworks = 127.0.0.0/8, 192.168.20.0/24
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”  student@mail.example.com
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 ./conf.pl file and finish it step by step.

[root@mail ~]# cd  /var/www/html/webmail/config
[root@mail config]# ./conf.pl
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): http://mail.example.com/webmail

or

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

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.

LEAVE A REPLY

Please enter your comment!
Please enter your name here