Install Postfix Mail Server with Dovecot and Squirrelmail on CentOS 6.4

Postfix is a free open source mail transfer agent (MTA). It is easy to administer, fast and as well as secure MTA. Its a alternative to Sendmail which is the default MTA for RHEL.

Prerequisites

1. Remove default MTA sendmail first:

[root@server ~]# yum remove sendmail

2. Setup DNS server and add the Mail server MX records in the forward and reverse zone files. To install and configure DNS server, navigate to this link. And you’ll need to contact your ISP to point your external static IP to your mail domain.

3. Add hostname entries in /etc/hosts file as shown below:

[root@server ~]# [root@server ~]# vi /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.1.200   server.unixmen.com      server

4. I disabled SELinux to reduce complexity in postfix configuration.

5. Install EPEL Repository:

[root@server ~]# rpm -ivh http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm

6. Allow the Apache default port 80 through your firewall/router:

[root@server ~]# vi /etc/sysconfig/iptables
-A INPUT -p udp -m state --state NEW --dport 80 -j ACCEPT
-A INPUT -p tcp -m state --state NEW --dport 80 -j ACCEPT

Install Postfix

In this how-to, my testbox hostname and password are server.unixmen.com and 192.168.1.250 respectively. Change these values as per your scenario:

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

Configuring Postfix

Open Postfix config file /etc/postfix/main.cf and find and edit the following lines:

## Line no 75 - Uncomment and set your mail server FQDN ##
myhostname = server.unixmen.com

## Line 83 - Uncomment and Set domain name ##
mydomain = unixmen.com

## Line 99 - Uncomment ##
myorigin = $mydomain

## Line 116 - Set ipv4 ##
inet_interfaces = all

## Line 119 - Change to all ##
inet_protocols = all

## Line 164 - Comment ##

#mydestination = $myhostname, localhost.$mydomain, localhost,

## Line 165 - Uncomment ##\
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain

## Line 264 - Uncomment and add IP range ##
mynetworks = 192.168.1.0/24, 127.0.0.0/8

## Line 419 - Uncomment ##
home_mailbox = Maildir/

Save and exit the file. Start Postfix service now:

[root@server ~]# /etc/init.d/postfix start
[root@server ~]# /etc/init.d/postfix status
master (pid  1290) is running...
[root@server ~]# chkconfig postfix on

Testing Postfix mail server

Access the server via telnet and enter the commands shown in red colored text.

First create a testing user called “sk”:

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

Now navigate to the user “sk” mail directory and check for the new mail:

[root@server ~]# ls /home/sk/Maildir/new/
1369816264.Vfd00I41ec0M251771.server.unixmen.com

A new mail is received to the user “sk”. To read the mail enter the following command:

[root@server ~]# cat /home/sk/Maildir/new/1369816264.Vfd00I41ec0M251771.server.unixmen.com 
Return-Path: <sk@unixmen.com>
X-Original-To: sk
Delivered-To: sk@unixmen.com
Received: from localhost (localhost [IPv6:::1])
    by server.unixmen.com (Postfix) with ESMTP id 3E68E284C
    for <sk>; Wed, 29 May 2013 14:00:36 +0530 (IST)
Message-Id: <20130529083047.3E68E284C@server.unixmen.com>
Date: Wed, 29 May 2013 14:00:36 +0530 (IST)
From: sk@unixmen.com
To: undisclosed-recipients:;

welcome to unixmen mail system

Installing Dovecot

Dovecote is an open source IMAP and POP3 mail server for Unix/Linux systems. To install:

[root@server ~]# yum install dovecot

Configuring Dovecot

Open the file /etc/dovecot/dovecot.conf file and edit as follows:

## Line 20 - umcomment ##
protocols = imap pop3 lmtp

Open /etc/dovecot/conf.d/10-mail.conf file and make the changes as shown below:

[root@server ~]# vi /etc/dovecot/conf.d/10-mail.conf 

## Line 24 - uncomment ##
mail_location = maildir:~/Maildir

Open /etc/dovecot/conf.d/10-auth.conf  and make the changes as shown below:

[root@server ~]# vi /etc/dovecot/conf.d/10-auth.conf 

