LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1812|回复: 12

架构基于FreeBSD和Postfix的邮件系统 (全ports安装)

[复制链接]
发表于 2005-1-25 16:33:29 | 显示全部楼层 |阅读模式
架构基于FreeBSD和Postfix的邮件系统
FreeBSD+Postfix+cyrus-sasl+Courier-imap+igenus+Clamav+amavisd-new
杨廷勇
Copyright & 2004
本文介绍使用FreeBSD+Postfix+cyrus-sasl+Courier-imap+igenus+Clamav+amavisd-new来架构一个具有多域名,有webmai防病毒
和垃圾邮件并有web管理界面的邮件系统。
scyzxp, $Revision: 0.1 $Date: 2005-1-25
________________________________________
Table of Contents
1. 系统简介
1.1 系统结构
1.2 软件介绍
2. 系统安装
2.1 安装perl
2.2 安装MySQL
2.3 安装Apache
2.4 安装PHP
2.5 安装openssl
2.6 安装phpMyAdmin
2.7 通过phpMyadmin设置数据库
2.8 安装cyrus-sasl和cyrus-sasl2-saslauthd
2.9 安装pam_mysql
2.10 安装postfix
2.11 安装expect
2.12 安装Courier-imap
3. 设置第一个用户并测试
3.1 设置第一个用户
3.2 用户登录测试
3.3 建立其他用户
4. 防病毒与防垃圾邮件
4.1 安装Clamav
4.2 安装amavisd-new
4.3 安装配置Spamassassin
5. 安装webmail
6. 邮件服务器的管理
6.1 配置apache
6.2 管理程序源代码
6.3 配置文件config.inc.php
6.4 增加域名
6.5 增加用户
6.6 查看系统状态

________________________________________
Chapter 1. 系统简介
本章介绍了系统的组成。
________________________________________
1.1 系统结构
________________________________________
1.2 软件介绍
________________________________________
Chapter 2. 系统安装
安装之前:因用户数据都保存在/var目录下,因此安装FreeBSD时/var的空间应尽量大。FreeBSD的版本为4.9,按最小化安装,软件包只安装cvsup,安装结束后用cvsup更新ports树。在文档中假设服务器的ip地址为192.168.204.38,域名为test.com,主机名为mail.test.com。
________________________________________
2.1 安装perl
版本为5.8.5,FreeBSD缺省安装的perl版本无法支持目前的amavisd-new。
mail# cd /usr/ports/lang/perl5.8

mail# make install clean

让新版本的perl成为系统的缺省
mail# /usr/local/bin/use.perl port

________________________________________
2.2 安装MySQL
版本为4.0.20,因目前的pam_mysql版本不支持4.1所以安装MySQL40。
mail# cd /usr/ports/databases/mysql40-server
mail# make install clean


________________________________________
2.3 安装Apache
版本为1.3.31_4。
mail# cd /usr/ports/www/apache2
mail# make install clean

编辑/etc/rc.conf,加入
Apache2_enable="YES"

________________________________________
2.4 安装PHP
版本为4.3.10。
mail# cd /usr/ports/lang/php4

mail# make install clean

安装需要的PHP扩展模块
mail# cd /usr/ports/lang/php4-extensions
mail# make install clean

注:gettext需选中

________________________________________
2.5 安装openssl
mail# cd /usr/ports/security/openssl

mail# make install clean

________________________________________
2.6 安装phpMyAdmin
mail# cd /usr/ports/databases/phpmyadmin
mail# make install clean

编辑/usr/local/etc/apache/httpd.conf,加入
Alias /phpMyAdmin/ "/usr/local/www/phpMyAdmin/"

<Directory "/usr/local/www/phpMyAdmin">
Options Indexes FollowSymlinks
Allowoverride AuthConfig
Order allow,deny
Allow from all
</Directory>

编辑编辑/usr/local/www/phpMyAdmin/.htaccess
authname "MySQL Admin"
authtype basic
authuserfile /etc/htpasswd
require user admin

运行以下命令生成可访问phpMyadmin的用户:
mail# /usr/local/bin/htpasswd -c /etc/htpasswd admin

修改/usr/local/www/phpMyAdmin/config.inc.php
$cfg['PmaAbsoluteUri'] = 'http://192.168.9.33/phpMyAdmin/';

重启服务器
在浏览器输入http://192.168. 9.33/phpMyAdmin/,修改mysql数据库里user表里的root用户的密码为admin123。
重启MySQL,再编辑/usr/local/www/phpMyAdmin/config.inc.php
$cfg['Servers'][$i]['password'] = 'admin123';

________________________________________
2.7 通过phpMyadmin设置数据库
建立两个数据库用户
#======================postfix==================================

INSERT INTO user (host,user,password) VALUES('localhost','postfix','');
update user set password=password('admin123') where User='postfix';
FLUSH PRIVILEGES;
GRANT ALL ON mail.* TO postfix@localhost IDENTIFIED BY "admin123";
#======================courier==================================
INSERT INTO user (host,user,password) VALUES ('localhost','courier','');
update user set password=password('admin123') where User='courier';
FLUSH PRIVILEGES;
GRANT select,insert,update on mail.* TO courier;


建立数据库
#=======================MAIL.SQL=================================

#Create mail database

CREATE DATABASE mail;
use mail;

#Create the aliases table

CREATE TABLE aliases (

alias varchar(255) NOT NULL default '',
rcpt varchar(255) default NULL,
PRIMARY KEY (alias)
) TYPE=MyISAM;

#Create the transport table

CREATE TABLE transport (

domain char(128) NOT NULL default '',
transport char(128) NOT NULL default '',
UNIQUE KEY domain (domain)
) TYPE=MyISAM;

#Create the virtua_users table

CREATE TABLE virtual_users (

unique_id int(32) unsigned NOT NULL auto_increment,
id char(128) NOT NULL default '',
password char(128) default NULL,
uid int(10) unsigned default '125',
gid int(10) unsigned default '125',
home char(255) default NULL,

maildir char(255) default NULL,
date_add date default NULL,
time_add time default NULL,
domain char(128) default NULL,
name char(255) default NULL,
imapok tinyint(3) unsigned default '1',

###缺省邮箱大小20M
quota char(255) default '20971520',
nickname varchar(10) default NULL,
realname varchar(10) default NULL,
office varchar(20) default NULL,
PRIMARY KEY (id),

KEY unique_id (unique_id)
) TYPE=MyISAM;

________________________________________
2.8 安装cyrus-sasl和cyrus-sasl2-saslauthd
mail# cd /usr/ports/security/cyrus-sasl2-saslauthd
mail# make install clean

编辑/etc/rc.conf,加入
saslauthd_enable="YES"

建立一个目录连接
mail# ln -s /usr/local/lib/sasl2 /usr/lib/sasl2


配置sasl的lib库:在/etc/defaults/rc.conf文件里的ldconfig_paths="/usr/local/lib后面加上/usr/local/lib/sasl2"
运行:
mail# echo pwcheck_method:saslauthd > /usr/lib/sasl2/smtpd.conf

编辑/usr/local/etc/rc.d/saslauthd.sh
command="${prefix}/sbin/${name}"

改成:
command="${prefix}/sbin/${name} -r"

重启服务器
________________________________________
2.9 安装pam_mysql
mail# cd /usr/ports/security/pam-mysql
mail# make install clean
mail# cp /usr/local/lib/pam_mysql.so /usr/lib/

