使用postfix,dovecot和squirrelmail设置邮件服务器
在安装Postfix之前,请从服务器中删除SendMail。
因为sendmail是redhat/centoS中的默认MTA。
[Hyman@theitroad ~]# yum remove sendmail
准备工作:
- 邮件服务器应在DNS服务器中包含有效的MX记录。导航到此链接如何设置DNS服务器。
- 防火墙和selinux应该被禁用。
[Hyman@theitroad ~]# service iptables stop [Hyman@theitroad ~]# service ip6tables stop [Hyman@theitroad ~]# chkconfig iptables off [Hyman@theitroad ~]# chkconfig ip6tables off
[Hyman@theitroad ~]# 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
重新启动服务器。
场景
在本教程中我的测试环境
- hostname = server.theitroad.com.
- IP地址= 192.168.1.200/24
我的服务器配置了DNS服务器中的正确MX记录。
安装
Postfix默认安装。
如果未安装,请使用以下命令安装Postfix。
[Hyman@theitroad ~]# yum install postfix
配置
打开postfix config文件/etc/postfix/main.cf。
找到以下行并如下所示编辑它们。
[Hyman@theitroad ~]# vi /etc/postfix/main.cf myhostname = server.theitroad.com ##line no 75 - uncomment and enter your host name mydomain = theitroad.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
启动PostFix服务。
[Hyman@theitroad ~]# service postfix start Starting postfix: [ OK ] [Hyman@theitroad ~]# chkconfig postfix on
测试Postfix.
应由用户输入以粗体字母显示的命令。
注意:测试命令后的点很重要。
[Hyman@theitroad ~]# telnet localhost smtp Trying ::1... Connected to localhost. Escape character is '^]'. 220 server.theitroad.com ESMTP Postfix ehlo localhost 250-server.theitroad.com 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> test . 250 2.0.0 Ok: queued as 117113FF18 quit 221 2.0.0 Bye Connection closed by foreign host.
检查邮件
导航到用户邮件目录并检查新邮件。
[Hyman@theitroad ~]# cd /home/user1/Maildir/new/ [Hyman@theitroad new]# ls 1360236956.Vfd00I35afM181256.server.theitroad.com [Hyman@theitroad new]# cat 1360236956.Vfd00I35afM181256.server.theitroad.com Return-Path: <Hyman@theitroad> X-Original-To: user1 Delivered-To: Hyman@theitroad Received: from localhost (localhost [IPv6:::1]) by server.theitroad.com (Postfix) with ESMTP id 117113FF18 for <user1>; Thu, 7 Nov 2013 17:05:32 +0530 (IST) Message-Id: <Hyman@theitroad> Date: Thu, 7 Nov 2013 17:05:32 +0530 (IST) From: Hyman@theitroad To: undisclosed-recipients:; test
Postfix现在工作。
安装Dovecot.
[Hyman@theitroad ~]# yum install dovecot
配置Dovecot.
打开dovecot confif文件/etc/dovecot/dovecot.conf。
查找并取消注释如下所示。
[Hyman@theitroad ~]# vi /etc/dovecot/dovecot.conf protocols = imap pop3 lmtp
打开file /etc/dovecot/conf.d/10-mail.conf并取消注释如下所示的行。
[Hyman@theitroad ~]# vi /etc/dovecot/conf.d/10-mail.conf mail_location = maildir:~/Maildir ##line no 24 - uncomment
打开/etc/dovecot/conf.d/10-auth.conf和编辑,如下所示。
[Hyman@theitroad ~]# 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
启动Dovecot服务。
[Hyman@theitroad ~]# service dovecot start Starting Dovecot Imap: [ OK ] [Hyman@theitroad ~]# chkconfig dovecot on
测试Dovecot.
应由用户输入粗体显示的命令。
[Hyman@theitroad ~]# 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: <Hyman@theitroad> X-Original-To: user1 Delivered-To: Hyman@theitroad Received: from localhost (localhost [IPv6:::1]) by server.theitroad.com (Postfix) with ESMTP id 117113FF18 for <user1>; Thu, 7 Nov 2013 17:05:32 +0530 (IST) Message-Id: <Hyman@theitroad> Date: Thu, 7 Nov 2013 17:05:32 +0530 (IST) From: Hyman@theitroad To: undisclosed-recipients:; test . quit +OK Logging out. Connection closed by foreign host. [Hyman@theitroad ~]#
Dovecot现在正在工作。
安装squirrelmail.
首先安装EPEL存储库。
并从epel存储库安装Squirrelmail包。
[Hyman@theitroad ~]# wget http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm [Hyman@theitroad ~]# rpm -ivh epel-release-6-8.noarch.rpm [Hyman@theitroad ~]# yum install squirrelmail [Hyman@theitroad ~]# service httpd start Starting httpd: [ OK ] [Hyman@theitroad ~]# chkconfig httpd on [Hyman@theitroad ~]#
配置squirrelmail.
转到SquirrelMail配置目录并使用命令./conf.pl开始配置,如下所示。
[Hyman@theitroad ~]# cd /usr/share/squirrelmail/config/ [Hyman@theitroad 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 : theitroad 2. Organization Logo : ../images/sm_logo.png 3. Org. Logo Width/Height : (308/111) 4. Organization Title : Welcome to theitroad webmail 5. Signout Page : 6. Top Frame : _top 7. Provider link : https://theitroad.com 8. Provider name : theitroad 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 : theitroad.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文件中添加以下行。
[Hyman@theitroad ~]# vi /etc/httpd/conf/httpd.conf 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>
重新启动httpd服务。
[Hyman@theitroad ~]# service httpd restart Stopping httpd: [ OK ] Starting httpd: [ OK ] [Hyman@theitroad ~]#
创建用户
[Hyman@theitroad ~]# useradd user1 [Hyman@theitroad ~]# useradd user2 [Hyman@theitroad ~]# passwd user1 [Hyman@theitroad ~]# passwd user2
从任何客户端打开浏览器。
在地址列中键入以下内容。
http://serveripaddress/webmail
或者
http://yourdomainname/webmail
现在让我们从User1封装到User2.
请参阅下面的 Screen截图。
然后从User2注销并登录。
我们收到了User1的邮件。