## line 9 - uncomment##
disable_plaintext_auth = yes

## Line 99- Add a letter "login" ##
auth_mechanisms = plain login

Open the file /etc/dovecot/conf.d/10-master.conf and make changes as shown below:

[root@server ~]# vi /etc/dovecot/conf.d/10-master.conf 

## Line 83, 84 - Uncomment and add "postfix"
#mode = 0600
   user = postfix
    group = postfix

Start Dovecot service:

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

Testing Dovecot

It’s time to test Dovecot configuration.

Enter the commands manually marked in red color:

[root@server ~]# telnet localhost pop3
Trying ::1...
Connected to localhost.
Escape character is '^]'.
+OK Dovecot ready.
user sk
+OK
pass centos      ## Here centos is password of user "sk" ##
+OK Logged in.
list
+OK 1 messages:
1 427
.
retr 1
+OK 427 octets
Return-Path: <sk@unixmen.com>
X-Original-To: sk
Delivered-To: sk@unixmen.com
Received: from localhost (localhost [IPv6:::1])
    by server.unixmen.com (Postfix) with ESMTP id 3E68E284C
    for <sk>; Wed, 29 May 2013 14:00:36 +0530 (IST)
Message-Id: <20130529083047.3E68E284C@server.unixmen.com>
Date: Wed, 29 May 2013 14:00:36 +0530 (IST)
From: sk@unixmen.com
To: undisclosed-recipients:;

welcome to unixmen mail system
.
quit
+OK Logging out.
Connection closed by foreign host.

Now Dovecot is working.

Working with mail in command modes little bit difficult to us. So we will install a webmail client called Squirrelmail to send/receive emails via web browser.

Installing Squirrelmail

Make sure that you installed EPEL repository. Now install Squirrelmail using the following command:

[root@server ~]# yum install squirrelmail -y

Configuring Squirrelmail

Navigate to /usr/share/squirrelmail/config/ directory and run the command conf.pl:

[root@server ~]# cd /usr/share/squirrelmail/config/
[root@server config]# ./conf.pl

The following wizard will open. Enter choice 1 to set your organization details:

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

The following wizard will open:

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

Again enter choice 1 to set your Organization name and enter all the details:

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]: unixmen mail

After setup all the details in the above wizard press S to save changes and press R to return back to your main menu:

SquirrelMail Configuration : Read: config.php (1.4.0)
---------------------------------------------------------
Organization Preferences
1.  Organization Name      : unixmen mail
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 >> s

Now enter R to setup mail server settings such as domain name and mail agent etc.:

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 and set your mail domain name:

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

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                 : unixmen
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
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 and Q to save and exit Squirrelmail configuration.

Create a squirrelmail vhost in apache config file:

[root@server config]# vi /etc/httpd/conf/httpd.conf 
## Add the lines at the end of this file ##
Alias /squirrelmail /usr/share/squirrelmail
<Directory /usr/share/squirrelmail>
    Options Indexes FollowSymLinks
    RewriteEngine On
    AllowOverride All
    DirectoryIndex index.php
    Order allow,deny
    Allow from all
</Directory>

Restart Apache service:

[root@server config]# service httpd restart

Create users

Create some users for testing. In my case i create two users called “senthil” and “kumar” respectively.

[root@server ~]# useradd senthil
[root@server ~]# useradd kumar
[root@server ~]# passwd senthil
[root@server ~]# passwd kumar

Webmail

Now navigate to http://ip-address/webmail or http://domain-name/webmail from your browser. The following should appear. Enter the username and password of the user.

unixmen mail - Login - Mozilla Firefox_001

Let us compose a test mail from user “senthil” to user “kumar”.

unixmen mail - Login - Mozilla Firefox_001

Now login to user “kumar” mail and check for any new mail.

SquirrelMail 1.4.22-3.el6 - Mozilla Firefox_003

There it is. We have got ourselves a new email

source: http://www.unixmen.com/install-postfix-mail-server-with-dovecot-and-squirrelmail-on-centos-6-4/

注: 这是一篇比较有分量的文章, 建议大家好好参考.

转载于:https://www.cnblogs.com/wwufengg/articles/CentOS-Postfix-Dovecot-Postfixadmin-Squirrelmail.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值