Install and Configure postfix, dovecot & Squirrelmail on CentOS 7

 

Sequence 1. Setup Prerequisites

    1. Remove default MTA

      sendmail

      if it’s already installed.
# yum remove sendmail
    1. Add hostname entry in /etc/hosts file:
192.168.1.150 server1.example.com server1    #Check your IP address with ip a
    1. Disable SELinux to reduce the complexity in postfix configuration.
vi /etc/sysconfig/selinux SELINUX=disabled
    1. Install EPEL Repository if not installed
yum install epel-release
    1. Allow the Apache default port 80 through your firewall/router:
firewall-cmd --permanent --add-port=80/tcp firewall-cmd --reload

 

Sequence 2. Install Postfix

Postfix

 is a free open source mail transfer agent (MTA). It is fast, secure and easy to administer. It’s an alternative to Sendmail.

    1. Install Postifix using command:
yum install postfix
    1. Configuring Postfix by edit /etc/postfix/main.cf file:
# vi /etc/postfix/main.cf # Line no 77 - Uncomment and set to your FQDN myhostname = server1.example.com mydomain = example.com     # Line 85 - Uncomment and Set domain name myorigin = $mydomain       # Line 101 - Uncomment inet_interfaces = all      # Line 115 - Uncomment and Set ipv4 inet_protocols = all       # Line 121 - Change to all # Line 166 - Comment #mydestination = $myhostname, localhost.$mydomain, localhost, # Line 167 - Uncomment mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain mynetworks = 192.168.1.0/24, 127.0.0.0/8 # Line 266 - Uncomment & add IP range home_mailbox = Maildir/    # Line 421 - Uncomment
    1. Start/restart Postfix service now:
systemctl enable postfix systemctl restart postfix

Sequence 3.  Testing Postfix mail server

    1. Create a test user called “sangwan“.
useradd sangwan
    1. Set the password for the user:
passwd sangwan
    1. Access the server via Telnet and enter the commands manually shown in red colored text.
telnet localhost smtp Sample output: Trying ::1... Connected to localhost. Escape character is '^]'. 220 server1.example.com ESMTP Postfix

ehlo localhost             # Type this line

250-server1.example.com 250-PIPELINING 250-SIZE 10240000 250-VRFY 250-ETRN 250-ENHANCEDSTATUSCODES 250-8BITMIME 250 DSN

mail from:        # Mail sender address

250 2.1.0 Ok

rcpt to:          # Mail receiver address

250 2.1.5 Ok

data                       # To input body of Email

354 End data with .

Welcome to TheSkillPedia mail server     # Body of the Email

.                          # After you finished with content

250 2.0.0 Ok: queued as E2B522032F93

quit                       # Exit from mail

221 2.0.0 Bye Connection closed by foreign host.

 

    1. Now navigate to the user “sangwan“ mail directory and check whether the new mail has been received.
ls /home/sangwan/Maildir/new/ Sample output: 1437722056.Vfd01I203e3e7M938078.server1.example.com Success! A new mail is received to the user “sangwan“.
    1. To read the mail, enter the following command:
cat /home/sangwan/Maildir/new/1437722056.Vfd01I203e3e7M938078.server1.example.com Sample output: Return-Path: X-Original-To: sangwan Delivered-To: sangwan@example.com Received: from localhost (localhost [IPv6:::1]) by server1.example.com (Postfix) with ESMTP id E2B522032F93 for ; Fri, 24 Jul 2015 12:42:36 +0530 (IST) Message-Id: <20150724071330.E2B522032F93@server1.example.com> Date: Fri, 24 Jul 2015 12:42:36 +0530 (IST) From: sangwan@example.com Welcome to TheSkillPedia mail server

 

Sequence 4. Install Dovecot

Dovecot

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

    1. To install it, run:
yum install dovecot
    1. Configuring Dovecot by editing file /etc/dovecot/dovecot.conf ,
vi /etc/dovecot/dovecot.conf protocols = imap pop3 lmtp             # Line 24 - umcomment
    1. Edit file /etc/dovecot/conf.d/10-mail.conf file
