郵件服務器安裝--Postfix + Dovecot + Squirrelmail--CentOS 6.4

英文原文連接 : http://www.unixmen.com/install-postfix-mail-server-with-dovecot-and-squirrelmail-on-centos-6-4/php

 

Postfix 是一款免費開源的 MTA. 兼顧易於管理, 響應快速, 安全有效的優勢. 它也是 RHEL(CentOS) 默認的 MTA.web

 

前期準備apache

1. 卸載原始 MTA sendmail:centos

[root@server ~]# yum remove sendmail

2. 配置 DNS 服務器並添加郵件服務器 MX 記錄. 並讓 ISP 支持你的靜態 IP 與域名. (局域網搭建跳過此步驟)安全

3.1 在 /etc/hosts 加入完整的 hostname:服務器

[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.cnblogs.com      server

3.2 在 /etc/sysconfig/network 更改 hostname:dom

[root@server ~]# vi /etc/sysconfig/network
HOSTNAME=server.cnblogs.com

3.3 重啓 Linux 使 hostname 生效.tcp

[root@server ~]# reboot

4. 關閉 SELinux 來下降配置 postfix 的難度. ( 不關閉網頁登不上 )ide

[root@server ~]# setenforce 0

5. 安裝 EPEL Repository: (根據本身的機器選擇)post

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

6. 給 Apache(後續進行安裝) 開放 80 端口:

[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

安裝 Postfix

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

配置 Postfix

打開 /etc/postfix/main.cf 更改以下配置:

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

## Line 83 - Uncomment and Set domain name ##
mydomain = cnblogs.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/

保存並退出, 重啓 Postfix 服務:

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

測試 Postfix

經過 telnet 進行測試, 沒有 telnet 可經過 yum 安裝, 一下出現紅色字體表示輸入.

新建測試用戶 zl:

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

進入 zl mail 目錄檢查郵件:

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

welcome to cnblogs mail system

安裝 Dovecot

Dovecote 是一款開源 IMAP/POP3 郵件服務器 for Unix/Linux systems.

[root@server ~]# yum install dovecot

配置 Dovecot

打開 /etc/dovecot/dovecot.conf 更改以下配置:

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

打開 /etc/dovecot/conf.d/10-mail.conf:

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

打開 /etc/dovecot/conf.d/10-auth.conf:

## line 9 - uncomment##
disable_plaintext_auth = yes

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

打開 /etc/dovecot/conf.d/10-master.conf:

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

開啓 Dovecot 服務:

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

測試 Dovecot

 

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

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

Dovecot 測試成功.

安裝 Squirrelmail WebMail

安裝 Squirrelmail:

[root@server ~]# yum install squirrelmail

配置 Squirrelmail

切換到 /usr/share/squirrelmail/config/ 並運行 conf.pl:

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

( 可選 ) 進入 1.  Organization Preferences 設置定製的網頁圖標等等.

( 必須 ) 進入 2.  Server Settings -> 1.  Domain 設置本身的 domain.

( 必須 ) 進入 2.  Server Settings -> 3.  Sendmail or SMTP 設置成 SMTP.

回到主界面按 S & Q 保存並退出.

Apache 關聯 Squirrelmail

在 apache 配置文件中新建一個 squirrelmail vhost:

[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>

重啓 Apache 服務:

[root@server config]# service httpd restart

到此環境搭建完成!

 

PS: Webmail 登陸時只要輸用戶名便可, 不用輸 @cnblogs.com . 使用的用戶必須通過密碼初始化, 即 passwd user.

     http://ip-address/webmail or http://domain-name/webmail 訪問 Webmail

相關文章
相關標籤/搜索