配置pam.conf调用mysql支持sasl认证。编辑/etc/pam.conf(将pop3 和imap的前面加上#)添加下列代码:
smtp auth sufficient pam_mysql.so user=postfix passwd=admin123 host=localhost db=mail table=virtual_users usercolumn=id passwdcolumn=password crypt=1
注:以上为一行。
smtp account required pam_mysql.so user=postfix passwd=admin123 host=localhost db=mail table=virtual_users usercolumn=id passwdcolumn=password crypt=1
注:以上为一行。

注:用tab键分隔,不是用空格。密码使用crypt加密,如果使用明文密码cyrpt=0,如果
使用password()加密crypt=2

________________________________________
2.10 安装postfix
停止sendmail
mail# killall sendmail
mail# mv /usr/bin/newaliases /usr/bin/newaliases.OFF

mail# mv /usr/bin/mailq /usr/bin/mailq.OFF
mail# mv /usr/sbin/sendmail /usr/sbin/sendmail.OFF
mail# mv /etc/rc.sendmail /etc/sendmail.OFF

开始安装postfix
mail# cd /usr/ports/mail/postfix

mail# make install clean

安装中选中SASL2、MySQL,及回答以下的问题。
You need user "postfix" added to group "mail".
Would you like me to add it [y]? y
Would you like to activate Postfix in /etc/mail/mailer.conf [n]? n

安装完进行一些设置:
mail# cd /usr/local/etc/rc.d
mail# ln -s /usr/local/sbin/postfix postfix.sh

mail# ln -s /usr/local/sbin/sendmail /usr/sbin/sendmail

mail# echo ‘postfix: root’ >> /etc/aliases
mail# /usr/local/bin/newaliases
mail# chown postfix:postfix /etc/opiekeys

编辑/etc/rc.conf
sendmail_enable="YES"
sendmail_flags="-bd"
sendmail_outbound_enable="NO"
sendmail_submit_enable="NO"
sendmail_msp_queue_enable="NO"
编辑//etc/periodic.conf
daily_clean_hoststat_enable="NO"
daily_status_mail_rejects_enable="NO"
daily_status_include_submit_mailq="NO"
daily_submit_queuerun="NO"
修改/usr/local/etc/postfix/main.cf,在文件最后加入以下内容
#======= BASE ==============
myhostname = mail.test.com
mydomain = test.com
home_mailbox = Maildir/
mydestination = $myhostname, $mydomain, $transport_maps
local_recipient_maps =
mailbox_command= /usr/local/bin/deliverquota -w 90 ~/Maildir
command_directory = /usr/local/sbin
#======= MYSQL =============
transport_maps = mysql:/usr/local/etc/postfix/transport.cf
virtual_gid_maps = mysql:/usr/local/etc/postfix/gids.cf
virtual_mailbox_base = /var/mail
virtual_mailbox_maps = mysql:/usr/local/etc/postfix/mysql_virtual.cf
virtual_maps = mysql:/usr/local/etc/postfix/mysql.aliases.cf
virtual_uid_maps = mysql:/usr/local/etc/postfix/uids.cf
#======= Quota ============
message_size_limit = 4194304 //限制每次发邮件的大小4MB
virtual_mailbox_limit_inbox = no
virtual_mailbox_limit_maps = mysql:/usr/local/etc/postfix/mailboxsize-mysql.cf
virtual_mailbox_limit_override = yes
virtual_maildir_extended = yes
virtual_create_maildirsize = yes
virtual_mailbox_limit = 20971520 //总邮箱的大小20MB
#====== SASL ================
smtpd_sasl_auth_enable = yes
smtpd_sasl_security_options = noanonymous
broken_sasl_auth_clients = yes
smtpd_recipient_restrictions = permit_sasl_authenticated permit_auth_destination reject
#smtpd_sasl_local_domain = $mydomain
smtpd_client_restrictions = permit_sasl_authenticated

确认/usr/local/etc/postfix/master.cf的配置有如下内容
virtual unix - n n - - virtual

编辑/usr/local/etc/posftix/transport.cf
user = postfix
password = admin123
dbname = mail
table = transport
select_field = transport
where_field = domain
hosts = localhost

编辑/usr/local/etc/postfix/gids.cf
user = postfix
password= admin123
dbname = mail
table = virtual_users
select_field = gid
where_field = id
hosts = localhost

编辑/usr/local/etc/postfix/uids.cf
user = postfix
password= admin123
dbname = mail
table = virtual_users
select_field = uid
where_field = id
hosts = localhost

编辑/usr/local/etc/posftix/mysql_virtual.cf
user = postfix
password= admin123
dbname = mail
table = virtual_users
select_field = maildir
where_field = id
hosts = localhost

编辑/usr/local/etc/postfix/mysql.aliases.cf
user = postfix
password= admin123
dbname = mail
table = aliases
select_field = rcpt
where_field = alias
hosts = localhost

编辑/etc/postfix/mailboxsize-mysql.cf
user = postfix
password = admin123
dbname = mail
table = virtual_users
select_field = quota
where_field = id
hosts = localhost

________________________________________
2.11 安装expect
mail# cd /usr/ports/lang/expect

mail# make install clean

________________________________________
2.12 安装Courier-imap
由于courier-imap 从 4版本开始,把 courier-authlib 独立出来了,需要先安装 courier-authlib. 具体步骤:
mail# cd courier-authlib
mail# make WITH_MYSQL=yes
mail# make install
mail# cd /usr/ports/mail/courier-imap
mail# make WITHOUT_OPENSSL= yes WITH_MYSQL= yes install clean

mail# cd /usr/local/etc/rc.d
mail# mv courier-imap-imapd-ssl.sh.sample courier-imap-imapd-ssl.sh
mail# mv courier-imap-imapd.sh.sample courier-imap-imapd.sh
mail# mv courier-imap-pop3d-ssl.sh.sample courier-imap-pop3d-ssl.sh

mail# mv courier-imap-pop3d.sh.sample courier-imap-pop3d.sh
mail# cd /usr/local/etc/authlih
mail# cd /usr/local/etc/courier-imap
mail# cp authdaemonrc.dist authdaemonrc
mail# cp authmysqlrc.dist authmysqlrc
mail# cd /usr/local/etc/courier-imap
mail# cp imapd-ssl.dist imapd-ssl
mail# cp imapd.cnf.dist imapd.cnf
mail# cp imapd.dist imapd
mail# cp pop3d-ssl.dist pop3d-ssl
mail# cp pop3d.cnf.dist pop3d.cnf
mail# cp pop3d.dist pop3d

编辑修改/usr/local/etc/courier-imap/authmysqlrc 示例:authmysqlrc
##VERSION: $Id: install.sgml,v 1.1 2004/11/01 14:47:56 wt Exp $
#
# Copyright 2000-2004 Double Precision, Inc. See COPYING for
# distribution information.
#
# Do not alter lines that begin with ##, they are used when upgrading
# this configuration.
#
# authmysqlrc created from authmysqlrc.dist by sysconftool
#
# DO NOT INSTALL THIS FILE with world read permissions. This file
# might contain the MySQL admin password!
#
# Each line in this file must follow the following format:
#
# field[spaces|tabs]value
#
# That is, the name of the field, followed by spaces or tabs, followed by
# field value. Trailing spaces are prohibited.


##NAME: LOCATION:0
#
# The server name, userid, and password used to log in.

MYSQL_SERVER localhost
MYSQL_USERNAME courier
MYSQL_PASSWORD admin123

##NAME: MYSQL_SOCKET:0
#
# MYSQL_SOCKET can be used with MySQL version 3.22 or later, it specifies the
# filesystem pipe used for the connection
#
# MYSQL_SOCKET /var/mysql/mysql.sock

##NAME: MYSQL_PORT:0
#
# MYSQL_PORT can be used with MySQL version 3.22 or later to specify a port to
# connect to.

MYSQL_PORT 3306

##NAME: MYSQL_OPT:0
#
# Leave MYSQL_OPT as 0, unless you know what you're doing.

MYSQL_OPT 0

##NAME: MYSQL_DATABASE:0
#
# The name of the MySQL database we will open:

MYSQL_DATABASE mail

##NAME: MYSQL_USER_TABLE:0
#
# The name of the table containing your user data. See README.authmysqlrc
# for the required fields in this table.

MYSQL_USER_TABLE virtual_users

##NAME: MYSQL_CRYPT_PWFIELD:0
#
# Either MYSQL_CRYPT_PWFIELD or MYSQL_CLEAR_PWFIELD must be defined. Both
# are OK too. crypted passwords go into MYSQL_CRYPT_PWFIELD, cleartext
# passwords go into MYSQL_CLEAR_PWFIELD. Cleartext passwords allow
# CRAM-MD5 authentication to be implemented.

MYSQL_CRYPT_PWFIELD password

##NAME: MYSQL_CLEAR_PWFIELD:0
#
#
# MYSQL_CLEAR_PWFIELD clear

##NAME: MYSQL_DEFAULT_DOMAIN:0
#
# If DEFAULT_DOMAIN is defined, and someone tries to log in as 'user',
# we will look up 'user@DEFAULT_DOMAIN' instead.
#
#
# DEFAULT_DOMAIN example.com

##NAME: MYSQL_UID_FIELD:0
#
# Other fields in the mysql table:
#
# MYSQL_UID_FIELD - contains the numerical userid of the account
#
MYSQL_UID_FIELD uid

##NAME: MYSQL_GID_FIELD:0
#
# Numerical groupid of the account

MYSQL_GID_FIELD gid

##NAME: MYSQL_LOGIN_FIELD:0
#
# The login id, default is id. Basically the query is:
#
# SELECT MYSQL_UID_FIELD, MYSQL_GID_FIELD, ... WHERE id='loginid'
#

MYSQL_LOGIN_FIELD id

##NAME: MYSQL_HOME_FIELD:0
#

MYSQL_HOME_FIELD home

##NAME: MYSQL_NAME_FIELD:0
#
# The user's name (optional)

MYSQL_NAME_FIELD name

##NAME: MYSQL_MAILDIR_FIELD:0
#
# This is an optional field, and can be used to specify an arbitrary
# location of the maildir for the account, which normally defaults to
# $HOME/Maildir (where $HOME is read from MYSQL_HOME_FIELD).
#
# You still need to provide a MYSQL_HOME_FIELD, even if you uncomment this
# out.
#
MYSQL_MAILDIR_FIELD maildir

##NAME: MYSQL_DEFAULTDELIVERY:0
#
# Courier mail server only: optional field specifies custom mail delivery
# instructions for this account (if defined) -- essentially overrides
# DEFAULTDELIVERY from ${sysconfdir}/courierd
#
# MYSQL_DEFAULTDELIVERY defaultdelivery

##NAME: MYSQL_QUOTA_FIELD:0
#
# Define MYSQL_QUOTA_FIELD to be the name of the field that can optionally
# specify a maildir quota. See README.maildirquota for more information
#
MYSQL_QUOTA_FIELD quota

##NAME: MYSQL_AUXOPTIONS:0
#
# Auxiliary options. The MYSQL_AUXOPTIONS field should be a char field that
# contains a single string consisting of comma-separated "ATTRIBUTE=NAME"
# pairs. These names are additional attributes that define various per-account
# "options", as given in INSTALL's description of the "Account OPTIONS"
# setting.
#
# MYSQL_AUXOPTIONS_FIELD auxoptions
#
# You might want to try something like this, if you'd like to use a bunch
# of individual fields, instead of a single text blob:
#
# MYSQL_AUXOPTIONS_FIELD CONCAT("disableimap=",disableimap,",
#disablepop3=",disablepop3,",di
#sablewebmail=",disablewebmail,",sharedgroup=",sharedgroup)
#
# This will let you define fields called "disableimap", etc, with the end result
# being something that the OPTIONS parser understands.


##NAME: MYSQL_WHERE_CLAUSE:0
#
# This is optional, MYSQL_WHERE_CLAUSE can be basically set to an arbitrary
# fixed string that is appended to the WHERE clause of our query
#
# MYSQL_WHERE_CLAUSE server='mailhost.example.com'


##NAME: MYSQL_SELECT_CLAUSE:0
#
# (EXPERIMENTAL)
# This is optional, MYSQL_SELECT_CLAUSE can be set when you have a database,
# which is structuraly different from proposed. The fixed string will
# be used to do a SELECT operation on database, which should return fields
# in order specified bellow:
#
# username, cryptpw, clearpw, uid, gid, home, maildir, quota, fullname, options
#
# The username field should include the domain (see example below).
#
# Enabling this option causes ignorance of any other field-related
# options, excluding default domain.
#
# There are two variables, which you can use. Substitution will be made
# for them, so you can put entered username (local part) and domain name
# in the right place of your query. These variables are:
# $(local_part), $(domain), $(service)
#
# If a $(domain) is empty (not given by the remote user) the default domain
# name is used in its place.
#
# $(service) will expand out to the service being authenticated: imap, imaps,
# pop3 or pop3s. Courier mail server only: service will also expand out to
# "courier", when searching for local mail account's location. In this case,
# if the "maildir" field is not empty it will be used in place of
# DEFAULTDELIVERY. Courier mail server will also use esmtp when doing
# authenticated ESMTP.
#
# This example is a little bit modified adaptation of vmail-sql
# database scheme:
#
# MYSQL_SELECT_CLAUSE SELECT CONCAT(popbox.local_part, '@', popbox.domain_name),
\
# CONCAT('{MD5}', popbox.password_hash), \
# popbox.clearpw, \
# domain.uid, \
# domain.gid, \
# CONCAT(domain.path, '/', popbox.mbox_name), \
# '', \
# domain.quota, \
# '', \
# CONCAT("disableimap=",disableimap,",disablepop3=", \
# disablepop3,",disablewebmail=",disablewebmail, \
# ",sharedgroup=",sharedgroup) \
# FROM popbox, domain \
# WHERE popbox.local_part = '$(local_part)' \
# AND popbox.domain_name = '$(domain)' \
# AND popbox.domain_name = domain.domain_name


##NAME: MYSQL_ENUMERATE_CLAUSE:0
#
# {EXPERIMENTAL}
# Optional custom SQL query used to enumerate accounts for authenumerate,
# in order to compile a list of accounts for shared folders. The query
# should return the following fields: name, uid, gid, homedir, maildir
#
# Example:
# MYSQL_ENUMERATE_CLAUSE SELECT CONCAT(popbox.local_part, '@',
#popbox.domain_name),
\
# domain.uid, \
# domain.gid, \
# CONCAT(domain.path, '/', popbox.mbox_name), \
# '' \
# FROM popbox, domain \
# WHERE popbox.local_part = '$(local_part)' \
# AND popbox.domain_name = '$(domain)' \
# AND popbox.domain_name = domain.domain_name



##NAME: MYSQL_CHPASS_CLAUSE:0
#
# (EXPERIMENTAL)
# This is optional, MYSQL_CHPASS_CLAUSE can be set when you have a database,
# which is structuraly different from proposed. The fixed string will
# be used to do an UPDATE operation on database. In other words, it is
# used, when changing password.
#
# There are four variables, which you can use. Substitution will be made
# for them, so you can put entered username (local part) and domain name
# in the right place of your query. There variables are:
# $(local_part) , $(domain) , $(newpass) , $(newpass_crypt)
#
# If a $(domain) is empty (not given by the remote user) the default domain
# name is used in its place.
# $(newpass) contains plain password
# $(newpass_crypt) contains its crypted form
#
# MYSQL_CHPASS_CLAUSE UPDATE popbox \
# SET clearpw='$(newpass)', \
# password_hash='$(newpass_crypt)' \
# WHERE local_part='$(local_part)' \
# AND domain_name='$(domain)'
#

重启服务器
________________________________________
Chapter 3. 设置第一个用户并测试
本章介绍如何开通用户,并且测试系统是否正常。
________________________________________
3.1 设置第一个用户
设置第一个用户
mail# mysql

mysql> use mail;
mysql> show tables;
+----------------+
| Tables_in_mail |
+----------------+
| aliases |
| transport |
| virtual_users |
+----------------+
mysql> desc aliases;
+-------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+--------------+------+-----+---------+-------+
| alias | varchar(255) | | PRI | | |
| rcpt | varchar(255) | YES | | NULL | |
+-------+--------------+------+-----+---------+-------+
mysql> insert aliases values('postmaster@test.com','webmaster@test.com');

mysql> select * from aliases;
+--------------------------+--------------------+
| alias | rcpt |
+--------------------------+--------------------+
| postmaster@test.com | webmaster@test.com |
+--------------------------+--------------------+
mysql> desc transport;
+-----------+-----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------+-----------+------+-----+---------+-------+
| domain | char(128) | | PRI | | |
| transport | char(128) | | | | |
+-----------+-----------+------+-----+---------+-------+
mysql> insert transport values('test.com','virtual:');
mysql> select * from transport;

+---------------+-----------+
| domain | transport |
+---------------+-----------+
| test.com | virtual: |
+---------------+-----------+
mysql> desc virtual_users;
+-----------+---------------------+------+-----+----------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-----------+---------------------+------+-----+----------+----------------+
| unique_id | int(32) unsigned | | MUL | NULL | auto_increment |
| id | char(128) | | PRI | | |
| password | char(128) | YES | | NULL | |
| uid | int(10) unsigned | YES | | 104 | |
| gid | int(10) unsigned | YES | | 104 | |
| home | char(255) | YES | | NULL | |
| maildir | char(255) | YES | | NULL | |
| date_add | date | YES | | NULL | |
| time_add | time | YES | | NULL | |
| domain | char(128) | YES | | NULL | |
| name | char(255) | YES | | NULL | |
| imapok | tinyint(3) unsigned | YES | | 1 | |
| quota | char(255) | YES | | 10485760 | |
+-----------+---------------------+------+-----+----------+----------------+
mysql> INSERT INTO virtual_users
mysql> (id,home,password,maildir,date_add,time_add,domain,name)
mysql> VALUES ('webmaster@test.com','/var/mail/',encrypt('admin123'),

mysql> 'test.com/webmaster/Maildir/','2004-08-08','16:28:24','test.com','webmaster');
mysql> quit

设置用户的目录与权限:
mail# mkdir -p /var/mail/test.com/webmaster
mail# /usr/local/bin/maildirmake /var/mail/test.com/webmaster/Maildir

mail# chmod -R 777 /var/mail/test.com/
mail# chown -R postfix:postfix /var/mail/test.com

至此用户设置完毕,这里只使用一个域名,同理可以设置多个域名。
________________________________________
3.2 用户登录测试
用户登录测试
安装p5-MIME-Base64
mail# cd /usr/ports/converters/p5-MIME-Base64/

mail# make install clean

通过p5-MIME-Base64来取得用户名和密码的base64编码
mail# perl -MMIME::Base64 -e 'print encode_base64("webmaster\@test.com");'
d2VibWFzdGVyQG1za2Uub3Jn
mail# perl -MMIME::Base64 -e 'print encode_base64("admin123");'
bHUwOTIx

发送邮件:
mail# telnet 127.0.0.1 25

Trying 127.0.0.1...
Connected to 0.
Escape character is '^]'.
220 mail.test.com ESMTP Postfix
ehlo mail
250-mail.test.com
250-PIPELINING
250-SIZE 4194304
250-VRFY
250-ETRN
250-AUTH NTLM LOGIN PLAIN OTP
250-AUTH=NTLM LOGIN PLAIN OTP
250 8BITMIME
auth login
334 VXNlcm5hbWU6
d2VibWFzdGVyQG1za2Uub3Jn //此为用户名id:webmaster@test.com
334 UGFzc3dvcmQ6
bHUwOTIx //此为用户密码password:admin123
235 Authentication successful
MAIL FROM:webmaster@test.com //告诉服务器发件人的Email地址
250 Ok
RCPT TO:webmaster@test.com //告诉服务器收件人的地址
250 OK

DATA //告诉服务器开始写信
354 End data with <CR><LF>.<CR><LF>
SUBJECT:test //subject后面填写的是邮件的主题
test
. //换行后输入.后按回车,表示信件内容书写完毕
250 Ok: queued as 58DC71D5

quit //发送信件,结束对话,退出SMTP服务器
221 Bye
Connection closed by foreign host

收取邮件:
mail# telnet 127.0.0.1 110
Trying 127.0.0.1...
Connected to 0
Escape character is '^]'
+OK Hello there
user webmaster@test.com
+OK Password required
pass admin123
+OK logged in
list

+OK POP3 clients that break here, they violate STD53
1 2217
.
retr 1 //返回第一封信的全部内容
+OK 2217 octets follow.
Return-Path: <webmaster@test.com>
X-Original-To: webmaster@test.com
Delivered-To: webmaster@test.com
Received: from mail (localhost.test.com [127.0.0.1])
by mail.test.com (Postfix) with ESMTP id 58DC71D5
for <webmaster@test.com>; Mon, 9 Aug 2004 21:11:20 +0800 (CST)
SUBJECT:test
Message-Id: <20040809131120.58DC71D5@mail.test.com>
Date: Mon, 9 Aug 2004 21:11:20 +0800 (CST)
From: webmaster@test.com
To: undisclosed-recipients:;

test
.
dele 1 //删除
+OK Deleted
quit

+OK Bye-bye
Connection closed by foreign host

也可以使用任何其它的邮件客户端程序来测试,如foxmail、Outlook Express等等。
________________________________________
3.3 建立其他用户
建立其他用户
mysql> INSERT INTO virtual_users
mysql> (id,home,password,maildir,date_add,time_add,domain,name,nickname,realname,office)
mysql> VALUES ('test@test.com','/var/mail/',encrypt('abc321'),
mysql> 'test.com/test/Maildir/','2004-08-09','22:49:24','test.com','test',);

mysql> '昵称','真实姓名','单位');
mysql> quit

设置用户的目录与权限:
mail# mkdir -p /var/mail/test.com/test
mail# /usr/local/bin/maildirmake /var/mail/test.com/test/Maildir

mail# chmod -R 700 /var/mail/test.com/
mail# chown -R postfix:postfix /var/mail/test.com

________________________________________
Chapter 4. 防病毒与防垃圾邮件
本章介绍病毒与垃圾邮件的防范。
________________________________________
4.1 安装Clamav
mail# cd /usr/ports/security/clamav

mail# make install clean
注:MILTER不用选中

重启服务器
测试
mail# clamscan -r -i /usr/local/www/data
----------- SCAN SUMMARY -----------
Known viruses: 22838
Scanned directories: 1
Scanned files: 31
Infected files: 0
Data scanned: 0.00 MB
I/O buffer size: 131072 bytes
Time: 1.298 sec (0 m 1 s)

升级病毒库
mail# freshclam


________________________________________
4.2 安装amavisd-new
版本20040701。
mail# cd /usr/ports/security/amavisd-new
mail# make install clean

选中MySQL

编辑/etc/rc.conf,加入
amavisd_enable="YES"

修改/usr/local/etc/amavisd.conf
$mydomain = 'example.com';改成$mydomain = 'test.com';

#$notify_method = 'smtp:[127.0.0.1]:10025';
#$forward_method = 'smtp:[127.0.0.1]:10025';
的注释去掉

修改/usr/local/etc/postfix/master.cf,最后加入
smtp-amavis unix - - y - 2 smtp -o smtp_data_done_timeout=1200
127.0.0.1:10025 inet n - n - - smtpd
-o content_filter=
-o local_recipient_maps=
-o relay_recipient_maps=
-o smtpd_restriction_classes=
-o smtpd_client_restrictions=
-o smtpd_helo_restrictions=
-o smtpd_sender_restrictions=
-o smtpd_recipient_restrictions=permit_mynetworks,reject
-o mynetworks=127.0.0.0/8
-o strict_rfc821_envelopes=yes
-o smtpd_error_sleep_time=0
-o smtpd_soft_error_limit=1001
-o smtpd_hard_error_limit=1000

重启服务器
________________________________________
4.3 安装配置Spamassassin
在最新的AMaVisd-new已经结合了Spamassassin功能,所以只要用 ports安装了 AMaVisd-new,那Spamassassin 也已经安装好了。
添加需要的用户
mail# pw useradd spam -c "Spam Bayes Learner" -d /var/empty -s /sbin/nologin

mail# pw useradd notspam -c "Not Spam Bayes Learner" -d /var/empty -s /sbin/nologin

修改/usr/local/etc/mail/spamassassin/local.cf
use_bayes 1
bayes_path /var/amavis/.spamassassin/bayes
auto_learn 1
auto_learn_threshold_nonspam -2
auto_learn_threshold_spam 15

修改/usr/local/etc/amavisd.conf,在MUST BE SET (no useful default)一段下面增加
$max_requests = 10;
$child_timeout=5*60;

@bypass_virus_checks_acl = qw( . );
@local_domains_acl = ( ".$mydomain" );

$final_spam_destiny = D_PASS;

read_hash(\%whitelist_sender, '/var/amavis/whitelist');
read_hash(\%blacklist_sender, '/var/amavis/blacklist');
read_hash(\%spam_lovers, '/var/amavis/spam_lovers');

建立所需要的文件
mail# touch /var/amavis/whitelist
mail# touch /var/amavis/blacklist

mail# touch /var/amavis/spam_lovers
mail# chown vscan /var/amavis/whitelist
mail# chown vscan /var/amavis/blacklist
mail# chown vscan /var/amavis/spam_lovers
mail# echo spam@test.com >> /var/amavis/spam_lovers

mail# echo notspam@test.com >> /var/amavis/spam_lovers

修改/usr/local/etc/postfix/main.cf,添加
content_filter = smtp-amavis:[127.0.0.1]:10024

建立自动学习体系
mail# vi /usr/local/sbin/my-sa-learn.sh

#!/bin/sh
if [ -e /var/mail/spam ]; then
/usr/local/bin/sa-learn --spam -p /var/amavis/.spamassassin/user_prefs
--mbox /var/mail/spam
注:以上两行为一行
rm /var/mail/spam > /dev/null
fi

if [ -e /var/mail/notspam ]; then
/usr/local/bin/sa-learn --ham -p /var/amavis/.spamassassin/user_prefs
--mbox /var/mail/notspam
注:以上两行为一行
rm /va/mail/notspam > /dev/null
fi

mail# chmod a+x /usr/local/sbin/my-sa-learn.sh


建立学习知识库:
mail# /usr/local/bin/sa-learn --rebuild -p /var/amavis/.spamassassin/user_prefs

加入自动运行:
mail# crontab -e

5 0 * * * /usr/local/sbin/my-sa-learn.sh

