在CentOS中使用Postfix,Dovecot和SquirrelMail设置邮件服务器

在安装postfix之前,请从服务器中删除sendmail。因为sendmail是Redhat / CentOS中的默认MTA。

[[email protected] ~]# yum remove sendmail

先决条件:

  • 邮件服务器应在DNS服务器中包含有效的MX记录。导航 这个连结 如何设置DNS服务器。
  • 应禁用防火墙和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

重新启动服务器。

情境

在本教程中,我的测试框

  • 主机名= server.ostechnix.com
  • IP地址= 192.168.1.200/24

并且我的服务器在DNS服务器中配置了正确的MX记录。

安装

默认情况下安装了Postfix。如果尚未安装,请使用以下命令安装后缀。

[[email protected] ~]# yum install postfix

组态

打开后缀配置文件/etc/postfix/main.cf。找到以下几行并进行编辑,如下所示。

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

启动后缀服务。

[[email protected] ~]# service postfix start
Starting postfix:                                          [  OK  ]
[[email protected] ~]# chkconfig postfix on

测试后缀

用户应输入以粗体字母显示的命令。
注意:测试命令后的点很重要。

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

检查邮件

导航到用户邮件目录,然后检查新邮件。

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

而已。 Postfix现在工作。

安装鸽舍

[[email protected] ~]# yum install dovecot

配置鸽舍

打开dovecot配置文件/etc/dovecot/dovecot.conf。找到并取消注释该行,如下所示。

[[email protected] ~]# vi /etc/dovecot/dovecot.conf
protocols = imap pop3 lmtp

打开文件/etc/dovecot/conf.d/10-mail.conf并取消注释该行,如下所示。

[[email protected] ~]# vi /etc/dovecot/conf.d/10-mail.conf
mail_location = maildir:~/Maildir  ##line no 24 - uncomment

打开/etc/dovecot/conf.d/10-auth.conf并进行如下编辑。

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

打开/etc/dovecot/conf.d/10-master.conf并进行如下编辑。

unix_listener auth-userdb {
    #mode = 0600
    user = postfix  ##line no 83 - uncomment and enter postfix
    group = postfix  ##line no 84 - uncomment and enter postfix

启动鸽舍服务。

[[email protected] ~]# service dovecot start
Starting Dovecot Imap:                                     [  OK  ]
[[email protected] ~]# chkconfig dovecot on

测试鸽舍

粗体显示的命令应由用户输入。

[[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现在正在工作。

安装Squirrelmail

首先安装EPEL存储库。并从EPEL存储库安装SquirrelMail软件包。

[[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] ~]#

配置Squirrelmail

转到squirrelmail config目录,然后使用命令./conf.pl开始配置,如下所示。

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

选择选项1并设置组织详细​​信息。

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

按R键返回主菜单,然后选择选项2。输入您的域名,然后在Sendmail或SMTP参数中选择dovecot。

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

完成后,按S保存数据,然后按Q退出。

最后,在httpd.conf文件中添加以下行。

[[email protected] ~]# vi /etc/httpd/conf/httpd.conf
Alias /squirrelmail /usr/share/squirrelmail

    Options Indexes FollowSymLinks
    RewriteEngine On
    AllowOverride All
    DirectoryIndex index.php
    Order allow,deny
    Allow from all

重新启动httpd服务。

[[email protected] ~]# service httpd restart
Stopping httpd:                                            [  OK  ]
Starting httpd:                                            [  OK  ]
[[email protected] ~]#

建立使用者

[[email protected] ~]# useradd user1
[[email protected] ~]# useradd user2
[[email protected] ~]# passwd user1
[[email protected] ~]# passwd user2

从任何客户端打开浏览器。在地址栏中键入以下内容。

http://serveripaddress/webmail

要么

http://yourdomainname/webmail

现在,让我们编写一个从user1到user2的邮件。请参考下面的屏幕截图。

然后退出并从user2重新登录。

在CentOS中使用Postfix,Dovecot和SquirrelMail设置邮件服务器

在CentOS中使用Postfix,Dovecot和SquirrelMail设置邮件服务器

而已。我们收到了来自user1的邮件。如果您在配置中有任何问题,请将其发布在评论部分。

祝你有美好的一天。
 

Sidebar