Linux Pathfinder: Linux Howtos and Tutorials

Install and Configure Mail Server Using Postfix, Dovecot and Squirrelmail On CentOS 6


Install & Configure Mail Server

The Postfix is a open source email server with high performance solution. There are many reasons to deploy Postfix Mail Transfer Agent on your environment. You can also setup Postfix to send email as an external SMTP provider like Google Apps and any other SMTP server. In this tutorial we will learn Postfix installation on Centos release 6.6 64-bit with IMAP/POP3 services like Dovecot and domains & users store information with mysql server. Now we will discuss in details how to install and configure mail server.

Prerequisites

If you have already sendmail MTA on your CentOS or RHEL, your need to uninstall it before installation of postfix MTA.

[root@mailserver ~]# yum remove sendmail

You have to add hostname entries on below host file.

[root@mailserver ~]# vim /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.100.11     mailserver.linuxpathfinder.local

Firewall and SELinux must be disabled.

You must have open/unblock standard mail ports (25, 465, 587, 110, 995, 143, and 993) that’s why disabled the iptables firewall.

[root@mailserver ~]# service iptables stop
[root@mailserver ~]# service ip6tables stop
[root@mailserver ~]# chkconfig iptables off
[root@mailserver ~]# chkconfig ip6tables off
[root@mailserver ~]# vim /etc/sysconfig/selinux
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of these two values:
#     targeted - Targeted processes are protected,
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted

Install Postfix

[root@mailserver ~]# yum install postfix

Configure Postfix

After installation, edit the postfix configuration file with vim editor (whatever you have editor). Search below mentioned lines and edit changes.

myhostname = mailserver.linuxpathfinder.local   # Line no 75 | Uncomment and set your mail server
mydomain = linuxpathfinder.local   # Line 83 | Uncomment and Set domain name
myorigin = $mydomain   # Line 99 | Uncomment
inet_interfaces = all   # Line 116 | Set ipv4
inet_protocols = all   # Line 119 | Change to all
#mydestination = $myhostname, localhost.$mydomain, localhost,   # Line 164 | Comment
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain   # Line 165 | Uncomment
mynetworks = 192.168.100.0/24, 127.0.0.0/8   # Line 264 | Uncomment and add IP range
home_mailbox = Maildir/   # Line 419 | Uncomment

Save the config file and exit from editor. Now start Postfix service.

[root@mailserver ~]# service postfix start
[root@mailserver ~]# chkconfig postfix on

Test Postfix

We’ll create users to test postfix mail server.

[root@mailserver ~]# useradd user1
[root@mailserver ~]# passwd user1
[root@mailserver ~]# useradd user2
[root@mailserver ~]# passwd user2

Below are the configuration entered by the user. Must put the dot (.) after the message.

[root@mailserver ~]# telnet localhost smtp
Trying ::1...
Connected to localhost.
Escape character is '^]'.
220 server.linuxpathfinder.local ESMTP Postfix
ehlo localhost
250-server.linuxpathfinder.local
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
mail from:<user1>
250 2.1.0 Ok
rcpt to:<user1>
250 2.1.5 Ok
data
354 End data with <CR><LF>.<CR><LF>
welcome to postfix mail server
.
250 2.0.0 Ok: queued as AC079411B3
quit
221 2.0.0 Bye
Connection closed by foreign host.

Verify Mail

Go to the user’s directory and check the new mail.

[root@mailserver ~]# cd /home/user1/Maildir/new
[root@mailserver new]# ls
1439228640.Vfd00Ic19bbM70513.server.linuxpathfinder.local
[root@mailserver new]# cat 1439228640.Vfd00Ic19bbM70513.server.linuxpathfinder.local
Return-Path: <user1@linuxpathfinder.local>
X-Original-To: user1
Delivered-To: user1@linuxpathfinder.local
Received: from localhost (localhost [IPv6:::1])
by server.linuxpathfinder.local (Postfix) with ESMTP id AC079411B3
for <user1>; Mon, 10 Aug 2015 22:41:58 +0500 (PKT)
Message-Id: <20150810174241.AC079411B3@server.linuxpathfinder.local>
Date: Mon, 10 Aug 2015 22:41:58 +0500 (PKT)
From: user1@linuxpathfinder.local
To: undisclosed-recipients:;welcome to postfix server

It shows that postfix configuration is OK.

Install Dovecot

Dovecot (open source) is used for IMAP/POP3 mail services in Linux systems.

[root@mailserver ~]# yum install dovecot

Configure Dovecot

Edit the config file /etc/dovecot/dovecot.conf

[root@mailserver ~]# vim /etc/dovecot/dovecot.conf
protocols = imap pop3 lmtp # line 20 | uncomment

Open the file /etc/dovecot/conf.d/10-mail.conf file

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

