webmail

/ns/wz/sys/data/20020801150144.htm

最近由于要把公司的mail服务器升级成webmail,看了不少资料。我的具体情况是我现在的mail服务是redhat 7.2上运行sendmail-8.11.6-3。sendmail本身不支持webmail.开始我用qmail+sqwebmail来代替现在的sendmail。主要看中qmail是因为它对数据库的支持和对mail用户的数据存储格式,比sendmail要好的多。但由于我开始用的mail用户是基于系统用户的,password采用的是md5加密格式,没办法导成数据库用户。衡量一下,决定用openwebmail来实现webmail。优点是对现在的系统改动不大,而且web界面良好。
安装总体分为三部分:
1、安装系统;redhat 7.2
2、安装sendmail and apache。
3、安装openwebmail。
第一步,安装redhat 7.2。安装时最好安装成server,在选用服务时,选上sendmail,www,ftp。默认安装的是apache-1.3.20,最近蜘蛛天天嚷着有安全漏洞。也可以不装,从网上下在最新的安装版本。安装ftp是为了上传一些文件,用完可关掉。分区时/var 要有足够的空间,因为sendmail要占用/var下的很大空间。别的就没什么要注意的了。
2、安装sendmail and apache。

一、利用RedHat 7.2中的默认配置方便地设置一台利用SASL库进行用户名和密码认证的SMTP服务器,以允许外面的用户以用户名和密码认证来relay邮件。
配置Sendmail
1. 选择‘服务器系统’安装Redhat 7.2
2. 进入目录 /usr/share/sendmail-cf/cf 。
如果你没有该目录,说明你还没有安装sendmail-cf-8.11.6-3 RPM包,从你的安装CD中安装它。
3. 修改文件redhat.mc如下
divert(-1)
dnl This is the sendmail macro config file. If you make changes to this file,
dnl you need the sendmail-cf rpm installed and then have to generate a
dnl new /etc/sendmail.cf by running the following command:
dnl
dnl m4 /etc/mail/sendmail.mc > /etc/sendmail.cf
dnl
include(`../m4/cf.m4')
VERSIONID(`linux setup for Red Hat Linux')dnl
OSTYPE(`linux')
define(`confDEF_USER_ID',``8:12'')dnl
undefine(`UUCP_RELAY')dnl
undefine(`BITNET_RELAY')dnl
define(`confAUTO_REBUILD')dnl
define(`confTO_CONNECT', `1m')dnl
define(`confTRY_NULL_MX_LIST',true)dnl
define(`confDONT_PROBE_INTERFACES',true)dnl
define(`PROCMAIL_MAILER_PATH',`/usr/bin/procmail')dnl
define(`ALIAS_FILE', `/etc/aliases')dnl
define(`STATUS_FILE', `/var/log/sendmail.st')dnl
define(`UUCP_MAILER_MAX', `2000000')dnl
define(`confUSERDB_SPEC', `/etc/mail/userdb.db')dnl
define(`confPRIVACY_FLAGS', `authwarnings,novrfy,noexpn,restrictqrun')dnl
define(`confAUTH_OPTIONS', `A')dnl
TRUST_AUTH_MECH(`DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl
define(`confAUTH_MECHANISMS', `DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl
DAEMON_OPTIONS(`Port=25,Name=MTA')dnl
DAEMON_OPTIONS(`Port=587,Name=MSA,M=Ea')dnl
dnl define(`confTO_QUEUEWARN', `4h')dnl
dnl define(`confTO_QUEUERETURN', `5d')dnl
dnl define(`confQUEUE_LA', `12')dnl
dnl define(`confREFUSE_LA', `18')dnl
dnl FEATURE(delay_checks)dnl
FEATURE(`no_default_msa',`dnl')dnl
FEATURE(`smrsh',`/usr/sbin/smrsh')dnl
FEATURE(`mailertable',`hash -o /etc/mail/mailertable')dnl
FEATURE(`virtusertable',`hash -o /etc/mail/virtusertable')dnl
FEATURE(redirect)dnl
FEATURE(always_add_domain)dnl
FEATURE(use_cw_file)dnl
FEATURE(use_ct_file)dnl
FEATURE(local_procmail)dnl
FEATURE(`access_db')dnl
FEATURE(`blacklist_recipients')dnl
EXPOSED_USER(`root')dnl
dnl This changes sendmail to only listen on the loopback device 127.0.0.1
dnl and not on any other network devices. Comment this out if you want
dnl to accept email over the network.
dnl DAEMON_OPTIONS(`Port=smtp,Addr=127.0.0.1, Name=MTA')
dnl We strongly recommend to comment this one out if you want to protect
dnl yourself from spam. However, the laptop and users on computers that do
dnl not have 24x7 DNS do need this.
dnl FEATURE(`accept_unresolvable_domains')dnl
dnl FEATURE(`relay_based_on_MX')dnl
MAILER(smtp)dnl
MAILER(procmail)dnl
其中,我加了下面的行:
1. TRUST_AUTH_MECH(`DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl
2. define(`confAUTH_MECHANISMS', `DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl
4. DAEMON_OPTIONS(`Port=25,Name=MTA')dnl
5. DAEMON_OPTIONS(`Port=587,Name=MSA,M=Ea')dnl
注:
第1,2行 移走前面的注释,打开相应的各种认证机制。
第3,4行 设置相应的MTA和MSA所在的端口号。
注意:要是你的系统是redhat 7.1的话,sendmail也是系统默认安装的话,还要打开以下注解:
1. dnl DAEMON_OPTIONS(`Port=smtp,Addr=127.0.0.1, Name=MTA')
2. dnl FEATURE(`accept_unresolvable_domains')dnl
第1行 允许通过网络连接Sendmail。
第2行 禁止不可解析的域名relay邮件
最后运行
#m4 /usr/share/sendmail-cf/cf/redhat.mc > /etc/sendmail.cf
写到/etc/sendmail.cf文件中

四: 设置SASL认证方案
1. 运行下面的命令,确保SASL被编译进Sendmail.
#/usr/sbin/sendmail -d0.1 -bv root |grep SASL
输出应该类似如下面:
NETUNIX NEWDB QUEUE SASL SCANF SMTP USERDB XDEBUG
确保你能看见上面的文本中的 SASL
2. 测试端口25,确保输出AUTH提示行。
#telnet localhost 25
Trying 127.0.0.1...
Connected to smtp.domain.com.
Escape character is '^]'.
220 smtp.domain.com ESMTP Sendmail 8.11.2/8.11.2; Sun, 1 July 2001 17:56:54 -0800
EHLO localhost
250-smtp.domain.com Hello IDENT:root@smtp.domain.com [127.0.0.1], pleased to meet you
250-ENHANCEDSTATUSCODES
250-EXPN
250-VERB
250-8BITMIME
250-SIZE
250-DSN
250-ONEX
250-ETRN
250-XUSR
250-AUTH LOGIN PLAIN
250 HELP
quit
221 2.0.0 smtp.domain.com closing connection
Connection closed by foreign host.
你需要至少看见AUTH行中有LOGIN PLAIN在那里,否则不能relay mail。
3. 增加SASL用户且更改密码
#/usr/sbin/saslpasswd jephe
Password: *******
Again (for verification): *******
#/usr/sbin/sasldblistusers
user: jephe realm: smtp.domain.com mech: DIGEST-MD5
user: jephe realm: smtp.domain.com mech: PLAIN
user: jephe realm: smtp.domain.com mech: CRAM-MD5
用户的密码DB文件在/etc/sasldb,用下面的命令确保正确的许可权设置。
特别注意: 在下面的windows的Outlook Express中设置用户名和密码时并不是简单地使用用户名jephe,而是用象“user@realm”的用户名,在这里是 jephe@smtp.domain.com作为用户名。
#chmod 400 /etc/sasldb
可以用/usr/sbin/saslpasswd加更多的用户,用/usr/sbin/sasldblistusers检查用户已经加入。
4. 更改默认的Redhat 7.2密码认证方法
默认地,Redhat 7.1中的Sendmail用PAM方法检查密码,这意味着用户必须是系统用户,为了
增强安全性,我们改用/etc/sasldb中的用户,改下面的文件中的pam为sasldb。
#vi /usr/lib/sasl/Sendmail.conf 更改pwcheck_method行象下面
pwcheck_method:sasldb
5. 最后,运行/etc/rc.d/init.d/sendmail restart重新启动Sendmail。
六: 设置Windows的Outlook Express。
1. Outlook Express仅仅使用 PLAIN LOGIN 认证机制,确保上面的telnet localhost 25中的AUTH行
输出PLAIN LOGIN即可。
2. 在‘工具’-‘帐号’-‘属性’-‘服务器‘-
’发送邮件服务器’中选中‘我的服务器需要认证’
七: FAQ。
1. 如果你没有命令saslpasswd,sasldblistusers在/usr/sbin/目录下面。
答: 你需要安装cyrus-sasl-RPM包。
2. 如果不想用SASL认证,就用默认的Redhat 的PAM方法。
答: 忽略上面的SASL设置的部分,默认地 Redhat 7.2的 /usr/lib/sasl/Sendmail.conf文件里面为
pwcheck_method:pam
则你就简单地用useradd增加一个系统用户并更改密码即可。

安装pop3,从redhat 7.2的光盘上有imap-2000c-15.i386.rpm
rpm -ivh imap-2000c-15.i386.rpm
OK!
验证:netstat -a |grep pop

输出 ------tcp 0 0 * : pop3 *:* listen
ok了!
安装apache:
要是系统默认安装,就可以跳过。要是没有安装,从www.apache.org上下载最新版本。我用的是httpd-2.0.39.tar.gz,官方说是当前最好的了。
安装步骤:
tar -zxvf httpd-2.0.29.tar.gz
cd httpd.2.0.29
./configure --prefix=/var/www
make
make instal
启动:/var/www/bin/apachectl start
(详细配置,你可以看httpd.2.0.29目录中的install文件)
OK!到这,apache配置完成。
3、安装openwebmail。
下载相关的软件:
1、CGI.pm-2.74.tar.gz
2、MIME-Base64-2.12.tar.gz
3、libnet-1.0901.tar.gz
4、Download openwebmail-1.65.tgz程式套件,
5、perl.5.XX (redhat 7.2系统自带)
把前三个文件放在/tep目录下:

(1)For CGI.pm do the following:
cd /tmp
tar -zxvf CGI.pm-2.74.tar.gz
cd CGI.pm-2.74
perl Makefile.PL
make
make install
(2)For MIME-Base64 do the following:
cd /tmp
tar -zxvf MIME-Base64-2.12.tar.gz
cd MIME-Base64-2.12
perl Makefile.PL
make
make install
(3)For libnet do the following:
cd /tmp
tar -zxvf libnet-1.0901.tar.gz
cd libnet-1.0901
perl Makefile.PL
make
make install
(4)For openwebmial 主程式
cd /var/www
tar -zxvf openwebmail-1.65.tgz
mv /var/www/data/openwebmail /var/www/htdocs/

修改设定值:

(1)vi /var/www/cgi-bin/openwebmail/auth_unix.pl)
my $unix_passwdfile to /etc/shadow (找到这两行,修改。)
my $unix_passwdmkdb to none
(2)vi /var/www/cgi-bin/openwebmail/etc/openwebmail.conf
下列是 RedHat 7.2 openwebmail.conf 的�热荩�请修改如下:
--------------------------------------------------------------------------------------
# Open WebMail configuration file
# This file contains just the overrides from openwebmail.conf.default
# please make all changes to this file.
# This file set options for all domains and all users.
# To set options on per domain basis, please put them in sites.conf/domainname
# To set options on per user basis, please put them in users.conf/username
domainnames auto
auth_module auth_unix.pl
mailspooldir /var/spool/mail
dbm_ext .db
dbmopen_ext none
ow_cgidir /var/www/cgi-bin/openwebmail
ow_htmldir /var/www/htdocs/openwebmail
logfile /var/log/openwebmail.log
spellcheck /usr/bin/aspell
default_language zh_CH.GB2312 -----默认简体中文

------------------------------------------------------------------------------

(3)为避免"Returned mail: see transcript for details"的错误信息,请做下列连接:

cd /etc/smrsh
ln -s /var/www/cgi-bin/openwebmail/vacation.pl /etc/smrsh/vacation.pl

大功告成、进行测试!
添加用户:
useradd -d /home/test test
passwd test ----创建密码
��入以下网址
http://yourservername/cgi-bin/openwebmail/openwebmail.pl
如果你觉得输入这么长的地址太麻烦,可以做个index.html连接。
cd /var/www/htdocs/
vi index.html
------------------------------------------------------
<html>
<head>
<META HTTP-EQUIV="REFRESH" CONTENT="1; URL=http:/cgi-bin/openwebmail/openwebmail.pl">
</head>
<body>
</body>
</html>
-----------------------------------------------------------
重启动apache:/var/www/bin/apachectl restart
输入://youservername ,看看是不是可以了!