Set up a mail server using Postfix, Dovecot, and SquirrelMail on CentOS
Remove sendmail from the server before installing postfix. This is because sendmail is the default MTA for Redhat / CentOS.
[[email protected] ~]# yum remove sendmail
Prerequisites:
- The mail server must have a valid MX record in the DNS server. invite This link How to set up a DNS server.
- You need to disable your firewall and SELinux.
[[email protected] ~]# service iptables stop [[email protected] ~]# service ip6tables stop [[email protected] ~]# chkconfig iptables off [[email protected] ~]# chkconfig ip6tables off
[[email protected] ~]# vi /etc/selinux/config # 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
Restart the server.
scenario
In this tutorial, the test box
- Host name = server.ostechnix.com
- IP address = 192.168.1.200/24
And my server is configured with the appropriate MX records for the DNS server.
Installation
Postfix is installed by default. If it is not installed, install postfix using the following command.
[[email protected] ~]# yum install postfix
Constitution
Open the postfix configuration file /etc/postfix/main.cf. Find the following line and edit it as follows:
[[email protected] ~]# vi /etc/postfix/main.cf myhostname = server.ostechnix.com ##line no 75 - uncomment and enter your host name mydomain = ostechnix.com ##line no 83 - uncomment and enter your domain name myorigin = $mydomain ##line no 99 - uncomment inet_interfaces = all ##line no 116 - change to all mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain ##line no 164 - add $domain at the end mynetworks = 192.168.1.0/24, 127.0.0.0/8 ##line no 264 - uncomment and add your network range home_mailbox = Maildir/ ##line no 419 - uncomment
Start the postfix service.
[[email protected] ~]# service postfix start Starting postfix: [ OK ] [[email protected] ~]# chkconfig postfix on
Post test
Commands shown in bold must be entered by the user.
Note: The dot after the test command is significant.
[[email protected] ~]# telnet localhost smtp Trying ::1... Connected to localhost. Escape character is '^]'. 220 server.ostechnix.com ESMTP Postfix ehlo localhost 250-server.ostechnix.com 250-PIPELINING 250-SIZE 10240000 250-VRFY 250-ETRN 250-ENHANCEDSTATUSCODES 250-8BITMIME 250 DSN mail from:250 2.1.0 Ok rcpt to: 250 2.1.5 Ok data 354 End data with . test . 250 2.0.0 Ok: queued as 117113FF18 quit 221 2.0.0 Bye Connection closed by foreign host.
Check email
Go to the user’s mail directory and check for new mail.
[[email protected] ~]# cd /home/user1/Maildir/new/ [[email protected] new]# ls 1360236956.Vfd00I35afM181256.server.ostechnix.com [[email protected] new]# cat 1360236956.Vfd00I35afM181256.server.ostechnix.com Return-Path: <[email protected]> X-Original-To: user1 Delivered-To: [email protected] Received: from localhost (localhost [IPv6:::1]) by server.ostechnix.com (Postfix) with ESMTP id 117113FF18 for; Thu, 7 Feb 2013 17:05:32 +0530 (IST) Message-Id: <[email protected]> Date: Thu, 7 Feb 2013 17:05:32 +0530 (IST) From: [email protected] To: undisclosed-recipients:; test
that’s it. Postfix is currently running.
Install Dovecot
[[email protected] ~]# yum install dovecot
Configure Dovecot
Open the dovecot configuration file /etc/dovecot/dovecot.conf. Find the line and uncomment it, as shown below.
[[email protected] ~]# vi /etc/dovecot/dovecot.conf protocols = imap pop3 lmtp
Open the file /etc/dovecot/conf.d/10-mail.conf and uncomment the line as follows:
[[email protected] ~]# vi /etc/dovecot/conf.d/10-mail.conf mail_location = maildir:~/Maildir ##line no 24 - uncomment
Open /etc/dovecot/conf.d/10-auth.conf and edit as shown below.
[[email protected] ~]# vi /etc/dovecot/conf.d/10-auth.conf disable_plaintext_auth = no ##line no 9 - uncomment and change from yes to no. auth_mechanisms = plain login ##line no 97 - add the text "login"
Open /etc/dovecot/conf.d/10-master.conf and edit as shown below.
unix_listener auth-userdb { #mode = 0600 user = postfix ##line no 83 - uncomment and enter postfix group = postfix ##line no 84 - uncomment and enter postfix
Start dovecot service.
[[email protected] ~]# service dovecot start Starting Dovecot Imap: [ OK ] [[email protected] ~]# chkconfig dovecot on
Test dovecot
Commands shown in bold must be entered by the user.
[[email protected] ~]# 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 428 . retr 1 +OK 428 octets Return-Path: <[email protected]> X-Original-To: user1 Delivered-To: [email protected] Received: from localhost (localhost [IPv6:::1]) by server.ostechnix.com (Postfix) with ESMTP id 117113FF18 for; Thu, 7 Feb 2013 17:05:32 +0530 (IST) Message-Id: <[email protected]> Date: Thu, 7 Feb 2013 17:05:32 +0530 (IST) From: [email protected] To: undisclosed-recipients:; test . quit +OK Logging out. Connection closed by foreign host. [[email protected] ~]#
Dovecot is currently running.
Install Squirrelmail
First, install the EPEL repository. Then install the SquirrelMail package from the EPEL repository.
[[email protected] ~]# wget http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm [[email protected] ~]# rpm -ivh epel-release-6-8.noarch.rpm [[email protected] ~]# yum install squirrelmail [[email protected] ~]# service httpd start Starting httpd: [ OK ] [[email protected] ~]# chkconfig httpd on [[email protected] ~]#
Configure Squirrelmail
Go to the squirrelmail config directory and use the command ./conf.pl to start configure as shown below.
[[email protected] ~]# cd /usr/share/squirrelmail/config/ [[email protected] 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
Select option 1 and set your organization details.
SquirrelMail Configuration : Read: config.php (1.4.0) --------------------------------------------------------- Organization Preferences 1. Organization Name : Ostechnix 2. Organization Logo : ../images/sm_logo.png 3. Org. Logo Width/Height : (308/111) 4. Organization Title : Welcome to Ostechnix webmail 5. Signout Page : 6. Top Frame : _top 7. Provider link : https://ostechnix.com 8. Provider name : Ostechnix R Return to Main Menu C Turn color off S Save data Q Quit Command >>R
Press R to return to the main menu and select option 2. Enter your domain name and select dovecot for Sendmail or SMTP parameters.
SquirrelMail Configuration : Read: config.php (1.4.0) --------------------------------------------------------- Server Settings General ------- 1. Domain : ostechnix.com 2. Invert Time : false 3. Sendmail or SMTP : SMTP 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 >> S
When done, press S to save the data and press Q to exit.
Add the following line to the end of the httpd.conf file:
[[email protected] ~]# vi /etc/httpd/conf/httpd.conf Alias /squirrelmail /usr/share/squirrelmailOptions Indexes FollowSymLinks RewriteEngine On AllowOverride All DirectoryIndex index.php Order allow,deny Allow from all
Restart the httpd service.
[[email protected] ~]# service httpd restart Stopping httpd: [ OK ] Starting httpd: [ OK ] [[email protected] ~]#
Create a user
[[email protected] ~]# useradd user1 [[email protected] ~]# useradd user2 [[email protected] ~]# passwd user1 [[email protected] ~]# passwd user2
Open a browser from any client. Enter the following in the address bar:
http://serveripaddress/webmail
Or
http://yourdomainname/webmail
Now, let’s create an email from user1 to user2. See the screenshot below.
Next, sign out and sign in from user2.
that’s it. An email has been received from user1. If you have any configuration issues, please post in the comments section.
have a good day.
.