Open next config file /etc/dovecot/conf.d/10-auth.conf

[root@mailserver ~]# vim /etc/dovecot/conf.d/10-auth.conf
disable_plaintext_auth = no # line 9 | uncomment and write no
auth_mechanisms = plain login # line 97 | Add 'login' letter

Open next file /etc/dovecot/conf.d/10-master.conf,

[root@mailserver ~]# vim /etc/dovecot/conf.d/10-master.conf
#mode = 0600     # lines 83-84 | uncomment and write 'postfix'
user = postfix
group = postfix

Save the config files and start dovecot service.

[root@mailserver ~]# service dovecot start
Starting Dovecot Imap:                                     [  OK  ]
[root@mailserver ~]# chkconfig dovecot on

Test Dovecot

Test dovecot with following configuration.

[root@mailserver ~]# telnet localhost pop3
Trying ::1...
Connected to localhost.
Escape character is '^]'.
+OK Dovecot ready.
user user1
+OK
pass user1
+OK Logged in.
list
+OK 1 messages:
1 494
.
retr 1
+OK 494 octets
Return-Path: <user1@linuxpathfinder.local>
X-Original-To: user1
Delivered-To: user1@linuxpathfinder.local
Received: from localhost (localhost [IPv6:::1])
by server.linuxpathfinder.local (Postfix) with ESMTP id AC079411B3
for <user1>; Mon, 10 Aug 2015 22:41:58 +0500 (PKT)
Message-Id: <20150810174241.AC079411B3@server.linuxpathfinder.local>
Date: Mon, 10 Aug 2015 22:41:58 +0500 (PKT)
From: user1@linuxpathfinder.local
To: undisclosed-recipients:;welcome to postfix mail server
.
quit
+OK Logging out.
Connection closed by foreign host.

It shows that dovecot configuration is OK.

Install Squirrelmail

Before installation of squirrelmail package from yum. You must install EPEL repository on your server then install with showing below command.

[root@mailserver ~]# yum install squirrelmail

Configure Squirrelmail

Go to configuration directory of squirrelmail and start configuring with command as shown below:

[root@mailserver ~]# cd /usr/share/squirrelmail/config/
[root@server config]# ./conf.plSquirrelMail 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. LanguagesD.  Set pre-defined settings for specific IMAP serversC   Turn color off
S   Save data
Q   QuitCommand >> 1

Select 1 for organizational details.
New wizard will open and press 1 option 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          : SquirrelMailR   Return to Main Menu
C   Turn color off
S   Save data
Q   QuitCommand >> 1

Put your organization name.

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]: linuxpathfinder

After done above changes save it and return back to your main menu. Enter option “2” to setting up of Server settings now.

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” option now.

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]: linuxpathfinder.local

Enter “3” option to change Postfix MTA (SMTP)

SquirrelMail Configuration : Read: config.php (1.4.0)
---------------------------------------------------------
Server Settings
General
-------
1.  Domain                 : linuxpathfinder.local
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 choose postfix (SMTP).

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 save SquirrelMail configuration and exit.

Create a Virtual Host of squirrelmail in apache configuration file as follows:

[root@mailserver ~]# vim /etc/httpd/conf/httpd.conf

Same following lines need to add at the bottom of the apache configuration file.

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

After changes in apache config file, you need to restart the apache services to change effect.

[root@mailserver ~]# service httpd restart

Now you have to create some users for email testing.

[root@mailserver ~]# useradd mailuser1
[root@mailserver ~]# useradd mailuser2
[root@mailserver ~]# passwd mailuser1
[root@mailserver ~]# passwd mailuser2

You may now open webmail like ip-address/mywebmail or domain-name/mywebmail. Screen should look like on your browser as shown below now put your newly created user’s credentials into mywebmail.

Squirrel Mail
Squirrel Mail

You have got the access of user named ‘mailuser1’. Now compose an email from your mail box to send email to other webmail user named mailuser2. In compose mailbox, put the second user mail id in recipient, and write mail and click send button.

User1 Inbox
User1 Inbox

Logout the current user and login second test user and check email.

User2 Inbox
User2 Inbox

You will see new email to mail ID mailuser2.linuxpathfinder.local as shown.

Email Get to User2
Email Get to User2

That’s it.

Share this article:

Asif Khan's picture
I am an experienced Linux System and Network Administrator with having more than 6 years of experience. My primary responsibilities are to keep up and running Linux system environment, backups important data with scripting and configuration management on AWS Linux server environments. My aim is to help people, in finding their path towards a solution to their problems. Well, I believe helping others can good for both parties, to them and to you as well. That day and today is the day that thousands of people seek help from my website to help people find answers to their questions. I am sure that everyone will get all the answers to their questions related to software and operating system, and this website will help you keep your system updated.

Add new comment

Image CAPTCHA

Enter the characters shown in the image.