架构基于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_1 $Date: 2005-1-27
________________________________________
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(如果没有这个文件就手动创建一个:touch /etc/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# chmod 755 /usr/local/etc/rc.d/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(18) 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(48) 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->;PASSWORD!=crypt($post_OldPasswd,$row->;PASSWORD) ) {
$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. ;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 bgco
flighttop 回复于:2005-01-26 04:08:53
Excellent note! Thank you for sharing your experience with us.
by the way, an extra disk (over 80GB) could be added into the system and mounted to /var/mail as the repository of all emails.
scyzxp 回复于:2005-01-27 11:50:21
那个高手来看一下呀!这里有一个问题我没有解决呀!
scyzxp 回复于:2005-01-31 15:08:36
权限问题己解决!文章本身没有什么问题的!请大家放心,如果发现有什么地方出错了那我请通知我。
scyzxp 回复于:2005-02-02 11:10:10
本想今天升级到2.0的可是发现还有好多不足呀,过了年等我加了postfixadmin了再升级吧!
heiyeluren 回复于:2005-02-04 14:18:49
鼓励原创~~~~好强!!!
chaohu 回复于:2005-02-15 12:55:22
谁是原创呀
http://www.mske.com/index.php?option=content&task=view&id=10&Itemid=28
hefish 回复于:2005-02-15 21:54:15
不管是谁原创,只要没错误就好。
海鹰 回复于:2005-02-15 23:35:10
有错
浪人夕远 回复于:2005-02-16 11:27:54
xiaohua 有错你直接指呀~ 该出手时就出手啊~ :)
海鹰 回复于:2005-02-16 11:51:32
pam那部分。还有,这种方案结构不能使用postfixadmin。因为它们的表结构不同
mysql>; use postfix;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql>; show tables;
+-------------------+
| Tables_in_postfix |
+-------------------+
| admin |
| alias |
| domain |
| domain_admins |
| log |
| mailbox |
| vacation |
+-------------------+
7 rows in set (0.01 sec)
mysql>; desc alias;
+----------+--------------+------+-----+---------------------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+--------------+------+-----+---------------------+-------+
| address | varchar(255) | | PRI | | |
| goto | text | | | | |
| domain | varchar(255) | | | | |
| created | datetime | | | 0000-00-00 00:00:00 | |
| modified | datetime | | | 0000-00-00 00:00:00 | |
| active | tinyint(1) | | | 1 | |
+----------+--------------+------+-----+---------------------+-------+
6 rows in set (0.00 sec)
mysql>; desc admin;
+----------+--------------+------+-----+---------------------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+--------------+------+-----+---------------------+-------+
| username | varchar(255) | | PRI | | |
| password | varchar(255) | | | | |
| created | datetime | | | 0000-00-00 00:00:00 | |
| modified | datetime | | | 0000-00-00 00:00:00 | |
| active | tinyint(1) | | | 1 | |
+----------+--------------+------+-----+---------------------+-------+
5 rows in set (0.00 sec)
mysql>; desc domain;
+-------------+--------------+------+-----+---------------------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------------+--------------+------+-----+---------------------+-------+
| domain | varchar(255) | | PRI | | |
| description | varchar(255) | | | | |
| aliases | int(10) | | | 0 | |
| mailboxes | int(10) | | | 0 | |
| maxquota | int(10) | | | 0 | |
| transport | varchar(255) | YES | | NULL | |
| backupmx | tinyint(1) | | | 0 | |
| created | datetime | | | 0000-00-00 00:00:00 | |
| modified | datetime | | | 0000-00-00 00:00:00 | |
| active | tinyint(1) | | | 1 | |
+-------------+--------------+------+-----+---------------------+-------+
10 rows in set (0.00 sec)
mysql>; desc domain_admins;
+----------+--------------+------+-----+---------------------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+--------------+------+-----+---------------------+-------+
| username | varchar(255) | | MUL | | |
| domain | varchar(255) | | | | |
| created | datetime | | | 0000-00-00 00:00:00 | |
| active | tinyint(1) | | | 1 | |
+----------+--------------+------+-----+---------------------+-------+
4 rows in set (0.00 sec)
mysql>; desc log;
+-----------+--------------+------+-----+---------------------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------+--------------+------+-----+---------------------+-------+
| timestamp | datetime | | MUL | 0000-00-00 00:00:00 | |
| username | varchar(255) | | | | |
| domain | varchar(255) | | | | |
| action | varchar(255) | | | | |
| data | varchar(255) | | | | |
+-----------+--------------+------+-----+---------------------+-------+
5 rows in set (0.01 sec)
mysql>; desc mailbox;
+----------+--------------+------+-----+---------------------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+--------------+------+-----+---------------------+-------+
| username | varchar(255) | | PRI | | |
| password | varchar(255) | | | | |
| name | varchar(255) | | | | |
| maildir | varchar(255) | | | | |
| quota | int(10) | | | 0 | |
| domain | varchar(255) | | | | |
| created | datetime | | | 0000-00-00 00:00:00 | |
| modified | datetime | | | 0000-00-00 00:00:00 | |
| active | tinyint(1) | | | 1 | |
+----------+--------------+------+-----+---------------------+-------+
9 rows in set (0.00 sec)
mysql>; desc vacation;
+---------+--------------+------+-----+---------------------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------+--------------+------+-----+---------------------+-------+
| email | varchar(255) | | PRI | | |
| subject | varchar(255) | | | | |
| body | text | | | | |
| cache | text | | | | |
| domain | varchar(255) | | | | |
| created | datetime | | | 0000-00-00 00:00:00 | |
| active | tinyint(1) | | | 1 | |
+---------+--------------+------+-----+---------------------+-------+
7 rows in set (0.00 sec)
luwentao 回复于:2005-02-17 21:22:02
pam这部分确实有错,可以用就懒得改了
管理部分比较难解决,自己写的太简陋了
zxy123 回复于:2005-02-20 16:33:47
小花同志能不能说一下pam和这个数据库结构应该怎么改吗?谢谢~
luckyzhang 回复于:2005-02-25 15:00:28
引用:原帖由 "海鹰"] 发表:
海鹰,能不能说一下,该怎么改才对么?这样好钓人胃口阿
。。。
海鹰 回复于:2005-02-25 17:18:17
引用:原帖由 "luckyzhang" 发表:
海鹰,能不能说一下,该怎么改才对么?这样好钓人胃口阿
。。。
不好意思啊,我这几天很多事,没空看。你可以看看我未整理好的资料
http://www.dmail-x.com/doc/postfix/
至少改,这实在是不好改。还不如重做系统算了
牙齿晒太阳 回复于:2005-02-25 18:40:57
我的系统是rhlinux AS3 mysql+postfix+postfixadmin+squirrelmail
配置完成后进入postfixadmin页面输入帐户和密码不能登陆,在mysql里面
我又修改了postfix帐户的密码,还是不能登陆管理界面
tnthb 回复于:2005-03-04 16:33:24
那里好想看过 有人做过用ldap作认证的吗?
hefish 回复于:2005-03-04 21:13:53
xiaohua的心情我理解,跟我一样,不高兴一遍又一遍地指出了。。。
另: xiaohua,我现在转搞DNS了,暂时对mail失去兴趣。。。:)
海鹰 回复于:2005-03-05 10:08:22
引用:原帖由 "hefish" 发表: xiaohua的心情我理解,跟我一样,不高兴一遍又一遍地指出了。。。
另: xiaohua,我现在转搞DNS了,暂时对mail失去兴趣。。。:)
:shock: :shock: :shock:
scyzxp 回复于:2005-03-11 11:05:07
当中是存在不足之处,不过照这个文档来安装是一定能让它正常运行的!请大家放心的参考,一起学习嘛!
scyzxp 回复于:2005-03-17 15:15:27
怎么没有人顶呢?
huxc34 回复于:2005-04-19 16:56:01
登到25端口上面发信,认证全部通过了,但是打完RCPT TO:webmaster@test.com
出现这个错误Temporary lookup failure
什么原因?
soka 回复于:2005-07-06 13:01:20
scyzxp是比很多人都强的.
|