重启服务器
测试
mail# su - vscan

mail# /usr/local/sbin/amavisd debug

启动另一个终端:
mail# telnet 127.0.0.1 10024
Trying 127.0.0.1...
Connected to localhost.test.com.
Escape character is '^]'.
220 [127.0.0.1] ESMTP amavisd-new service ready
MAIL FROM:<webmaster@test.com>
250 2.1.0 Sender webmaster@test.com OK
RCPT TO:<webmaster@test.com>

250 2.1.5 Recipient webmaster@test.com OK
DATA
354 End data with <CR><LF>.<CR><LF>
Subject: test

X5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*
.

250 2.7.1 Ok, discarded, id=00228-01 - VIRUS: Eicar-Test-Signature
//出现这一行表示系统已经认出这个邮件中含有 Virus
quit

________________________________________
Chapter 5. 安装webmail
webmail使用igenus,版本是2004.7.13。
下载igenus到/var/mail目录后解压
安装autorespond,版本是2.53_3。
mail# cd /usr/ports/mail/autorespond
mail# make install clean


修改/usr/local/etc/apache/httpd.conf
Group nobody、User nobody修改为: Group postfix、User postfix
DocumentRoot "/usr/local/apache/htdocs"修改为:DocumentRoot "/var/mail/webmail"
<Directory "/usr/local/www/data">修改成<Directory "/var/mail/igenus">

mail# cd /usr/local/www
mail# chown -R postfix:postfix phpMyAdmin

mail# cd /usr/local/etc
mail# cp php.ini-dist php.ini

修改/usr/local/etc/php.ini
register_globals = On
max_execution_time = 30 //改为60 (增加处理脚本的时间限制)
memory_limit = 8M //改为40M (这样才能发10M的附件)
post_max_size = 8M //改为10M
upload_max_filesize = 2M //改为10M

重启apache
mail# /usr/local/etc/rc.d/apache.sh restart

在mail数据库下增加的表
# phpMyAdmin SQL Dump
# version 2.5.3
# http://www.phpmyadmin.net
#
# Host: localhost
# Generation Time: Jun 04, 2004 at 11:26 AM
# Server version: 3.23.55
# PHP Version: 4.3.0
#
# Database : `vpopmail`
#

# --------------------------------------------------------

#
# Table structure for table `address`
#

CREATE TABLE `address` (
`id` int(11) unsigned NOT NULL auto_increment,
`pw_id` int(5) NOT NULL default '0',
`name` varchar(64) NOT NULL default '',
`email` varchar(128) NOT NULL default '',
UNIQUE KEY `id` (`id`),
KEY `pw_id` (`pw_id`)
) TYPE=MyISAM PACK_KEYS=1 ;

# --------------------------------------------------------

#
# Table structure for table `admin`
#

CREATE TABLE `admin` (
`id` int(10) unsigned NOT NULL auto_increment,
`site_id` int(10) unsigned NOT NULL default '0',
`domain` varchar(128) NOT NULL default '',
`quota` smallint(5) unsigned NOT NULL default '0',
`total` smallint(5) unsigned NOT NULL default '0',
`createtime` timestamp(14) NOT NULL,
`login` char(1) NOT NULL default '',
`cur_total` smallint(5) NOT NULL default '0',
`cur_quota` smallint(5) NOT NULL default '0',
`gid` varchar(11) NOT NULL default '',
`expiration_time` timestamp(14) NOT NULL,
`flag` int(10) unsigned NOT NULL default '0',
`maxmsg` int(10) unsigned NOT NULL default '0',
PRIMARY KEY (`id`),
UNIQUE KEY `domain` (`domain`)
) TYPE=MyISAM PACK_KEYS=1 ;

# --------------------------------------------------------

#
# Table structure for table `card`
#

CREATE TABLE `card` (
`id` int(5) unsigned NOT NULL auto_increment,
`pw_id` int(5) unsigned NOT NULL default '0',
`LinkMan` varchar(64) NOT NULL default '',
`CompanyName` varchar(100) NOT NULL default '',
`Address` varchar(255) NOT NULL default '',
`Position` varchar(32) NOT NULL default '',
`PhoneNumber` varchar(16) NOT NULL default '',
`Mobile` varchar(12) NOT NULL default '',
`Email` varchar(128) NOT NULL default '',
`Partaker` varchar(32) NOT NULL default '',
`Memo` varchar(255) NOT NULL default '',
PRIMARY KEY (`id`)
) TYPE=MyISAM ;

# --------------------------------------------------------

#
# Table structure for table `lastauth`
#