vi /etc/dovecot/conf.d/10-mail.conf mail_location = maildir:~/Maildir      # Line 24 - uncomment
    1. Edit /etc/dovecot/conf.d/10-auth.conf
vi /etc/dovecot/conf.d/10-auth.conf disable_plaintext_auth = yes           #line 10 - uncomment auth_mechanisms = plain login          #Line 100 - Add the word: "login"
    1. Edit file /etc/dovecot/conf.d/10-master.conf,
vi /etc/dovecot/conf.d/10-master.conf #Line 91, 92 - Uncomment and add "postfix" #mode = 0600  user = postfix   group = postfix
    1. Start Dovecot service:
systemctl enable dovecot systemctl start dovecot

 

Sequence 5. Testing Dovecot

    1. Enter the following command in Terminal:
telnet localhost pop3
    1. Enter the commands given marked with comment:
Trying ::1... Connected to localhost. Escape character is '^]'. +OK Dovecot ready.

user sangwan               #Enter the mail user name

+OK

pass centos                #Enter the password

+OK Logged in.

retr 1                     #Type this command to view mail

+OK 415 octets Return-Path: X-Original-To: sangwan Delivered-To: sangwan@example.com Received: from localhost (localhost [IPv6:::1]) by server1.example.com (Postfix) with ESMTP id E2B522032F93 for ; Fri, 24 Jul 2015 12:42:36 +0530 (IST) Message-Id: <20150724071330.E2B522032F93@server1.example.com> Date: Fri, 24 Jul 2015 12:42:36 +0530 (IST) From: sangwan@example.com Welcome to TheSkillPedia mail server .

quit                       #Type 'quit' to exit

+OK Logging out. Connection closed by foreign host.

 

 

Sequence 6. Install Squirrelmail

[the_ad id="2469"] We can easily send/receive mails using webmail client called 

Squirrelmail

 via a web browser. Make sure that you’ve installed and enabled EPEL repository.

    1. Install Squirrelmail:
# yum install squirrelmail
    1. Change to 

      /usr/share/squirrelmail/config/

       and run conf.pl
# cd /usr/share/squirrelmail/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 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 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]: TheSkillPedia Similarly, set all the details such as organization title, logo, provider name in the above wizard. Once you done, press 

“S”

 to save the changes, and press 

“R”

 to return back to your main menu: SquirrelMail Configuration : Read: config.php (1.4.0) --------------------------------------------------------- Organization Preferences 1.  Organization Name      : TheSkillPedia 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          : TheSkillPedia Mail R   Return to Main Menu C   Turn color off S   Save data Q   Quit Command >> S Then R to return to main menu 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 Enter “1”, Enter your mail domain (ex. TheSkillPedia. local) and press Enter key. SquirrelMail Configuration : Read: config.php (1.4.0) --------------------------------------------------------- Server Settings General ------- 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 jdoe@example.com, then your domain would be example.com. [localhost]: example.com Enter “3” and change from sendmail to Postfix MTA (i.e. SMTP): SquirrelMail Configuration : Read: config.php (1.4.0) --------------------------------------------------------- Server Settings General ------- 1.  Domain                 : example.com 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 Enter “2” to switch from sendmail MTA to postfix. 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 enter “S” followed by “Q” to save and exit Squirrelmail configuration.

    1. Create a squirrelmail vhost in apache config file:
vi /etc/httpd/conf/httpd.conf Add the following lines at the end: Alias /webmail /usr/share/squirrelmail Options Indexes FollowSymLinks RewriteEngine On AllowOverride All DirectoryIndex index.php Order allow,deny Allow from all
    1. Restart the Apache service:
systemctl restart httpd

 

Sequence 7. Access Webmail

Now navigate to

http://ip-address/webmail

or

http://example.com/webmail

 from your browser. From this interface, you can send and receive mails to local users on this server.

Complete this lab successfully and avail 80% discount on any course on this website. Drop a mail with screenshot at admin@theskillpedia.com and we will share the discount coupon with you.

Take a look at the Courses offered with Course Contents at https://www.theskillpedia.com/category/course-contents/ [the_ad id="2469"]