CREATE TABLE `lastauth` (
`user` char(32) NOT NULL default '',
`domain` char(64) NOT NULL default '',
`remote_ip` char(1 NOT NULL default '',
`timestamp` bigint(20) NOT NULL default '0',
PRIMARY KEY (`user`,`domain`)
) TYPE=MyISAM;

# --------------------------------------------------------

#
# Table structure for table `logs`
#

CREATE TABLE `logs` (
`pw_id` int(5) default '0',
`ip` varchar(15) NOT NULL default '',
`action` varchar(15) NOT NULL default '',
`time` datetime default NULL,
`content` varchar(64) NOT NULL default '',
`email` varchar(128) NOT NULL default ''
) TYPE=MyISAM;

# --------------------------------------------------------

#
# Table structure for table `message`
#

CREATE TABLE `message` (
`id` int(5) unsigned NOT NULL auto_increment,
`title` varchar(255) NOT NULL default '',
`body` text NOT NULL,
`createtime` datetime NOT NULL default '0000-00-00 00:00:00',
`updatetime` datetime NOT NULL default '0000-00-00 00:00:00',
`pw_domain` varchar(64) NOT NULL default '',
UNIQUE KEY `id` (`id`)
) TYPE=MyISAM ;

# --------------------------------------------------------

#
# Table structure for table `personal`
#
//原来的monthe,day为大写,改成小写
CREATE TABLE `personal` (
`id` int(11) unsigned NOT NULL auto_increment,
`pw_id` int(5) NOT NULL default '0',
`truename` varchar(10) NOT NULL default '',
`fax` varchar(20) NOT NULL default '',
`telephone` varchar(15) NOT NULL default '',
`sex` int(1) NOT NULL default '0',
`year` int(4) NOT NULL default '0',
`month` int(2) NOT NULL default '0',
`day` int(2) NOT NULL default '0',
`education` varchar(4) NOT NULL default '',
`marital` int(1) NOT NULL default '0',
`occupation` varchar(15) NOT NULL default '',
`companyname` varchar(30) NOT NULL default '',
`province` varchar(6) NOT NULL default '',
PRIMARY KEY (`id`)
) TYPE=MyISAM PACK_KEYS=1 ;

# --------------------------------------------------------

#
# Table structure for table `scheduler`
#

CREATE TABLE `scheduler` (
`id` int(11) unsigned NOT NULL auto_increment,
`begin_time` int(11) unsigned default NULL,
`end_time` int(11) unsigned default NULL,
`title` varchar(255) NOT NULL default '',
`body` varchar(255) NOT NULL default '',
`pw_id` int(11) unsigned NOT NULL default '0',
PRIMARY KEY (`id`)
) TYPE=MyISAM ;

# --------------------------------------------------------

#
# Table structure for table `stow`
#

CREATE TABLE `stow` (
`id` int(5) unsigned NOT NULL auto_increment,
`pw_id` int(5) unsigned NOT NULL default '0',
`Name` varchar(128) NOT NULL default '',
`http` varchar(255) NOT NULL default 'http://',
`memo` varchar(255) NOT NULL default '',
PRIMARY KEY (`id`)
) TYPE=MyISAM ;

# --------------------------------------------------------

#
# Table structure for table `vpopmail`
#

CREATE TABLE `vpopmail` (
`pw_id` int(5) unsigned NOT NULL auto_increment,
`pw_name` varchar(32) NOT NULL default '',
`pw_domain` varchar(64) NOT NULL default '',
`pw_passwd` varchar(40) NOT NULL default '',
`pw_uid` int(11) default NULL,
`pw_gid` int(11) default NULL,
`pw_gecos` varchar(4 default NULL,
`pw_dir` varchar(255) default NULL,
`pw_shell` varchar(20) default NULL,
`createtime` timestamp(14) NOT NULL,
PRIMARY KEY (`pw_id`),
KEY `pw_name` (`pw_name`,`pw_domain`)
) TYPE=MyISAM PACK_KEYS=1 ;

修改config/config_inc.php
$CFG_BASEPATH = "/var/mail/igenus";
$CFG_MYSQL_HOST = 'localhost';
$CFG_MYSQL_USER = 'postfix';
$CFG_MYSQL_PASS = 'admin123';
$CFG_MYSQL_DB = 'mail';
$CFG_NETDISK_PATH = "/var/mail/igenus/netdisk";

$CFG_TEMP = $CFG_BASEPATH."/../../temp";
改成:
$CFG_TEMP = $CFG_BASEPATH."/temp";

修改include/login_inc.php
if ( !isset($_SESSION['G_USERNAME']) || $SG_USERNAME == "" ||
!isset($_SESSION['G_DOMAIN']) || $SG_DOMAIN == "" ||
!isset($_SESSION['G_HOME']) || $SG_HOME == "" ||
!isset($_SESSION['G_TIME']) || $SG_TIME == "" ||
!isset($_SESSION['G_NICKNAME']) || $SG_NICKNAME == ""
){
header("Location: login.php");
exit();
}
改成:
if ( !isset($_SESSION['G_USERNAME']) || $SG_USERNAME == "" ||
!isset($_SESSION['G_DOMAIN']) || $SG_DOMAIN == "" ||
!isset($_SESSION['G_HOME']) || $SG_HOME == "" ||
!isset($_SESSION['G_TIME']) || $SG_TIME == ""
// !isset($_SESSION['G_NICKNAME']) || $SG_NICKNAME == ""
){
header("Location: login.php");
exit();
}

修改login.php
if ($CFG_VPOPMAIL_MYSQL_LARGE_SITE){
$Vpopmail_Domain = ereg_replace("\.","_",$Post_domain);
$query = "SELECT * FROM $Vpopmail_Domain WHERE pw_name='$Post_name'";
}else{
$query = "SELECT * FROM vpopmail WHERE pw_name='$Post_name' and
pw_domain='$Post_domain'";
}
改成:
if ($CFG_VPOPMAIL_MYSQL_LARGE_SITE){
$Vpopmail_Domain = ereg_replace("\.","_",$Post_domain);
$query = "SELECT * FROM $Vpopmail_Domain WHERE pw_name='$Post_name'";
}else{
$query = "SELECT * FROM virtual_users WHERE name='$Post_name' and
domain='$Post_domain'";
}

$data = mysql_fetch_array($result);
$home = $data['pw_dir'];
$Post_passwd2 = $data['pw_passwd'];
$pw_id = $data['pw_id'];
$pw_shell = $data['pw_shell'];
$pw_gecos = $data['pw_gecos'];
$pw_gid = $data['pw_gid'];
$pw_domain = strtolower($data['pw_domain']);
$pw_name = strtolower($data['pw_name']);
改成:
$data = mysql_fetch_array($result);
$home1 = $data['home'];
$home2 = $data['maildir'];
$home = $home1.$home2;
$Post_passwd2 = $data['PASSWORD'];
$pw_id = $data['unique_id'];
$pw_shell = $data['quota'];
$pw_gecos = $data['nickname'];
$pw_domain = strtolower($data['domain']);
$pw_name = strtolower($data['name']);

修改inclue/mailbox_inc.php
$sizefile = "$SG_HOME/Maildir/maildirsize";
全部改成:
$sizefile = "$SG_HOME/maildirsize";

if(!is_dir("$SG_HOME/Maildir/$Mailbox")){
mkdir("$SG_HOME/Maildir/$Mailbox",0700);
mkdir("$SG_HOME/Maildir/$Mailbox/new",0700);
mkdir("$SG_HOME/Maildir/$Mailbox/cur",0700);
mkdir("$SG_HOME/Maildir/$Mailbox/tmp",0700);
}
改成:
if(!is_dir("$SG_HOME/$Mailbox")){
mkdir("$SG_HOME/$Mailbox",0700);
mkdir("$SG_HOME/$Mailbox/new",0700);
mkdir("$SG_HOME/$Mailbox/cur",0700);
mkdir("$SG_HOME/$Mailbox/tmp",0700);
}

$home = $SG_HOME . "/Maildir/".$Mailbox."/new";
改成:
$home = $SG_HOME . $Mailbox."/new";

$home = $SG_HOME . "/Maildir/".$Mailbox."/cur";
改成:
$home = $SG_HOME . $Mailbox."/cur";

修改sendmail.php
$Path = "$SG_HOME/Maildir/".$CFG_MAILBOX['outbox']."/new/" . $Path;
改成:
$Path = "$SG_HOME/".$CFG_MAILBOX['outbox']."/new/" . $Path;

$Path = "$SG_HOME/Maildir/".$CFG_MAILBOX['draft']."/new/" . $Path;
改成:
$Path = "$SG_HOME/".$CFG_MAILBOX['draft']."/new/" . $Path;

修改list.php
if(!is_dir("$SG_HOME/Maildir/$mailbox")){
mkdir("$SG_HOME/Maildir/$mailbox",0700);
mkdir("$SG_HOME/Maildir/$mailbox/new",0700);
mkdir("$SG_HOME/Maildir/$mailbox/cur",0700);
mkdir("$SG_HOME/Maildir/$mailbox/tmp",0700);
}
改成:
if(!is_dir("$SG_HOME/$mailbox")){
mkdir("$SG_HOME/$mailbox",0700);
mkdir("$SG_HOME/$mailbox/new",0700);
mkdir("$SG_HOME/$mailbox/cur",0700);
mkdir("$SG_HOME/$mailbox/tmp",0700);
}

$myhome = "$SG_HOME/Maildir/$mailbox/$home";
改成:
$myhome = "$SG_HOME/$mailbox/$home";

修改folder.php
$mailfile = "$SG_HOME/Maildir/$SMailbox/$IsNew/$File";
改成:
$mailfile = "$SG_HOME/$SMailbox/$IsNew/$File";

$home = $SG_HOME . "/Maildir/".$SMailbox."/cur";
改成:
home = $SG_HOME .$SMailbox."/cur";

$mailfile = "$SG_HOME/Maildir/$SMailbox/cur/$file";
改成:
$mailfile = "$SG_HOME/$SMailbox/cur/$file";

link($mailfile, "$SG_HOME/Maildir/$DMoveTo/$IsNew/$cur_file");
改成:
link($mailfile, "$SG_HOME/$DMoveTo/$IsNew/$cur_file");

修改prev.php
$mailfile = "$SG_HOME/Maildir/$SMailbox/$IsNew/$File";
改成:
$mailfile = "$SG_HOME/$SMailbox/$IsNew/$File";

$home = $SG_HOME . "/Maildir/".$SMailbox."/cur";
改成:
$home = $SG_HOME .$SMailbox."/cur";

$mailfile = "$SG_HOME/Maildir/$SMailbox/cur/$file";
改成:
$mailfile = "$SG_HOME/$SMailbox/cur/$file";

if(file_exists("$SG_HOME/Maildir/$SMailbox/new/$File")) {
@link("$SG_HOME/Maildir/$SMailbox/new/$File",
"$SG_HOME/Maildir/$SMailbox/cur/$File:2,S");
@unlink("$SG_HOME/Maildir/$SMailbox/new/$File");
}
改成:
if(file_exists("$SG_HOME/$SMailbox/new/$File")) {
@link("$SG_HOME/$SMailbox/new/$File",
"$SG_HOME/$SMailbox/cur/$File:2,S");
@unlink("$SG_HOME/$SMailbox/new/$File");
}

$home = $SG_HOME . "/Maildir/".$SMailbox."/cur";
改成:
$home = $SG_HOME .$SMailbox."/cur";

if($isread==0)
{
@link("$SG_HOME/Maildir/$SMailbox/cur/$file",
"$SG_HOME/Maildir/$SMailbox/cur/$file"."S");
@unlink("$SG_HOME/Maildir/$SMailbox/cur/$file");
}
改成:
if($isread==0)
{
@link("$SG_HOME/$SMailbox/cur/$file",
"$SG_HOME/$SMailbox/cur/$file"."S");
@unlink("$SG_HOME/$SMailbox/cur/$file");
}

修改passwd.php
$query = "SELECT pw_name,pw_passwd FROM vpopmail WHERE pw_id='$SG_ID'";
改成:
$query = "SELECT name,PASSWORD FROM virtual_users WHERE unique_id='$SG_ID'";

if( $row->pw_passwd!=crypt($post_OldPasswd,$row->pw_passwd) ) {
改成:
if( $row->ASSWORD!=crypt($post_OldPasswd,$row->ASSWORD) ) {

$query = "UPDATE vpopmail SET pw_passwd='$NewPasswd' WHERE pw_id='$SG_ID'";
改成:
$query = "UPDATE virtual_users SET PASSWORD='$NewPasswd' WHERE unique_id='$SG_ID'";

修改read.php
if(!file_exists($mailfile))
{
$home = $SG_HOME . "/Maildir/".$SMailbox."/cur";
$handle=opendir($home);

while (($filename = readdir($handle))!==false)
{
if (substr_count($filename, $file)==1)
{
$mailfile = "$SG_HOME/Maildir/$SMailbox/cur/$filename";
}
}
closedir($handle);
}
改成:
if(!file_exists($mailfile))
{
$home = $SG_HOME .$SMailbox."/cur";
$handle=opendir($home);

while (($filename = readdir($handle))!==false)
{
if (substr_count($filename, $file)==1)
{
$mailfile = "$SG_HOME/Maildir/$SMailbox/cur/$filename";
}
}
closedir($handle);
}

$mailfile = "$SG_HOME/Maildir/$SMailbox/$isnew/$file";
改成:
$mailfile = "$SG_HOME/$SMailbox/$isnew/$file";

$mailfile = "$SG_HOME/Maildir/$SMailbox/cur/$filename";
改成:
$mailfile = "$SG_HOME/$SMailbox/cur/$filename";

修改forward.php
$mailfile = "$SG_HOME/Maildir/$SMailbox/$IsNew/$File";
if(!file_exists($mailfile)) $mailfile = "$SG_HOME/Maildir/$SMailbox/cur/$Files";
改成:
$mailfile = "$SG_HOME/$SMailbox/$IsNew/$File";
if(!file_exists($mailfile)) $mailfile = "$SG_HOME/$SMailbox/cur/$Files";

其它小方面的修改,把不能实现的功能和我自己觉得没用的功能屏蔽掉。
修改template\_menu.php把邮件过滤、转发、自动回复屏蔽掉。
<!--<TR>

<TD><IMG SRC="images/folder/vertline.gif" WIDTH="16" HEIGHT="22">
<IMG SRC="images/folder/node.gif" WIDTH="16" HEIGHT="22">
<IMG SRC="images/folder/antispam.gif" WIDTH="22" HEIGHT="21">
</TD>
<TD><A HREF="javascript:OpenWin('filter.php')">
<?php echo $LANG_MENU_SETUP_FILTER;?></A></TD>
</TR>-->

<!--<TR>
<TD><IMG SRC="images/folder/vertline.gif" WIDTH="16" HEIGHT="22">
<IMG SRC="images/folder/node.gif" WIDTH="16" HEIGHT="22">
<IMG SRC="images/folder/forward.gif" WIDTH="22" HEIGHT="21">
</TD>
<TD><A HREF="javascript:OpenWin('forwarders.php')">
<?php echo $LANG_MENU_SETUP_FORWARD;?></A></TD>

</TR>-->
<!--<TR>
<TD><IMG SRC="images/folder/vertline.gif" WIDTH="16" HEIGHT="22">
<IMG SRC="images/folder/node.gif" WIDTH="16" HEIGHT="22">
<IMG SRC="images/folder/autorespond.gif" WIDTH="22" HEIGHT="21">
</TD>
<TD><A HREF="javascript:OpenWin('autorespond.php')">

<?php echo $LANG_MENU_SETUP_AUTORESPOND;?></A></TD>
</TR>-->

屏蔽掉内部通知、日程安排、帮助。
<!--<TR>
<TD> <TABLE WIDTH="100%" BORDER="0" CELLSPACING="0" CELLPADDING="0">
<TR>

<TD WIDTH="38">
<IMG SRC="images/folder/node.gif" WIDTH="16" HEIGHT="22">
<IMG SRC="images/folder/message.gif" WIDTH="22" HEIGHT="21"></TD>
<TD><A HREF=message.php TARGET="main">
<?php echo $LANG_MENU_MESSAGE;?></A></TD>
</TR>
</TABLE></TD>

</TR>
<TR>
<TD> <TABLE WIDTH="100%" BORDER="0" CELLSPACING="0" CELLPADDING="0">
<TR>
<TD WIDTH="38">
<IMG SRC="images/folder/node.gif" WIDTH="16" HEIGHT="22">
<IMG SRC="images/folder/scheduler.gif" WIDTH="22" HEIGHT="21"></TD>

<TD><A HREF=scheduler.php TARGET="main">
<?php echo $LANG_MENU_SCHEDULE;?></A></TD>
</TR>
</TABLE></TD>
</TR>
<TR>
<TD> <TABLE WIDTH="100%" BORDER="0" CELLSPACING="0" CELLPADDING="0">

<TR>
<TD WIDTH="38">
<IMG SRC="images/folder/node.gif" WIDTH="16" HEIGHT="22">
<IMG SRC="images/folder/help.gif" WIDTH="22" HEIGHT="21"></TD>
<TD><A HREF="#">
<?php echo $LANG_MENU_HELP;?></A></TD>
</TR>

</TABLE></TD>
</TR>-->

修改template\_mailbox.php把日程安排和内部通知屏蔽掉。
<!--<td width="46%" valign="top">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="right"><strong>

<?php echo $LANG_MAILBOX_HELO?>,</strong><U>
<?php echo $OUT['NICKNAME']?></U><strong>
<?php echo $LANG_MAILBOX_TODAY_IS?>: </strong><u>
<?php echo $OUT['today']?></u>

<u><?php echo $LANG_WEEKDAY.$OUT['weekday']?></u>
</td>
</tr>
</table>
<TABLE BORDER="1" CELLSPACING="0" CELLPADDING="1" BGcolor="#EAF3E9"
BORDERcolor="#FFFFFF" WIDTH="100%" ALIGN="CENTER">
<TR BGcolor="#FFFFFF">
<TD HEIGHT="22" colspan="2"><img src=images/dot-2.gif>

<strong><?php echo $LANG_MAILBOX_TODAY_SCHEDULER?></strong>
</TD>
</TR>
<TR>
<TD HEIGHT="22" align="CENTER" bgcolor="#D0E6CE"><B>
<?php echo $LANG_MAILBOX_DATETIME?></B></TD>

<TD align="CENTER" bgcolor="#D0E6CE"><B>
<?php echo $LANG_MAILBOX_SUBJ?></B></TD>
</TR>
<?php echo $OUT['scheduler']?>
<TR >
<td height="20" colspan="2"align="right" bgcolor="#FFFFFF">
<a href="scheduler.php"><?php echo $LANG_MAILBOX_MORE?>

>>></a>
</td>
</TR>
</TABLE>
<TABLE BORDER="1" CELLSPACING="0" CELLPADDING="1" BGcolor="#EAF3E9"
BORDERcolor="#FFFFFF" WIDTH="100%" ALIGN="CENTER">
<TR BGcolor="#FFFFFF">
<TD HEIGHT="22" colspan="3"> <p><img src=images/dot-2.gif>

<strong><?php echo $LANG_MAILBOX_NOTICE?></strong></p>
</TD>
</TR>
<TR>
<TD HEIGHT="22" align="CENTER" bgcolor="#D0E6CE"> <B>
<?php echo $LNAG_LIST_NUM?></B> </TD>

<TD align="CENTER" bgcolor="#D0E6CE"><B>
<?php echo $LANG_MAILBOX_SUBJ?></B> </TD>
<TD align="CENTER" bgcolor="#D0E6CE"><B>
<?php echo $LANG_MAILBOX_DATETIME?></B></TD>
</TR>

<?php echo $ListOut;?>
<TR >
<td height="20" colspan="3"align="right" bgcolor="#FFFFFF">
<a href="message.php"><?php echo $LANG_MAILBOX_MORE?>
>>></a>
</td>
</TR>
</TABLE>

</td>-->
<td width="10"> </td>
<td valign="top"><TABLE WIDTH="100%" BORDER="0" ALIGN="CENTER">
<tr>
<td align="right"><strong>
<?php echo $LANG_MAILBOX_HELO?>,</strong><U>

<?php echo $OUT['N
ICKNAME']?></U><strong>
<?php echo $LANG_MAILBOX_TODAY_IS?>: </strong><u>
<?php echo $OUT['today']?></u>
<u><?php echo $LANG_WEEKDAY.$OUT['weekday']?>

</u></td>
</tr>
<TR>

修改template\_login.php如title、Copyright以适合自己情况。
修改language\gb_inc.php里的$LANG_LOGIN_WELCOME。
修改config\config_inc.php里的iGENUS is a free webmail interface等。
________________________________________
Chapter 6. 邮件服务器的管理
6.1 配置apache
配置apache
mail# mkdir /var/mail/admin_mail

mail# cd /var/mail/admin_mail
mail# vi .htaccess

内容如下:
authname "Email Admin"
authtype basic
authuserfile /etc/htpasswd
require user admin

修改/usr/local/etc/apache/httpd.conf,增加以下内容
Listen 80
Listen 2888

NameVirtualHost *:2888
<VirtualHost *:2888>
DocumentRoot /var/mail/admin_mail
<Directory "/var/mail/admin_mail">

options indexes followsymlinks
allowoverride authconfig
order allow,deny
allow from all
</Directory>
ServerAdmin webmaster@test.com
ErrorLog /var/log/admin_mail-error.log
CustomLog /var/log/admin_mail-access.log common
</VirtualHost>

________________________________________
6.2 管理程序源代码
________________________________________
6.3 配置文件config.inc.php
配置文件config.inc.php
<?php

//MySQL
$CFG_MYSQL_HOST = 'localhost';
$CFG_MYSQL_USER = 'postfix';
$CFG_MYSQL_PASS = 'admin123';
$CFG_MYSQL_DB = 'mail';

//Language
$CFG_LANG = gb; //gb - Chinese GB
//en - English

//footer
function showFooter(){
echo "<hr size=\"1\">\n";
echo "<DIV style=\"FONT-SIZE: 11px\" align=\"left\">\n";
echo "Copyright 2001 - 2004 <b>

<a href=\"http://mske.com\" target=\"_blank\">Mske.com</a>
</B> All Rights Reserved.<BR>Email:webmaster at mske dot com\n";
echo "</DIV>\n";
}

?>

________________________________________
6.4 增加域名
增加域名,adddomain1.php
<?php

require("config.inc.php");
require("lang/$CFG_LANG"."_inc.php");

?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=<?php echo $CFG_CHARSET; ?>">
<title><?php echo $LANG_TITLE; ?></title>
</head>

<body>
<?php
$conn=mysql_connect($CFG_MYSQL_HOST,$CFG_MYSQL_USER,$CFG_MYSQL_PASS);
mysql_select_db($CFG_MYSQL_DB, $conn);

if (eregi("([0-9a-z][0-9a-z-]+\.)+[a-z]{2,3}$",$add_domain_name)) {

$sql = "select * from transport where domain='$add_domain_name'";
$query = mysql_query($sql, $conn);
$rows = mysql_num_rows($query);
if($rows==1){
echo "$LANG_DOMAIN_EXIST";
exit;
}

$sql ="insert into transport (domain,transport) values
('$add_domain_name','virtual:')";
$query = mysql_query($sql, $conn);

$dir1 = "/var/mail/" . $add_domain_name;

system("mkdir -p $dir1");

echo "$LANG_DOMAIN_SUCCEED";
}else{
echo "$LANG_DOMAIN_ERROR";
}
showFooter();
mysql_close($conn);
?>
</body>
</html>

________________________________________
6.5 增加用户
增加用户,adduser1.php和adduser2.php。
########adduser1.php#############
<?php
require("config.inc.php");
require("lang/$CFG_LANG"."_inc.php");
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>

<head>
<meta http-equiv="Content-Type" content="text/html;
charset=<?php echo $CFG_CHARSET; ?>">
<title><?php echo $LANG_TITLE; ?></title>
</head>

<body>
<?php
if (eregi("^[_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,3}$",$add_user_name)) {
?>

<div align="left">
<form action="adduser2.php" method="post">
<table cellspacing="2" cellpadding="2" border="0" width="664">
<tr>
<td bgcolor="#D0DCE0" width="10%"><?php echo $LANG_USER_MAILBOX ?> :</td>
<td bgcolor="#DDDDDD" width="90%"><?php echo $add_user_name ?></td>

</tr>
<tr>
<td bgcolor="#D0DCE0" width="10%"><?php echo $LANG_USER_PASSWD ?> :</td>
<td bgcolor="#DDDDDD" width="90%"><input type="text" name="add_password"
size="20" maxlength="128"></td>
</tr>

<tr>
<td bgcolor="#D0DCE0" width="10%"><?php echo $LANG_USER_NAME ?> :</td>
<td bgcolor="#DDDDDD" width="90%"><input type="text" name="add_realname"
size="10" maxlength="10"></td>
</tr>
<tr>

<td bgcolor="#D0DCE0" width="10%"><?php echo $LANG_USER_OFFICE ?> :</td>
<td bgcolor="#DDDDDD" width="90%"><input type="text" name="add_office"
size="20" maxlength="20"></td>
</tr>
<tr>
<td bgcolor="#D0DCE0" width="10%"><?php echo $LANG_USER_QUOTA ?> :</td>

<td bgcolor="#DDDDDD" width="90%"><input type="text" name="add_quota"
value="20971520" size="10" maxlength="255"></td>
</tr>
<tr>
<td colspan="2"><input type="submit" name="submit"
value="<?php echo $LANG_USER_ADDSUBMIT ?>"></td>
</tr>

</table>
<input type="hidden" name="add_user_name" value="<?php echo $add_user_name ?>">
</form>
</div>

<?php
}else{
echo "$LANG_USER_ERROR";
}
showFooter();
?>
</body>
</html>


########adduser2.php#############
<?php
require("config.inc.php");
require("lang/$CFG_LANG"."_inc.php");
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=<?php echo $CFG_CHARSET; ?>">
<title><?php echo $LANG_TITLE; ?></title>

</head>

<body>
<?php
$conn=mysql_connect($CFG_MYSQL_HOST,$CFG_MYSQL_USER,$CFG_MYSQL_PASS);
mysql_select_db($CFG_MYSQL_DB, $conn);

$id=$add_user_name;
$PASSWORD = crypt($add_password);
$domain = substr( strrchr( $add_user_name, "@" ), 1 );
$name = substr($add_user_name,0,(strlen($add_user_name)-strlen($domain)-1));
$date_add = date("Y-m-d");
$time_add = date("G-i-s");
$maildir = $domain . "/" . $name . "/Maildir/";

$sql = "select * from virtual_users where id='$id'";
$query = mysql_query($sql, $conn);
$rows = mysql_num_rows($query);
if($rows==1){
echo "$LANG_USER_EXIST";
exit;
}
$sql = "select * from transport where domain='$domain'";
$query = mysql_query($sql, $conn);
$rows = mysql_num_rows($query);
if($rows!==1){
echo "$LANG_USER_NODOMAIN";
exit;
}

$sql ="insert into virtual_users
(id,PASSWORD,uid,gid,home,maildir,date_add,time_add,domain,name,imapok,
quota,realname,office) values ('$id','$PASSWORD',125,125,'/var/mail/',
'$maildir','$date_add','$time_add','$domain','$name',1,'$add_quota',
'$add_realname','$add_office')";
$query = mysql_query($sql, $conn);

$dir1 = "/var/mail/" . $domain . "/" . $name;
$dir2 = $dir1 . "/Maildir";
system("mkdir -p $dir1");
system("/usr/local/bin/maildirmake $dir2");
system("chmod -R 700 $dir1");

echo "$LANG_USER_SUCCEED";

showFooter();
mysql_close($conn);
?>
</body>
</html>

________________________________________
6.6 查看系统状态
安装phpSysInfo(2.2)
mail# cd /usr/ports/www/phpSysInfo

mail# make install clean
mail# cd /usr/local/www/data-dist/phpSysInfo
mail# cp config.php.new config.php

修改/usr/local/etc/apache/httpd.conf,添加以下内容
Alias /phpSysInfo/ "/usr/local/www/data/phpSysInfo/"
<Directory "/usr/local/www/data/phpSysInfo">

Options Indexes FollowSymlinks MultiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory>
本人水平有限,错误之处在所难免,希望高手们给于指证(scyz2 at 163.com)。
发表于 2005-1-25 16:49:20 | 显示全部楼层
没法,强就一个字。慢慢看。本人还水平有限,完全看不懂呢。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2005-1-26 10:28:35 | 显示全部楼层

架构基于FreeBSD和Postfix的邮件系统 (全ports安装)不断整理中!!

架构基于FreeBSD和Postfix的邮件系统
FreeBSD+Postfix+cyrus-sasl+Courier-imap+igenus+Clamav+amavisd-new
杨廷勇
Copyright & 2004
本文介绍使用FreeBSD+Postfix+cyrus-sasl+Courier-imap+igenus+Clamav+amavisd-new来架构一个具有多域名,有webmai防病毒
和垃圾邮件并有web管理界面的邮件系统。
scyzxp, $Revision: 0.1 $Date: 2005-1-25
________________________________________
Table of Contents
1. 系统简介
1.1 系统结构
1.2 软件介绍
2. 系统安装
2.1 安装perl
2.2 安装MySQL
2.3 安装Apache
2.4 安装PHP
2.5 安装openssl
2.6 安装phpMyAdmin
2.7 通过phpMyadmin设置数据库
2.8 安装cyrus-sasl和cyrus-sasl2-saslauthd
2.9 安装pam_mysql
2.10 安装postfix
2.11 安装expect
2.12 安装Courier-imap
3. 设置第一个用户并测试
3.1 设置第一个用户
3.2 用户登录测试
3.3 建立其他用户
4. 防病毒与防垃圾邮件
4.1 安装Clamav
4.2 安装amavisd-new
4.3 安装配置Spamassassin
5. 安装webmail
6. 邮件服务器的管理
6.1 配置apache
6.2 管理程序源代码
6.3 配置文件config.inc.php
6.4 增加域名
6.5 增加用户
6.6 查看系统状态

________________________________________
Chapter 1. 系统简介
本章介绍了系统的组成。
________________________________________
1.1 系统结构
________________________________________
1.2 软件介绍
________________________________________
Chapter 2. 系统安装
安装之前:因用户数据都保存在/var目录下,因此安装FreeBSD时/var的空间应尽量大。FreeBSD的版本为4.9,按最小化安装,软件包只安装cvsup,安装结束后用cvsup更新ports树。在文档中假设服务器的ip地址为192.168.204.38,域名为test.com,主机名为mail.test.com。
________________________________________
2.1 安装perl
版本为5.8.5,FreeBSD缺省安装的perl版本无法支持目前的amavisd-new。
mail# cd /usr/ports/lang/perl5.8

mail# make install clean

让新版本的perl成为系统的缺省
mail# /usr/local/bin/use.perl port

________________________________________
2.2 安装MySQL
版本为4.0.20,因目前的pam_mysql版本不支持4.1所以安装MySQL40。
mail# cd /usr/ports/databases/mysql40-server
mail# make install clean


________________________________________
2.3 安装Apache
版本为1.3.31_4。
mail# cd /usr/ports/www/apache2
mail# make install clean

编辑/etc/rc.conf,加入
Apache2_enable="YES"

________________________________________
2.4 安装PHP
版本为4.3.10。
mail# cd /usr/ports/lang/php4

mail# make install clean

安装需要的PHP扩展模块
mail# cd /usr/ports/lang/php4-extensions
mail# make install clean

注:gettext需选中

________________________________________
2.5 安装openssl
mail# cd /usr/ports/security/openssl

mail# make install clean

________________________________________
2.6 安装phpMyAdmin
mail# cd /usr/ports/databases/phpmyadmin
mail# make install clean

编辑/usr/local/etc/apache/httpd.conf,加入
Alias /phpMyAdmin/ "/usr/local/www/phpMyAdmin/"

<Directory "/usr/local/www/phpMyAdmin">
Options Indexes FollowSymlinks
Allowoverride AuthConfig
Order allow,deny
Allow from all
</Directory>

编辑编辑/usr/local/www/phpMyAdmin/.htaccess
authname "MySQL Admin"
authtype basic
authuserfile /etc/htpasswd
require user admin

运行以下命令生成可访问phpMyadmin的用户:
mail# /usr/local/bin/htpasswd -c /etc/htpasswd admin

修改/usr/local/www/phpMyAdmin/config.inc.php
$cfg['PmaAbsoluteUri'] = 'http://192.168.9.33/phpMyAdmin/';

重启服务器
在浏览器输入http://192.168. 9.33/phpMyAdmin/,修改mysql数据库里user表里的root用户的密码为admin123。
重启MySQL,再编辑/usr/local/www/phpMyAdmin/config.inc.php
$cfg['Servers'][$i]['password'] = 'admin123';

________________________________________
2.7 通过phpMyadmin设置数据库
建立两个数据库用户
#======================postfix==================================

INSERT INTO user (host,user,password) VALUES('localhost','postfix','');
update user set password=password('admin123') where User='postfix';
FLUSH PRIVILEGES;
GRANT ALL ON mail.* TO postfix@localhost IDENTIFIED BY "admin123";
#======================courier==================================
INSERT INTO user (host,user,password) VALUES ('localhost','courier','');
update user set password=password('admin123') where User='courier';
FLUSH PRIVILEGES;
GRANT select,insert,update on mail.* TO courier;


建立数据库
#=======================MAIL.SQL=================================

#Create mail database

CREATE DATABASE mail;
use mail;

#Create the aliases table

CREATE TABLE aliases (

alias varchar(255) NOT NULL default '',
rcpt varchar(255) default NULL,
PRIMARY KEY (alias)
) TYPE=MyISAM;

#Create the transport table

CREATE TABLE transport (

domain char(128) NOT NULL default '',
transport char(128) NOT NULL default '',
UNIQUE KEY domain (domain)
) TYPE=MyISAM;

#Create the virtua_users table

CREATE TABLE virtual_users (

unique_id int(32) unsigned NOT NULL auto_increment,
id char(128) NOT NULL default '',
password char(128) default NULL,
uid int(10) unsigned default '125',
gid int(10) unsigned default '125',
home char(255) default NULL,

maildir char(255) default NULL,
date_add date default NULL,
time_add time default NULL,
domain char(128) default NULL,
name char(255) default NULL,
imapok tinyint(3) unsigned default '1',

###缺省邮箱大小20M
quota char(255) default '20971520',
nickname varchar(10) default NULL,
realname varchar(10) default NULL,
office varchar(20) default NULL,
PRIMARY KEY (id),

KEY unique_id (unique_id)
) TYPE=MyISAM;

________________________________________
2.8 安装cyrus-sasl和cyrus-sasl2-saslauthd
mail# cd /usr/ports/security/cyrus-sasl2-saslauthd
mail# make install clean

编辑/etc/rc.conf,加入
saslauthd_enable="YES"

建立一个目录连接
mail# ln -s /usr/local/lib/sasl2 /usr/lib/sasl2


配置sasl的lib库:在/etc/defaults/rc.conf文件里的ldconfig_paths="/usr/local/lib后面加上/usr/local/lib/sasl2"
运行:
mail# echo pwcheck_method:saslauthd > /usr/lib/sasl2/smtpd.conf

编辑/usr/local/etc/rc.d/saslauthd.sh
command="${prefix}/sbin/${name}"

改成:
command="${prefix}/sbin/${name} -r"

重启服务器
________________________________________
2.9 安装pam_mysql
mail# cd /usr/ports/security/pam-mysql
mail# make install clean
mail# cp /usr/local/lib/pam_mysql.so /usr/lib/

配置pam.conf调用mysql支持sasl认证。编辑/etc/pam.conf(将pop3 和imap的前面加上#)添加下列代码:
smtp auth sufficient pam_mysql.so user=postfix passwd=admin123 host=localhost db=mail table=virtual_users usercolumn=id passwdcolumn=password crypt=1
注:以上为一行。
smtp account required pam_mysql.so user=postfix passwd=admin123 host=localhost db=mail table=virtual_users usercolumn=id passwdcolumn=password crypt=1
注:以上为一行。

注:用tab键分隔,不是用空格。密码使用crypt加密,如果使用明文密码cyrpt=0,如果
使用password()加密crypt=2

________________________________________
2.10 安装postfix
停止sendmail
mail# killall sendmail
mail# mv /usr/bin/newaliases /usr/bin/newaliases.OFF

mail# mv /usr/bin/mailq /usr/bin/mailq.OFF
mail# mv /usr/sbin/sendmail /usr/sbin/sendmail.OFF
mail# mv /etc/rc.sendmail /etc/sendmail.OFF

开始安装postfix
mail# cd /usr/ports/mail/postfix

mail# make install clean

安装中选中SASL2、MySQL,及回答以下的问题。
You need user "postfix" added to group "mail".
Would you like me to add it [y]? y
Would you like to activate Postfix in /etc/mail/mailer.conf [n]? n

安装完进行一些设置:
mail# cd /usr/local/etc/rc.d
mail# ln -s /usr/local/sbin/postfix postfix.sh

mail# ln -s /usr/local/sbin/sendmail /usr/sbin/sendmail

mail# echo ‘postfix: root’ >> /etc/aliases
mail# /usr/local/bin/newaliases
mail# chown postfix:postfix /etc/opiekeys

编辑/etc/rc.conf
sendmail_enable="YES"
sendmail_flags="-bd"
sendmail_outbound_enable="NO"
sendmail_submit_enable="NO"
sendmail_msp_queue_enable="NO"
编辑//etc/periodic.conf
daily_clean_hoststat_enable="NO"
daily_status_mail_rejects_enable="NO"
daily_status_include_submit_mailq="NO"
daily_submit_queuerun="NO"
修改/usr/local/etc/postfix/main.cf,在文件最后加入以下内容
#======= BASE ==============
myhostname = mail.test.com
mydomain = test.com
home_mailbox = Maildir/
mydestination = $myhostname, $mydomain, $transport_maps
local_recipient_maps =
mailbox_command= /usr/local/bin/deliverquota -w 90 ~/Maildir
command_directory = /usr/local/sbin
#======= MYSQL =============
transport_maps = mysql:/usr/local/etc/postfix/transport.cf
virtual_gid_maps = mysql:/usr/local/etc/postfix/gids.cf
virtual_mailbox_base = /var/mail
virtual_mailbox_maps = mysql:/usr/local/etc/postfix/mysql_virtual.cf
virtual_maps = mysql:/usr/local/etc/postfix/mysql.aliases.cf
virtual_uid_maps = mysql:/usr/local/etc/postfix/uids.cf
#======= Quota ============
message_size_limit = 4194304 //限制每次发邮件的大小4MB
virtual_mailbox_limit_inbox = no
virtual_mailbox_limit_maps = mysql:/usr/local/etc/postfix/mailboxsize-mysql.cf
virtual_mailbox_limit_override = yes
virtual_maildir_extended = yes
virtual_create_maildirsize = yes
virtual_mailbox_limit = 20971520 //总邮箱的大小20MB
#====== SASL ================
smtpd_sasl_auth_enable = yes
smtpd_sasl_security_options = noanonymous
broken_sasl_auth_clients = yes
smtpd_recipient_restrictions = permit_sasl_authenticated permit_auth_destination reject
#smtpd_sasl_local_domain = $mydomain
smtpd_client_restrictions = permit_sasl_authenticated

确认/usr/local/etc/postfix/master.cf的配置有如下内容
virtual unix - n n - - virtual

编辑/usr/local/etc/posftix/transport.cf
user = postfix
password = admin123
dbname = mail
table = transport
select_field = transport
where_field = domain
hosts = localhost

编辑/usr/local/etc/postfix/gids.cf
user = postfix
password= admin123
dbname = mail
table = virtual_users
select_field = gid
where_field = id
hosts = localhost

编辑/usr/local/etc/postfix/uids.cf
user = postfix
password= admin123
dbname = mail
table = virtual_users
select_field = uid
where_field = id
hosts = localhost

编辑/usr/local/etc/posftix/mysql_virtual.cf
user = postfix
password= admin123
dbname = mail
table = virtual_users
select_field = maildir
where_field = id
hosts = localhost

编辑/usr/local/etc/postfix/mysql.aliases.cf
user = postfix
password= admin123
dbname = mail
table = aliases
select_field = rcpt
where_field = alias
hosts = localhost

编辑/etc/postfix/mailboxsize-mysql.cf
user = postfix
password = admin123
dbname = mail
table = virtual_users
select_field = quota
where_field = id
hosts = localhost

________________________________________
2.11 安装expect
mail# cd /usr/ports/lang/expect

mail# make install clean

________________________________________
2.12 安装Courier-imap
由于courier-imap 从 4版本开始,把 courier-authlib 独立出来了,需要先安装 courier-authlib. 具体步骤:
mail# cd courier-authlib
mail# make WITH_MYSQL=yes
mail# make install
mail# cd /usr/ports/mail/courier-imap
mail# make WITHOUT_OPENSSL= yes WITH_MYSQL= yes install clean

mail# cd /usr/local/etc/rc.d
mail# mv courier-imap-imapd-ssl.sh.sample courier-imap-imapd-ssl.sh
mail# mv courier-imap-imapd.sh.sample courier-imap-imapd.sh
mail# mv courier-imap-pop3d-ssl.sh.sample courier-imap-pop3d-ssl.sh

mail# mv courier-imap-pop3d.sh.sample courier-imap-pop3d.sh
mail# cd /usr/local/etc/authlih
mail# cd /usr/local/etc/courier-imap
mail# cp authdaemonrc.dist authdaemonrc
mail# cp authmysqlrc.dist authmysqlrc
mail# cd /usr/local/etc/courier-imap
mail# cp imapd-ssl.dist imapd-ssl
mail# cp imapd.cnf.dist imapd.cnf
mail# cp imapd.dist imapd
mail# cp pop3d-ssl.dist pop3d-ssl
mail# cp pop3d.cnf.dist pop3d.cnf
mail# cp pop3d.dist pop3d

编辑修改/usr/local/etc/courier-imap/authmysqlrc 示例:authmysqlrc
##VERSION: $Id: install.sgml,v 1.1 2004/11/01 14:47:56 wt Exp $
#
# Copyright 2000-2004 Double Precision, Inc. See COPYING for
# distribution information.
#
# Do not alter lines that begin with ##, they are used when upgrading
# this configuration.
#
# authmysqlrc created from authmysqlrc.dist by sysconftool
#
# DO NOT INSTALL THIS FILE with world read permissions. This file
# might contain the MySQL admin password!
#
# Each line in this file must follow the following format:
#
# field[spaces|tabs]value
#
# That is, the name of the field, followed by spaces or tabs, followed by
# field value. Trailing spaces are prohibited.


##NAME: LOCATION:0
#
# The server name, userid, and password used to log in.

MYSQL_SERVER localhost
MYSQL_USERNAME courier
MYSQL_PASSWORD admin123

##NAME: MYSQL_SOCKET:0
#
# MYSQL_SOCKET can be used with MySQL version 3.22 or later, it specifies the
# filesystem pipe used for the connection
#
# MYSQL_SOCKET /var/mysql/mysql.sock

##NAME: MYSQL_PORT:0
#
# MYSQL_PORT can be used with MySQL version 3.22 or later to specify a port to
# connect to.

MYSQL_PORT 3306

##NAME: MYSQL_OPT:0
#
# Leave MYSQL_OPT as 0, unless you know what you're doing.

MYSQL_OPT 0

##NAME: MYSQL_DATABASE:0
#
# The name of the MySQL database we will open:

MYSQL_DATABASE mail

##NAME: MYSQL_USER_TABLE:0
#
# The name of the table containing your user data. See README.authmysqlrc
# for the required fields in this table.

MYSQL_USER_TABLE virtual_users

##NAME: MYSQL_CRYPT_PWFIELD:0
#
# Either MYSQL_CRYPT_PWFIELD or MYSQL_CLEAR_PWFIELD must be defined. Both
# are OK too. crypted passwords go into MYSQL_CRYPT_PWFIELD, cleartext
# passwords go into MYSQL_CLEAR_PWFIELD. Cleartext passwords allow
# CRAM-MD5 authentication to be implemented.

MYSQL_CRYPT_PWFIELD password

##NAME: MYSQL_CLEAR_PWFIELD:0
#
#
# MYSQL_CLEAR_PWFIELD clear

##NAME: MYSQL_DEFAULT_DOMAIN:0
#
# If DEFAULT_DOMAIN is defined, and someone tries to log in as 'user',
# we will look up 'user@DEFAULT_DOMAIN' instead.
#
#
# DEFAULT_DOMAIN example.com

##NAME: MYSQL_UID_FIELD:0
#
# Other fields in the mysql table:
#
# MYSQL_UID_FIELD - contains the numerical userid of the account
#
MYSQL_UID_FIELD uid

##NAME: MYSQL_GID_FIELD:0
#
# Numerical groupid of the account

MYSQL_GID_FIELD gid

##NAME: MYSQL_LOGIN_FIELD:0
#
# The login id, default is id. Basically the query is:
#
# SELECT MYSQL_UID_FIELD, MYSQL_GID_FIELD, ... WHERE id='loginid'
#

MYSQL_LOGIN_FIELD id

##NAME: MYSQL_HOME_FIELD:0
#

MYSQL_HOME_FIELD home

##NAME: MYSQL_NAME_FIELD:0
#
# The user's name (optional)

MYSQL_NAME_FIELD name

##NAME: MYSQL_MAILDIR_FIELD:0
#
# This is an optional field, and can be used to specify an arbitrary
# location of the maildir for the account, which normally defaults to
# $HOME/Maildir (where $HOME is read from MYSQL_HOME_FIELD).
#
# You still need to provide a MYSQL_HOME_FIELD, even if you uncomment this
# out.
#
MYSQL_MAILDIR_FIELD maildir

##NAME: MYSQL_DEFAULTDELIVERY:0
#
# Courier mail server only: optional field specifies custom mail delivery
# instructions for this account (if defined) -- essentially overrides
# DEFAULTDELIVERY from ${sysconfdir}/courierd
#
# MYSQL_DEFAULTDELIVERY defaultdelivery

##NAME: MYSQL_QUOTA_FIELD:0
#
# Define MYSQL_QUOTA_FIELD to be the name of the field that can optionally
# specify a maildir quota. See README.maildirquota for more information
#
MYSQL_QUOTA_FIELD quota

##NAME: MYSQL_AUXOPTIONS:0
#
# Auxiliary options. The MYSQL_AUXOPTIONS field should be a char field that
# contains a single string consisting of comma-separated "ATTRIBUTE=NAME"
# pairs. These names are additional attributes that define various per-account
# "options", as given in INSTALL's description of the "Account OPTIONS"
# setting.
#
# MYSQL_AUXOPTIONS_FIELD auxoptions
#
# You might want to try something like this, if you'd like to use a bunch
# of individual fields, instead of a single text blob:
#
# MYSQL_AUXOPTIONS_FIELD CONCAT("disableimap=",disableimap,",
#disablepop3=",disablepop3,",di
#sablewebmail=",disablewebmail,",sharedgroup=",sharedgroup)
#
# This will let you define fields called "disableimap", etc, with the end result
# being something that the OPTIONS parser understands.


##NAME: MYSQL_WHERE_CLAUSE:0
#
# This is optional, MYSQL_WHERE_CLAUSE can be basically set to an arbitrary
# fixed string that is appended to the WHERE clause of our query
#
# MYSQL_WHERE_CLAUSE server='mailhost.example.com'


##NAME: MYSQL_SELECT_CLAUSE:0
#
# (EXPERIMENTAL)
# This is optional, MYSQL_SELECT_CLAUSE can be set when you have a database,
# which is structuraly different from proposed. The fixed string will
# be used to do a SELECT operation on database, which should return fields
# in order specified bellow:
#
# username, cryptpw, clearpw, uid, gid, home, maildir, quota, fullname, options
#
# The username field should include the domain (see example below).
#
# Enabling this option causes ignorance of any other field-related
# options, excluding default domain.
#
# There are two variables, which you can use. Substitution will be made
# for them, so you can put entered username (local part) and domain name
# in the right place of your query. These variables are:
# $(local_part), $(domain), $(service)
#
# If a $(domain) is empty (not given by the remote user) the default domain
# name is used in its place.
#
# $(service) will expand out to the service being authenticated: imap, imaps,
# pop3 or pop3s. Courier mail server only: service will also expand out to
# "courier", when searching for local mail account's location. In this case,
# if the "maildir" field is not empty it will be used in place of
# DEFAULTDELIVERY. Courier mail server will also use esmtp when doing
# authenticated ESMTP.
#
# This example is a little bit modified adaptation of vmail-sql
# database scheme:
#
# MYSQL_SELECT_CLAUSE SELECT CONCAT(popbox.local_part, '@', popbox.domain_name),
\
# CONCAT('{MD5}', popbox.password_hash), \
# popbox.clearpw, \
# domain.uid, \
# domain.gid, \
# CONCAT(domain.path, '/', popbox.mbox_name), \
# '', \
# domain.quota, \
# '', \
# CONCAT("disableimap=",disableimap,",disablepop3=", \
# disablepop3,",disablewebmail=",disablewebmail, \
# ",sharedgroup=",sharedgroup) \
# FROM popbox, domain \
# WHERE popbox.local_part = '$(local_part)' \
# AND popbox.domain_name = '$(domain)' \
# AND popbox.domain_name = domain.domain_name


##NAME: MYSQL_ENUMERATE_CLAUSE:0
#
# {EXPERIMENTAL}
# Optional custom SQL query used to enumerate accounts for authenumerate,
# in order to compile a list of accounts for shared folders. The query
# should return the following fields: name, uid, gid, homedir, maildir
#
# Example:
# MYSQL_ENUMERATE_CLAUSE SELECT CONCAT(popbox.local_part, '@',
#popbox.domain_name),
\
# domain.uid, \
# domain.gid, \
# CONCAT(domain.path, '/', popbox.mbox_name), \
# '' \
# FROM popbox, domain \
# WHERE popbox.local_part = '$(local_part)' \
# AND popbox.domain_name = '$(domain)' \
# AND popbox.domain_name = domain.domain_name



##NAME: MYSQL_CHPASS_CLAUSE:0
#
# (EXPERIMENTAL)
# This is optional, MYSQL_CHPASS_CLAUSE can be set when you have a database,
# which is structuraly different from proposed. The fixed string will
# be used to do an UPDATE operation on database. In other words, it is
# used, when changing password.
#
# There are four variables, which you can use. Substitution will be made
# for them, so you can put entered username (local part) and domain name
# in the right place of your query. There variables are:
# $(local_part) , $(domain) , $(newpass) , $(newpass_crypt)
#
# If a $(domain) is empty (not given by the remote user) the default domain
# name is used in its place.
# $(newpass) contains plain password
# $(newpass_crypt) contains its crypted form
#
# MYSQL_CHPASS_CLAUSE UPDATE popbox \
# SET clearpw='$(newpass)', \
# password_hash='$(newpass_crypt)' \
# WHERE local_part='$(local_part)' \
# AND domain_name='$(domain)'
#

重启服务器
________________________________________
Chapter 3. 设置第一个用户并测试
本章介绍如何开通用户,并且测试系统是否正常。
________________________________________
3.1 设置第一个用户
设置第一个用户
mail# mysql

mysql> use mail;
mysql> show tables;
+----------------+
| Tables_in_mail |
+----------------+
| aliases |
| transport |
| virtual_users |
+----------------+
mysql> desc aliases;
+-------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+--------------+------+-----+---------+-------+
| alias | varchar(255) | | PRI | | |
| rcpt | varchar(255) | YES | | NULL | |
+-------+--------------+------+-----+---------+-------+
mysql> insert aliases values('postmaster@test.com','webmaster@test.com');

mysql> select * from aliases;
+--------------------------+--------------------+
| alias | rcpt |
+--------------------------+--------------------+
| postmaster@test.com | webmaster@test.com |
+--------------------------+--------------------+
mysql> desc transport;
+-----------+-----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------+-----------+------+-----+---------+-------+
| domain | char(128) | | PRI | | |
| transport | char(128) | | | | |
+-----------+-----------+------+-----+---------+-------+
mysql> insert transport values('test.com','virtual:');
mysql> select * from transport;

+---------------+-----------+
| domain | transport |
+---------------+-----------+
| test.com | virtual: |
+---------------+-----------+
mysql> desc virtual_users;
+-----------+---------------------+------+-----+----------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-----------+---------------------+------+-----+----------+----------------+
| unique_id | int(32) unsigned | | MUL | NULL | auto_increment |
| id | char(128) | | PRI | | |
| password | char(128) | YES | | NULL | |
| uid | int(10) unsigned | YES | | 104 | |
| gid | int(10) unsigned | YES | | 104 | |
| home | char(255) | YES | | NULL | |
| maildir | char(255) | YES | | NULL | |
| date_add | date | YES | | NULL | |
| time_add | time | YES | | NULL | |
| domain | char(128) | YES | | NULL | |
| name | char(255) | YES | | NULL | |
| imapok | tinyint(3) unsigned | YES | | 1 | |
| quota | char(255) | YES | | 10485760 | |
+-----------+---------------------+------+-----+----------+----------------+
mysql> INSERT INTO virtual_users
mysql> (id,home,password,maildir,date_add,time_add,domain,name)
mysql> VALUES ('webmaster@test.com','/var/mail/',encrypt('admin123'),

mysql> 'test.com/webmaster/Maildir/','2004-08-08','16:28:24','test.com','webmaster');
mysql> quit

设置用户的目录与权限:
mail# mkdir -p /var/mail/test.com/webmaster
mail# /usr/local/bin/maildirmake /var/mail/test.com/webmaster/Maildir

mail# chmod -R 777 /var/mail/test.com/
mail# chown -R postfix:postfix /var/mail/test.com

至此用户设置完毕,这里只使用一个域名,同理可以设置多个域名。
________________________________________
3.2 用户登录测试
用户登录测试
安装p5-MIME-Base64
mail# cd /usr/ports/converters/p5-MIME-Base64/

mail# make install clean

通过p5-MIME-Base64来取得用户名和密码的base64编码
mail# perl -MMIME::Base64 -e 'print encode_base64("webmaster\@test.com");'
d2VibWFzdGVyQG1za2Uub3Jn
mail# perl -MMIME::Base64 -e 'print encode_base64("admin123");'
bHUwOTIx

发送邮件:
mail# telnet 127.0.0.1 25

Trying 127.0.0.1...
Connected to 0.
Escape character is '^]'.
220 mail.test.com ESMTP Postfix
ehlo mail
250-mail.test.com
250-PIPELINING
250-SIZE 4194304
250-VRFY
250-ETRN
250-AUTH NTLM LOGIN PLAIN OTP
250-AUTH=NTLM LOGIN PLAIN OTP
250 8BITMIME
auth login
334 VXNlcm5hbWU6
d2VibWFzdGVyQG1za2Uub3Jn //此为用户名id:webmaster@test.com
334 UGFzc3dvcmQ6
bHUwOTIx //此为用户密码password:admin123
235 Authentication successful
MAIL FROM:webmaster@test.com //告诉服务器发件人的Email地址
250 Ok
RCPT TO:webmaster@test.com //告诉服务器收件人的地址
250 OK

DATA //告诉服务器开始写信
354 End data with <CR><LF>.<CR><LF>
SUBJECT:test //subject后面填写的是邮件的主题
test
. //换行后输入.后按回车,表示信件内容书写完毕
250 Ok: queued as 58DC71D5

quit //发送信件,结束对话,退出SMTP服务器
221 Bye
Connection closed by foreign host

收取邮件:
mail# telnet 127.0.0.1 110
Trying 127.0.0.1...
Connected to 0
Escape character is '^]'
+OK Hello there
user webmaster@test.com
+OK Password required
pass admin123
+OK logged in
list

+OK POP3 clients that break here, they violate STD53
1 2217
.
retr 1 //返回第一封信的全部内容
+OK 2217 octets follow.
Return-Path: <webmaster@test.com>
X-Original-To: webmaster@test.com
Delivered-To: webmaster@test.com
Received: from mail (localhost.test.com [127.0.0.1])
by mail.test.com (Postfix) with ESMTP id 58DC71D5
for <webmaster@test.com>; Mon, 9 Aug 2004 21:11:20 +0800 (CST)
SUBJECT:test
Message-Id: <20040809131120.58DC71D5@mail.test.com>
Date: Mon, 9 Aug 2004 21:11:20 +0800 (CST)
From: webmaster@test.com
To: undisclosed-recipients:;

test
.
dele 1 //删除
+OK Deleted
quit

+OK Bye-bye
Connection closed by foreign host

也可以使用任何其它的邮件客户端程序来测试,如foxmail、Outlook Express等等。
________________________________________
3.3 建立其他用户
建立其他用户
mysql> INSERT INTO virtual_users
mysql> (id,home,password,maildir,date_add,time_add,domain,name,nickname,realname,office)
mysql> VALUES ('test@test.com','/var/mail/',encrypt('abc321'),
mysql> 'test.com/test/Maildir/','2004-08-09','22:49:24','test.com','test',);

mysql> '昵称','真实姓名','单位');
mysql> quit

设置用户的目录与权限:
mail# mkdir -p /var/mail/test.com/test
mail# /usr/local/bin/maildirmake /var/mail/test.com/test/Maildir

mail# chmod -R 700 /var/mail/test.com/
mail# chown -R postfix:postfix /var/mail/test.com

________________________________________
Chapter 4. 防病毒与防垃圾邮件
本章介绍病毒与垃圾邮件的防范。
________________________________________
4.1 安装Clamav
mail# cd /usr/ports/security/clamav

mail# make install clean
注:MILTER不用选中

重启服务器
测试
mail# clamscan -r -i /usr/local/www/data
----------- SCAN SUMMARY -----------
Known viruses: 22838
Scanned directories: 1
Scanned files: 31
Infected files: 0
Data scanned: 0.00 MB
I/O buffer size: 131072 bytes
Time: 1.298 sec (0 m 1 s)

升级病毒库
mail# freshclam


________________________________________
4.2 安装amavisd-new
版本20040701。
mail# cd /usr/ports/security/amavisd-new
mail# make install clean

选中MySQL

编辑/etc/rc.conf,加入
amavisd_enable="YES"

修改/usr/local/etc/amavisd.conf
$mydomain = 'example.com';改成$mydomain = 'test.com';

#$notify_method = 'smtp:[127.0.0.1]:10025';
#$forward_method = 'smtp:[127.0.0.1]:10025';
的注释去掉

修改/usr/local/etc/postfix/master.cf,最后加入
smtp-amavis unix - - y - 2 smtp -o smtp_data_done_timeout=1200
127.0.0.1:10025 inet n - n - - smtpd
-o content_filter=
-o local_recipient_maps=
-o relay_recipient_maps=
-o smtpd_restriction_classes=
-o smtpd_client_restrictions=
-o smtpd_helo_restrictions=
-o smtpd_sender_restrictions=
-o smtpd_recipient_restrictions=permit_mynetworks,reject
-o mynetworks=127.0.0.0/8
-o strict_rfc821_envelopes=yes
-o smtpd_error_sleep_time=0
-o smtpd_soft_error_limit=1001
-o smtpd_hard_error_limit=1000

重启服务器
________________________________________
4.3 安装配置Spamassassin
在最新的AMaVisd-new已经结合了Spamassassin功能,所以只要用 ports安装了 AMaVisd-new,那Spamassassin 也已经安装好了。
添加需要的用户
mail# pw useradd spam -c "Spam Bayes Learner" -d /var/empty -s /sbin/nologin

mail# pw useradd notspam -c "Not Spam Bayes Learner" -d /var/empty -s /sbin/nologin

修改/usr/local/etc/mail/spamassassin/local.cf
use_bayes 1
bayes_path /var/amavis/.spamassassin/bayes
auto_learn 1
auto_learn_threshold_nonspam -2
auto_learn_threshold_spam 15

修改/usr/local/etc/amavisd.conf,在MUST BE SET (no useful default)一段下面增加
$max_requests = 10;
$child_timeout=5*60;

@bypass_virus_checks_acl = qw( . );
@local_domains_acl = ( ".$mydomain" );

$final_spam_destiny = D_PASS;

read_hash(\%whitelist_sender, '/var/amavis/whitelist');
read_hash(\%blacklist_sender, '/var/amavis/blacklist');
read_hash(\%spam_lovers, '/var/amavis/spam_lovers');

建立所需要的文件
mail# touch /var/amavis/whitelist
mail# touch /var/amavis/blacklist

mail# touch /var/amavis/spam_lovers
mail# chown vscan /var/amavis/whitelist
mail# chown vscan /var/amavis/blacklist
mail# chown vscan /var/amavis/spam_lovers
mail# echo spam@test.com >> /var/amavis/spam_lovers

mail# echo notspam@test.com >> /var/amavis/spam_lovers

修改/usr/local/etc/postfix/main.cf,添加
content_filter = smtp-amavis:[127.0.0.1]:10024

建立自动学习体系
mail# vi /usr/local/sbin/my-sa-learn.sh

#!/bin/sh
if [ -e /var/mail/spam ]; then
/usr/local/bin/sa-learn --spam -p /var/amavis/.spamassassin/user_prefs
--mbox /var/mail/spam
注:以上两行为一行
rm /var/mail/spam > /dev/null
fi

if [ -e /var/mail/notspam ]; then
/usr/local/bin/sa-learn --ham -p /var/amavis/.spamassassin/user_prefs
--mbox /var/mail/notspam
注:以上两行为一行
rm /va/mail/notspam > /dev/null
fi

mail# chmod a+x /usr/local/sbin/my-sa-learn.sh


建立学习知识库:
mail# /usr/local/bin/sa-learn --rebuild -p /var/amavis/.spamassassin/user_prefs

加入自动运行:
mail# crontab -e

5 0 * * * /usr/local/sbin/my-sa-learn.sh

重启服务器
测试
mail# su - vscan

mail# /usr/local/sbin/amavisd debug

启动另一个终端:
mail# telnet 127.0.0.1 10024
Trying 127.0.0.1...
Connected to localhost.test.com.
Escape character is '^]'.
220 [127.0.0.1] ESMTP amavisd-new service ready
MAIL FROM:<webmaster@test.com>
250 2.1.0 Sender webmaster@test.com OK
RCPT TO:<webmaster@test.com>

250 2.1.5 Recipient webmaster@test.com OK
DATA
354 End data with <CR><LF>.<CR><LF>
Subject: test

X5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*
.

250 2.7.1 Ok, discarded, id=00228-01 - VIRUS: Eicar-Test-Signature
//出现这一行表示系统已经认出这个邮件中含有 Virus
quit

________________________________________
Chapter 5. 安装webmail
webmail使用igenus,版本是2004.7.13。
下载igenus到/var/mail目录后解压
安装autorespond,版本是2.53_3。
mail# cd /usr/ports/mail/autorespond
mail# make install clean


修改/usr/local/etc/apache/httpd.conf
Group nobody、User nobody修改为: Group postfix、User postfix
DocumentRoot "/usr/local/apache/htdocs"修改为:DocumentRoot "/var/mail/webmail"
<Directory "/usr/local/www/data">修改成<Directory "/var/mail/igenus">

mail# cd /usr/local/www
mail# chown -R postfix:postfix phpMyAdmin

mail# cd /usr/local/etc
mail# cp php.ini-dist php.ini

修改/usr/local/etc/php.ini
register_globals = On
max_execution_time = 30 //改为60 (增加处理脚本的时间限制)
memory_limit = 8M //改为40M (这样才能发10M的附件)
post_max_size = 8M //改为10M
upload_max_filesize = 2M //改为10M

重启apache
mail# /usr/local/etc/rc.d/apache.sh restart

在mail数据库下增加的表
# phpMyAdmin SQL Dump
# version 2.5.3
# http://www.phpmyadmin.net
#
# Host: localhost
# Generation Time: Jun 04, 2004 at 11:26 AM
# Server version: 3.23.55
# PHP Version: 4.3.0
#
# Database : `vpopmail`
#

# --------------------------------------------------------

#
# Table structure for table `address`
#

CREATE TABLE `address` (
`id` int(11) unsigned NOT NULL auto_increment,
`pw_id` int(5) NOT NULL default '0',
`name` varchar(64) NOT NULL default '',
`email` varchar(128) NOT NULL default '',
UNIQUE KEY `id` (`id`),
KEY `pw_id` (`pw_id`)
) TYPE=MyISAM PACK_KEYS=1 ;

# --------------------------------------------------------

#
# Table structure for table `admin`
#

CREATE TABLE `admin` (
`id` int(10) unsigned NOT NULL auto_increment,
`site_id` int(10) unsigned NOT NULL default '0',
`domain` varchar(128) NOT NULL default '',
`quota` smallint(5) unsigned NOT NULL default '0',
`total` smallint(5) unsigned NOT NULL default '0',
`createtime` timestamp(14) NOT NULL,
`login` char(1) NOT NULL default '',
`cur_total` smallint(5) NOT NULL default '0',
`cur_quota` smallint(5) NOT NULL default '0',
`gid` varchar(11) NOT NULL default '',
`expiration_time` timestamp(14) NOT NULL,
`flag` int(10) unsigned NOT NULL default '0',
`maxmsg` int(10) unsigned NOT NULL default '0',
PRIMARY KEY (`id`),
UNIQUE KEY `domain` (`domain`)
) TYPE=MyISAM PACK_KEYS=1 ;

# --------------------------------------------------------

#
# Table structure for table `card`
#

CREATE TABLE `card` (
`id` int(5) unsigned NOT NULL auto_increment,
`pw_id` int(5) unsigned NOT NULL default '0',
`LinkMan` varchar(64) NOT NULL default '',
`CompanyName` varchar(100) NOT NULL default '',
`Address` varchar(255) NOT NULL default '',
`Position` varchar(32) NOT NULL default '',
`PhoneNumber` varchar(16) NOT NULL default '',
`Mobile` varchar(12) NOT NULL default '',
`Email` varchar(128) NOT NULL default '',
`Partaker` varchar(32) NOT NULL default '',
`Memo` varchar(255) NOT NULL default '',
PRIMARY KEY (`id`)
) TYPE=MyISAM ;

# --------------------------------------------------------

#
# Table structure for table `lastauth`
#

CREATE TABLE `lastauth` (
`user` char(32) NOT NULL default '',
`domain` char(64) NOT NULL default '',
`remote_ip` char(1 NOT NULL default '',
`timestamp` bigint(20) NOT NULL default '0',
PRIMARY KEY (`user`,`domain`)
) TYPE=MyISAM;

# --------------------------------------------------------

#
# Table structure for table `logs`
#

CREATE TABLE `logs` (
`pw_id` int(5) default '0',
`ip` varchar(15) NOT NULL default '',
`action` varchar(15) NOT NULL default '',
`time` datetime default NULL,
`content` varchar(64) NOT NULL default '',
`email` varchar(128) NOT NULL default ''
) TYPE=MyISAM;

# --------------------------------------------------------

#
# Table structure for table `message`
#

CREATE TABLE `message` (
`id` int(5) unsigned NOT NULL auto_increment,
`title` varchar(255) NOT NULL default '',
`body` text NOT NULL,
`createtime` datetime NOT NULL default '0000-00-00 00:00:00',
`updatetime` datetime NOT NULL default '0000-00-00 00:00:00',
`pw_domain` varchar(64) NOT NULL default '',
UNIQUE KEY `id` (`id`)
) TYPE=MyISAM ;

# --------------------------------------------------------

#
# Table structure for table `personal`
#
//原来的monthe,day为大写,改成小写
CREATE TABLE `personal` (
`id` int(11) unsigned NOT NULL auto_increment,
`pw_id` int(5) NOT NULL default '0',
`truename` varchar(10) NOT NULL default '',
`fax` varchar(20) NOT NULL default '',
`telephone` varchar(15) NOT NULL default '',
`sex` int(1) NOT NULL default '0',
`year` int(4) NOT NULL default '0',
`month` int(2) NOT NULL default '0',
`day` int(2) NOT NULL default '0',
`education` varchar(4) NOT NULL default '',
`marital` int(1) NOT NULL default '0',
`occupation` varchar(15) NOT NULL default '',
`companyname` varchar(30) NOT NULL default '',
`province` varchar(6) NOT NULL default '',
PRIMARY KEY (`id`)
) TYPE=MyISAM PACK_KEYS=1 ;

# --------------------------------------------------------

#
# Table structure for table `scheduler`
#

CREATE TABLE `scheduler` (
`id` int(11) unsigned NOT NULL auto_increment,
`begin_time` int(11) unsigned default NULL,
`end_time` int(11) unsigned default NULL,
`title` varchar(255) NOT NULL default '',
`body` varchar(255) NOT NULL default '',
`pw_id` int(11) unsigned NOT NULL default '0',
PRIMARY KEY (`id`)
) TYPE=MyISAM ;

# --------------------------------------------------------

#
# Table structure for table `stow`
#

CREATE TABLE `stow` (
`id` int(5) unsigned NOT NULL auto_increment,
`pw_id` int(5) unsigned NOT NULL default '0',
`Name` varchar(128) NOT NULL default '',
`http` varchar(255) NOT NULL default 'http://',
`memo` varchar(255) NOT NULL default '',
PRIMARY KEY (`id`)
) TYPE=MyISAM ;

# --------------------------------------------------------

#
# Table structure for table `vpopmail`
#

CREATE TABLE `vpopmail` (
`pw_id` int(5) unsigned NOT NULL auto_increment,
`pw_name` varchar(32) NOT NULL default '',
`pw_domain` varchar(64) NOT NULL default '',
`pw_passwd` varchar(40) NOT NULL default '',
`pw_uid` int(11) default NULL,
`pw_gid` int(11) default NULL,
`pw_gecos` varchar(4 default NULL,
`pw_dir` varchar(255) default NULL,
`pw_shell` varchar(20) default NULL,
`createtime` timestamp(14) NOT NULL,
PRIMARY KEY (`pw_id`),
KEY `pw_name` (`pw_name`,`pw_domain`)
) TYPE=MyISAM PACK_KEYS=1 ;

修改config/config_inc.php
$CFG_BASEPATH = "/var/mail/igenus";
$CFG_MYSQL_HOST = 'localhost';
$CFG_MYSQL_USER = 'postfix';
$CFG_MYSQL_PASS = 'admin123';
$CFG_MYSQL_DB = 'mail';
$CFG_NETDISK_PATH = "/var/mail/igenus/netdisk";

$CFG_TEMP = $CFG_BASEPATH."/../../temp";
改成:
$CFG_TEMP = $CFG_BASEPATH."/temp";

修改include/login_inc.php
if ( !isset($_SESSION['G_USERNAME']) || $SG_USERNAME == "" ||
!isset($_SESSION['G_DOMAIN']) || $SG_DOMAIN == "" ||
!isset($_SESSION['G_HOME']) || $SG_HOME == "" ||
!isset($_SESSION['G_TIME']) || $SG_TIME == "" ||
!isset($_SESSION['G_NICKNAME']) || $SG_NICKNAME == ""
){
header("Location: login.php");
exit();
}
改成:
if ( !isset($_SESSION['G_USERNAME']) || $SG_USERNAME == "" ||
!isset($_SESSION['G_DOMAIN']) || $SG_DOMAIN == "" ||
!isset($_SESSION['G_HOME']) || $SG_HOME == "" ||
!isset($_SESSION['G_TIME']) || $SG_TIME == ""
// !isset($_SESSION['G_NICKNAME']) || $SG_NICKNAME == ""
){
header("Location: login.php");
exit();
}

修改login.php
if ($CFG_VPOPMAIL_MYSQL_LARGE_SITE){
$Vpopmail_Domain = ereg_replace("\.","_",$Post_domain);
$query = "SELECT * FROM $Vpopmail_Domain WHERE pw_name='$Post_name'";
}else{
$query = "SELECT * FROM vpopmail WHERE pw_name='$Post_name' and
pw_domain='$Post_domain'";
}
改成:
if ($CFG_VPOPMAIL_MYSQL_LARGE_SITE){
$Vpopmail_Domain = ereg_replace("\.","_",$Post_domain);
$query = "SELECT * FROM $Vpopmail_Domain WHERE pw_name='$Post_name'";
}else{
$query = "SELECT * FROM virtual_users WHERE name='$Post_name' and
domain='$Post_domain'";
}

$data = mysql_fetch_array($result);
$home = $data['pw_dir'];
$Post_passwd2 = $data['pw_passwd'];
$pw_id = $data['pw_id'];
$pw_shell = $data['pw_shell'];
$pw_gecos = $data['pw_gecos'];
$pw_gid = $data['pw_gid'];
$pw_domain = strtolower($data['pw_domain']);
$pw_name = strtolower($data['pw_name']);
改成:
$data = mysql_fetch_array($result);
$home1 = $data['home'];
$home2 = $data['maildir'];
$home = $home1.$home2;
$Post_passwd2 = $data['PASSWORD'];
$pw_id = $data['unique_id'];
$pw_shell = $data['quota'];
$pw_gecos = $data['nickname'];
$pw_domain = strtolower($data['domain']);
$pw_name = strtolower($data['name']);

修改inclue/mailbox_inc.php
$sizefile = "$SG_HOME/Maildir/maildirsize";
全部改成:
$sizefile = "$SG_HOME/maildirsize";

if(!is_dir("$SG_HOME/Maildir/$Mailbox")){
mkdir("$SG_HOME/Maildir/$Mailbox",0700);
mkdir("$SG_HOME/Maildir/$Mailbox/new",0700);
mkdir("$SG_HOME/Maildir/$Mailbox/cur",0700);
mkdir("$SG_HOME/Maildir/$Mailbox/tmp",0700);
}
改成:
if(!is_dir("$SG_HOME/$Mailbox")){
mkdir("$SG_HOME/$Mailbox",0700);
mkdir("$SG_HOME/$Mailbox/new",0700);
mkdir("$SG_HOME/$Mailbox/cur",0700);
mkdir("$SG_HOME/$Mailbox/tmp",0700);
}

$home = $SG_HOME . "/Maildir/".$Mailbox."/new";
改成:
$home = $SG_HOME . $Mailbox."/new";

$home = $SG_HOME . "/Maildir/".$Mailbox."/cur";
改成:
$home = $SG_HOME . $Mailbox."/cur";

修改sendmail.php
$Path = "$SG_HOME/Maildir/".$CFG_MAILBOX['outbox']."/new/" . $Path;
改成:
$Path = "$SG_HOME/".$CFG_MAILBOX['outbox']."/new/" . $Path;

$Path = "$SG_HOME/Maildir/".$CFG_MAILBOX['draft']."/new/" . $Path;
改成:
$Path = "$SG_HOME/".$CFG_MAILBOX['draft']."/new/" . $Path;

修改list.php
if(!is_dir("$SG_HOME/Maildir/$mailbox")){
mkdir("$SG_HOME/Maildir/$mailbox",0700);
mkdir("$SG_HOME/Maildir/$mailbox/new",0700);
mkdir("$SG_HOME/Maildir/$mailbox/cur",0700);
mkdir("$SG_HOME/Maildir/$mailbox/tmp",0700);
}
改成:
if(!is_dir("$SG_HOME/$mailbox")){
mkdir("$SG_HOME/$mailbox",0700);
mkdir("$SG_HOME/$mailbox/new",0700);
mkdir("$SG_HOME/$mailbox/cur",0700);
mkdir("$SG_HOME/$mailbox/tmp",0700);
}

$myhome = "$SG_HOME/Maildir/$mailbox/$home";
改成:
$myhome = "$SG_HOME/$mailbox/$home";

修改folder.php
$mailfile = "$SG_HOME/Maildir/$SMailbox/$IsNew/$File";
改成:
$mailfile = "$SG_HOME/$SMailbox/$IsNew/$File";

$home = $SG_HOME . "/Maildir/".$SMailbox."/cur";
改成:
home = $SG_HOME .$SMailbox."/cur";

$mailfile = "$SG_HOME/Maildir/$SMailbox/cur/$file";
改成:
$mailfile = "$SG_HOME/$SMailbox/cur/$file";

link($mailfile, "$SG_HOME/Maildir/$DMoveTo/$IsNew/$cur_file");
改成:
link($mailfile, "$SG_HOME/$DMoveTo/$IsNew/$cur_file");

修改prev.php
$mailfile = "$SG_HOME/Maildir/$SMailbox/$IsNew/$File";
改成:
$mailfile = "$SG_HOME/$SMailbox/$IsNew/$File";

$home = $SG_HOME . "/Maildir/".$SMailbox."/cur";
改成:
$home = $SG_HOME .$SMailbox."/cur";

$mailfile = "$SG_HOME/Maildir/$SMailbox/cur/$file";
改成:
$mailfile = "$SG_HOME/$SMailbox/cur/$file";

if(file_exists("$SG_HOME/Maildir/$SMailbox/new/$File")) {
@link("$SG_HOME/Maildir/$SMailbox/new/$File",
"$SG_HOME/Maildir/$SMailbox/cur/$File:2,S");
@unlink("$SG_HOME/Maildir/$SMailbox/new/$File");
}
改成:
if(file_exists("$SG_HOME/$SMailbox/new/$File")) {
@link("$SG_HOME/$SMailbox/new/$File",
"$SG_HOME/$SMailbox/cur/$File:2,S");
@unlink("$SG_HOME/$SMailbox/new/$File");
}

$home = $SG_HOME . "/Maildir/".$SMailbox."/cur";
改成:
$home = $SG_HOME .$SMailbox."/cur";

if($isread==0)
{
@link("$SG_HOME/Maildir/$SMailbox/cur/$file",
"$SG_HOME/Maildir/$SMailbox/cur/$file"."S");
@unlink("$SG_HOME/Maildir/$SMailbox/cur/$file");
}
改成:
if($isread==0)
{
@link("$SG_HOME/$SMailbox/cur/$file",
"$SG_HOME/$SMailbox/cur/$file"."S");
@unlink("$SG_HOME/$SMailbox/cur/$file");
}

修改passwd.php
$query = "SELECT pw_name,pw_passwd FROM vpopmail WHERE pw_id='$SG_ID'";
改成:
$query = "SELECT name,PASSWORD FROM virtual_users WHERE unique_id='$SG_ID'";

if( $row->pw_passwd!=crypt($post_OldPasswd,$row->pw_passwd) ) {
改成:
if( $row->ASSWORD!=crypt($post_OldPasswd,$row->ASSWORD) ) {

$query = "UPDATE vpopmail SET pw_passwd='$NewPasswd' WHERE pw_id='$SG_ID'";
改成:
$query = "UPDATE virtual_users SET PASSWORD='$NewPasswd' WHERE unique_id='$SG_ID'";

修改read.php
if(!file_exists($mailfile))
{
$home = $SG_HOME . "/Maildir/".$SMailbox."/cur";
$handle=opendir($home);

while (($filename = readdir($handle))!==false)
{
if (substr_count($filename, $file)==1)
{
$mailfile = "$SG_HOME/Maildir/$SMailbox/cur/$filename";
}
}
closedir($handle);
}
改成:
if(!file_exists($mailfile))
{
$home = $SG_HOME .$SMailbox."/cur";
$handle=opendir($home);

while (($filename = readdir($handle))!==false)
{
if (substr_count($filename, $file)==1)
{
$mailfile = "$SG_HOME/Maildir/$SMailbox/cur/$filename";
}
}
closedir($handle);
}

$mailfile = "$SG_HOME/Maildir/$SMailbox/$isnew/$file";
改成:
$mailfile = "$SG_HOME/$SMailbox/$isnew/$file";

$mailfile = "$SG_HOME/Maildir/$SMailbox/cur/$filename";
改成:
$mailfile = "$SG_HOME/$SMailbox/cur/$filename";

修改forward.php
$mailfile = "$SG_HOME/Maildir/$SMailbox/$IsNew/$File";
if(!file_exists($mailfile)) $mailfile = "$SG_HOME/Maildir/$SMailbox/cur/$Files";
改成:
$mailfile = "$SG_HOME/$SMailbox/$IsNew/$File";
if(!file_exists($mailfile)) $mailfile = "$SG_HOME/$SMailbox/cur/$Files";

其它小方面的修改,把不能实现的功能和我自己觉得没用的功能屏蔽掉。
修改template\_menu.php把邮件过滤、转发、自动回复屏蔽掉。
<!--<TR>

<TD><IMG SRC="images/folder/vertline.gif" WIDTH="16" HEIGHT="22">
<IMG SRC="images/folder/node.gif" WIDTH="16" HEIGHT="22">
<IMG SRC="images/folder/antispam.gif" WIDTH="22" HEIGHT="21">
</TD>
<TD><A HREF="javascript:OpenWin('filter.php')">
<?php echo $LANG_MENU_SETUP_FILTER;?></A></TD>
</TR>-->

<!--<TR>
<TD><IMG SRC="images/folder/vertline.gif" WIDTH="16" HEIGHT="22">
<IMG SRC="images/folder/node.gif" WIDTH="16" HEIGHT="22">
<IMG SRC="images/folder/forward.gif" WIDTH="22" HEIGHT="21">
</TD>
<TD><A HREF="javascript:OpenWin('forwarders.php')">
<?php echo $LANG_MENU_SETUP_FORWARD;?></A></TD>

</TR>-->
<!--<TR>
<TD><IMG SRC="images/folder/vertline.gif" WIDTH="16" HEIGHT="22">
<IMG SRC="images/folder/node.gif" WIDTH="16" HEIGHT="22">
<IMG SRC="images/folder/autorespond.gif" WIDTH="22" HEIGHT="21">
</TD>
<TD><A HREF="javascript:OpenWin('autorespond.php')">

<?php echo $LANG_MENU_SETUP_AUTORESPOND;?></A></TD>
</TR>-->

屏蔽掉内部通知、日程安排、帮助。
<!--<TR>
<TD> <TABLE WIDTH="100%" BORDER="0" CELLSPACING="0" CELLPADDING="0">
<TR>

<TD WIDTH="38">
<IMG SRC="images/folder/node.gif" WIDTH="16" HEIGHT="22">
<IMG SRC="images/folder/message.gif" WIDTH="22" HEIGHT="21"></TD>
<TD><A HREF=message.php TARGET="main">
<?php echo $LANG_MENU_MESSAGE;?></A></TD>
</TR>
</TABLE></TD>

</TR>
<TR>
<TD> <TABLE WIDTH="100%" BORDER="0" CELLSPACING="0" CELLPADDING="0">
<TR>
<TD WIDTH="38">
<IMG SRC="images/folder/node.gif" WIDTH="16" HEIGHT="22">
<IMG SRC="images/folder/scheduler.gif" WIDTH="22" HEIGHT="21"></TD>

<TD><A HREF=scheduler.php TARGET="main">
<?php echo $LANG_MENU_SCHEDULE;?></A></TD>
</TR>
</TABLE></TD>
</TR>
<TR>
<TD> <TABLE WIDTH="100%" BORDER="0" CELLSPACING="0" CELLPADDING="0">

<TR>
<TD WIDTH="38">
<IMG SRC="images/folder/node.gif" WIDTH="16" HEIGHT="22">
<IMG SRC="images/folder/help.gif" WIDTH="22" HEIGHT="21"></TD>
<TD><A HREF="#">
<?php echo $LANG_MENU_HELP;?></A></TD>
</TR>

</TABLE></TD>
</TR>-->

修改template\_mailbox.php把日程安排和内部通知屏蔽掉。
<!--<td width="46%" valign="top">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="right"><strong>

<?php echo $LANG_MAILBOX_HELO?>,</strong><U>
<?php echo $OUT['NICKNAME']?></U><strong>
<?php echo $LANG_MAILBOX_TODAY_IS?>: </strong><u>
<?php echo $OUT['today']?></u>

<u><?php echo $LANG_WEEKDAY.$OUT['weekday']?></u>
</td>
</tr>
</table>
<TABLE BORDER="1" CELLSPACING="0" CELLPADDING="1" BGcolor="#EAF3E9"
BORDERcolor="#FFFFFF" WIDTH="100%" ALIGN="CENTER">
<TR BGcolor="#FFFFFF">
<TD HEIGHT="22" colspan="2"><img src=images/dot-2.gif>

<strong><?php echo $LANG_MAILBOX_TODAY_SCHEDULER?></strong>
</TD>
</TR>
<TR>
<TD HEIGHT="22" align="CENTER" bgcolor="#D0E6CE"><B>
<?php echo $LANG_MAILBOX_DATETIME?></B></TD>

<TD align="CENTER" bgcolor="#D0E6CE"><B>
<?php echo $LANG_MAILBOX_SUBJ?></B></TD>
</TR>
<?php echo $OUT['scheduler']?>
<TR >
<td height="20" colspan="2"align="right" bgcolor="#FFFFFF">
<a href="scheduler.php"><?php echo $LANG_MAILBOX_MORE?>

>>></a>
</td>
</TR>
</TABLE>
<TABLE BORDER="1" CELLSPACING="0" CELLPADDING="1" BGcolor="#EAF3E9"
BORDERcolor="#FFFFFF" WIDTH="100%" ALIGN="CENTER">
<TR BGcolor="#FFFFFF">
<TD HEIGHT="22" colspan="3"> <p><img src=images/dot-2.gif>

<strong><?php echo $LANG_MAILBOX_NOTICE?></strong></p>
</TD>
</TR>
<TR>
<TD HEIGHT="22" align="CENTER" bgcolor="#D0E6CE"> <B>
<?php echo $LNAG_LIST_NUM?></B> </TD>

<TD align="CENTER" bgcolor="#D0E6CE"><B>
<?php echo $LANG_MAILBOX_SUBJ?></B> </TD>
<TD align="CENTER" bgcolor="#D0E6CE"><B>
<?php echo $LANG_MAILBOX_DATETIME?></B></TD>
</TR>

<?php echo $ListOut;?>
<TR >
<td height="20" colspan="3"align="right" bgcolor="#FFFFFF">
<a href="message.php"><?php echo $LANG_MAILBOX_MORE?>
>>></a>
</td>
</TR>
</TABLE>

</td>-->
<td width="10"> </td>
<td valign="top"><TABLE WIDTH="100%" BORDER="0" ALIGN="CENTER">
<tr>
<td align="right"><strong>
<?php echo $LANG_MAILBOX_HELO?>,</strong><U>

<?php echo $OUT['N
ICKNAME']?></U><strong>
<?php echo $LANG_MAILBOX_TODAY_IS?>: </strong><u>
<?php echo $OUT['today']?></u>
<u><?php echo $LANG_WEEKDAY.$OUT['weekday']?>

</u></td>
</tr>
<TR>

修改template\_login.php如title、Copyright以适合自己情况。
修改language\gb_inc.php里的$LANG_LOGIN_WELCOME。
修改config\config_inc.php里的iGENUS is a free webmail interface等。
________________________________________
Chapter 6. 邮件服务器的管理
6.1 配置apache
配置apache
mail# mkdir /var/mail/admin_mail

mail# cd /var/mail/admin_mail
mail# vi .htaccess

内容如下:
authname "Email Admin"
authtype basic
authuserfile /etc/htpasswd
require user admin

修改/usr/local/etc/apache/httpd.conf,增加以下内容
Listen 80
Listen 2888

NameVirtualHost *:2888
<VirtualHost *:2888>
DocumentRoot /var/mail/admin_mail
<Directory "/var/mail/admin_mail">

options indexes followsymlinks
allowoverride authconfig
order allow,deny
allow from all
</Directory>
ServerAdmin webmaster@test.com
ErrorLog /var/log/admin_mail-error.log
CustomLog /var/log/admin_mail-access.log common
</VirtualHost>

________________________________________
6.2 管理程序源代码
________________________________________
6.3 配置文件config.inc.php
配置文件config.inc.php
<?php

//MySQL
$CFG_MYSQL_HOST = 'localhost';
$CFG_MYSQL_USER = 'postfix';
$CFG_MYSQL_PASS = 'admin123';
$CFG_MYSQL_DB = 'mail';

//Language
$CFG_LANG = gb; //gb - Chinese GB
//en - English

//footer
function showFooter(){
echo "<hr size=\"1\">\n";
echo "<DIV style=\"FONT-SIZE: 11px\" align=\"left\">\n";
echo "Copyright 2001 - 2004 <b>

<a href=\"http://mske.com\" target=\"_blank\">Mske.com</a>
</B> All Rights Reserved.<BR>Email:webmaster at mske dot com\n";
echo "</DIV>\n";
}

?>

________________________________________
6.4 增加域名
增加域名,adddomain1.php
<?php

require("config.inc.php");
require("lang/$CFG_LANG"."_inc.php");

?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=<?php echo $CFG_CHARSET; ?>">
<title><?php echo $LANG_TITLE; ?></title>
</head>

<body>
<?php
$conn=mysql_connect($CFG_MYSQL_HOST,$CFG_MYSQL_USER,$CFG_MYSQL_PASS);
mysql_select_db($CFG_MYSQL_DB, $conn);

if (eregi("([0-9a-z][0-9a-z-]+\.)+[a-z]{2,3}$",$add_domain_name)) {

$sql = "select * from transport where domain='$add_domain_name'";
$query = mysql_query($sql, $conn);
$rows = mysql_num_rows($query);
if($rows==1){
echo "$LANG_DOMAIN_EXIST";
exit;
}

$sql ="insert into transport (domain,transport) values
('$add_domain_name','virtual:')";
$query = mysql_query($sql, $conn);

$dir1 = "/var/mail/" . $add_domain_name;

system("mkdir -p $dir1");

echo "$LANG_DOMAIN_SUCCEED";
}else{
echo "$LANG_DOMAIN_ERROR";
}
showFooter();
mysql_close($conn);
?>
</body>
</html>

________________________________________
6.5 增加用户
增加用户,adduser1.php和adduser2.php。
########adduser1.php#############
<?php
require("config.inc.php");
require("lang/$CFG_LANG"."_inc.php");
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>

<head>
<meta http-equiv="Content-Type" content="text/html;
charset=<?php echo $CFG_CHARSET; ?>">
<title><?php echo $LANG_TITLE; ?></title>
</head>

<body>
<?php
if (eregi("^[_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,3}$",$add_user_name)) {
?>

<div align="left">
<form action="adduser2.php" method="post">
<table cellspacing="2" cellpadding="2" border="0" width="664">
<tr>
<td bgcolor="#D0DCE0" width="10%"><?php echo $LANG_USER_MAILBOX ?> :</td>
<td bgcolor="#DDDDDD" width="90%"><?php echo $add_user_name ?></td>

</tr>
<tr>
<td bgcolor="#D0DCE0" width="10%"><?php echo $LANG_USER_PASSWD ?> :</td>
<td bgcolor="#DDDDDD" width="90%"><input type="text" name="add_password"
size="20" maxlength="128"></td>
</tr>

<tr>
<td bgcolor="#D0DCE0" width="10%"><?php echo $LANG_USER_NAME ?> :</td>
<td bgcolor="#DDDDDD" width="90%"><input type="text" name="add_realname"
size="10" maxlength="10"></td>
</tr>
<tr>

<td bgcolor="#D0DCE0" width="10%"><?php echo $LANG_USER_OFFICE ?> :</td>
<td bgcolor="#DDDDDD" width="90%"><input type="text" name="add_office"
size="20" maxlength="20"></td>
</tr>
<tr>
<td bgcolor="#D0DCE0" width="10%"><?php echo $LANG_USER_QUOTA ?> :</td>

<td bgcolor="#DDDDDD" width="90%"><input type="text" name="add_quota"
value="20971520" size="10" maxlength="255"></td>
</tr>
<tr>
<td colspan="2"><input type="submit" name="submit"
value="<?php echo $LANG_USER_ADDSUBMIT ?>"></td>
</tr>

</table>
<input type="hidden" name="add_user_name" value="<?php echo $add_user_name ?>">
</form>
</div>

<?php
}else{
echo "$LANG_USER_ERROR";
}
showFooter();
?>
</body>
</html>


########adduser2.php#############
<?php
require("config.inc.php");
require("lang/$CFG_LANG"."_inc.php");
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=<?php echo $CFG_CHARSET; ?>">
<title><?php echo $LANG_TITLE; ?></title>

</head>

<body>
<?php
$conn=mysql_connect($CFG_MYSQL_HOST,$CFG_MYSQL_USER,$CFG_MYSQL_PASS);
mysql_select_db($CFG_MYSQL_DB, $conn);

$id=$add_user_name;
$PASSWORD = crypt($add_password);
$domain = substr( strrchr( $add_user_name, "@" ), 1 );
$name = substr($add_user_name,0,(strlen($add_user_name)-strlen($domain)-1));
$date_add = date("Y-m-d");
$time_add = date("G-i-s");
$maildir = $domain . "/" . $name . "/Maildir/";

$sql = "select * from virtual_users where id='$id'";
$query = mysql_query($sql, $conn);
$rows = mysql_num_rows($query);
if($rows==1){
echo "$LANG_USER_EXIST";
exit;
}
$sql = "select * from transport where domain='$domain'";
$query = mysql_query($sql, $conn);
$rows = mysql_num_rows($query);
if($rows!==1){
echo "$LANG_USER_NODOMAIN";
exit;
}

$sql ="insert into virtual_users
(id,PASSWORD,uid,gid,home,maildir,date_add,time_add,domain,name,imapok,
quota,realname,office) values ('$id','$PASSWORD',125,125,'/var/mail/',
'$maildir','$date_add','$time_add','$domain','$name',1,'$add_quota',
'$add_realname','$add_office')";
$query = mysql_query($sql, $conn);

$dir1 = "/var/mail/" . $domain . "/" . $name;
$dir2 = $dir1 . "/Maildir";
system("mkdir -p $dir1");
system("/usr/local/bin/maildirmake $dir2");
system("chmod -R 700 $dir1");

echo "$LANG_USER_SUCCEED";

showFooter();
mysql_close($conn);
?>
</body>
</html>

________________________________________
6.6 查看系统状态
安装phpSysInfo(2.2)
mail# cd /usr/ports/www/phpSysInfo

mail# make install clean
mail# cd /usr/local/www/data-dist/phpSysInfo
mail# cp config.php.new config.php

修改/usr/local/etc/apache/httpd.conf,添加以下内容
Alias /phpSysInfo/ "/usr/local/www/data/phpSysInfo/"
<Directory "/usr/local/www/data/phpSysInfo">

Options Indexes FollowSymlinks MultiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory>
本人水平有限,错误之处在所难免,希望高手们给于指证(scyz2 at 163.com)。
回复 支持 反对

使用道具 举报

发表于 2005-1-28 08:47:12 | 显示全部楼层
好贴!!!!!!!暴力支持一下!
回复 支持 反对

使用道具 举报

发表于 2005-2-11 22:43:58 | 显示全部楼层
有没有在 FREEBSD 5.3下测试安装过 ?
回复 支持 反对

使用道具 举报

 楼主| 发表于 2005-2-16 16:57:28 | 显示全部楼层
你没有看平台呀!就是FB5.3的呀!呵呵
回复 支持 反对

使用道具 举报

发表于 2005-2-17 21:11:37 | 显示全部楼层
Chapter 2. 系统安装
安装之前:因用户数据都保存在/var目录下,因此安装FreeBSD时/var的空间应尽量大。FreeBSD的版本为4.9,按最小化安装,软件包只安装cvsup,安装结束后用cvsup更新ports树。在文档中假设服务器的ip地址为192.168.204.38,域名为test.com,主机名为mail.test.com。


昏....你自己写的是4.9啊??
回复 支持 反对

使用道具 举报

 楼主| 发表于 2005-2-18 10:52:30 | 显示全部楼层
那你照你找到那篇在FB5.3上安装一下看你能不能安装成功吧?
呵呵!
回复 支持 反对

使用道具 举报

发表于 2005-2-18 13:54:52 | 显示全部楼层
好久以前在那里看过
回复 支持 反对

使用道具 举报

发表于 2005-2-18 13:57:37 | 显示全部楼层
不过文章还是不错的。4.x成功,5.x没试过。4.x比较稳定,5.x有可能有漏洞
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表