Postfix邮件系统安装手册
10.安装Courier-imap-1.7.1(need gmake、expect)
1、安装
hawk# pkg_add -r gmake 远程安装包
hawk# pw useradd cnhawk -g wheel(the software MUST run the configure script as normal user, not root)
hawk$ bunzip2 courier-imap-1.7.1.tar.bz2
hawk$ tar xvf courier-imap-1.7.1.tar
hawk$ cd courier-imap-1.7.1
如果你的mysql是源码编译请用下面这个命令
hawk$ ./configure --without-ipv6 --enable-unicode
--enable-workarounds-for-imap-client-bugs
--with-mysql-libs=/usr/local/mysql/lib/mysql
--with-mysql-includes=/usr/local/mysql/include/mysql
如果你的mysql是ports安装请用下面这个命令
Hawk$./configure --without-ipv6 --enable-unicode --enable-workarounds-for-imap-client-bugs --with-mysql-libs=/usr/local/lib/mysql --with-mysql-includes=/usr/local/include/mysql
hawk$ gmake
hawk# su root
hawk# gmake install
# 记住一定用 gmake
hawk# gmake install-configure
2)配置
编辑修改/usr/lib/courier-imap/etc/authmysqlrc 示例:authmysqlrc
##VERSION: $Id: authmysqlrc,v 1.10 2002/04/02 23:41:41 mrsam Exp $
#
# Copyright 2000 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 hawk
##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 /tmp/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_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_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 imapok=1
##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, uid, gid, clearpw, home, maildir, quota, fullname
#
# 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) and $(domain)
#
# If a $(domain) is empty (not given by the remote user) the default domain
# name is used in its place.
#
# This example is a little bit modified adaptation of vmail-sql
# database scheme:
#
# MYSQL_SELECT_CLAUSE SELECT popbox.local_part,
# CONCAT(''{MD5}'', popbox.password_hash),
# popbox.clearpw,
# domain.uid,
# domain.gid,
# CONCAT(domain.path, ''/'', popbox.mbox_name),
# '''',
# domain.quota,
# '''',
# 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)''
#
编辑修改/usr/lib/courier-imap/etc/authdaemonrc
version="authdaemond.mysql"
3)设置自启动
hawk# cd /usr/local/etc/rc.d
hawk# ln -s /usr/lib/courier-imap/libexec/imapd.rc imapd.sh
hawk# ln -s /usr/lib/courier-imap/libexec/pop3d.rc pop3d.sh
hawk# chmod 755 imapd.sh
hawk# chmod 755 pop3d.sh
现在开始测试:
1)设置用户:
hawk# 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@the9.com'',''cnhawk@the9.com'');
mysql> insert aliases values(''postmaster@freebsd.net'',''cnhawk@freebsd.net'');
mysql> select * from aliases;
+--------------------------+--------------------+
| alias | rcpt |
+--------------------------+--------------------+
| postmaster@the9.com | cnhawk@the9.com |
| postmaster@freebsd.net | cnhawk@freebse.net |
+--------------------------+--------------------+
mysql> desc transport;
+-----------+-----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------+-----------+------+-----+---------+-------+
| domain | char(128) | | PRI | | |
| transport | char(128) | | | | |
+-----------+-----------+------+-----+---------+-------+
mysql> insert transport values(''the9.com'',''virtual:'');
mysql> insert transport values(''freebsd.net'',''virtual:'');
mysql> select * from transport;
+---------------+-----------+
| domain | transport |
+---------------+-----------+
| nankai.edu.cn | virtual: |
| freebsd.net | 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 (''cnhawk@the9.com'',''/var/mail/'',encrypt(''cnhawk''),
mysql> ''the9.com/cnhawk/Maildir/'',''2003-04-23'',''01:18:24'',''the9.com'',''cnhawk'');
mysql> INSERT INTO virtual_users
mysql> (id,home,password,maildir,date_add,time_add,domain,name)
mysql> VALUES (''hawk@freebsd.net'',''/var/mail/'',encrypt(''hawk''),
mysql> ''freebsd.net/hawk/Maildir/'',''2003-04-23'',''01:18:24'',''freebsd.net'',''hawk'');
mysql> quit
2)设置用户的目录与权限:
hawk# mkdir -p /var/mail/the9.com/cnhawk
hawk# mkdir -p /var/mail/freebsd.net/hawk
hawk# cd /usr/lib/courier-imap/bin
hawk# ./maildirmake /var/mail/the9.com/cnhawk/Maildir
hawk# ./maildirmake /var/mail/freebsd.net/hawk/Maildir
hawk# chmod -R 700 /var/mail/the9.com/
hawk# chmod -R 700 /var/mail/freebsd.net/
hawk# chown -R postfix:postfix /var/mail/the9.com
hawk# chown -R postfix:postfix /var/mail/freebsd.net
至此用户设置完毕,这里仅仅使用两个虚拟域,同理可以设置若干个虚拟域,如:mail.com
3)用户登录测试:
先用perl的mod来产生这个base64编码,安装ports在/usr/ports/converters/p5-MIME-Base64/
先获取plain字符窜。为了获得plain字符串,必须要用base64编码
hawk# perl -MMIME::Base64 -e ''print encode_base64("cnhawk@the9.com");''
在@前面的加个才可以成功得到字符串
Y25oYXdrQHRoZTkuY29t
hawk# perl -MMIME::Base64 -e ''print encode_base64("cnhawk");''
Y25oYXdr
%telnet 127.0.0.1 25
Trying 127.0.0.1...
Connected to 0.
Escape character is ''^]''.
220 hawk.the9.com ESMTP Postfix
ehlo hawk
250-hawk.the9.com
250-PIPELINING
250-SIZE 2097152
250-VRFY
250-ETRN
250-AUTH LOGIN PLAIN OTP
250-AUTH=LOGIN PLAIN OTP
250-XVERP
250 8BITMIME
auth login
334 VXNlcm5hbWU6
Y25oYXdrQHRoZTkuY29t (此为用户名id:cnhawk@the9.com)
334 UGFzc3dvcmQ6
Y25oYXdr (此为用户密码password:cnhawk)
235 Authentication successful
quit
221 Bye
Connection closed by foreign host.
hawk# telnet 127.0.0.1 110
Trying 127.0.0.1....
Connected to 0.
Escape character is ''^]''.
+OK Hello there.
user cnhawk@the9.com
+OK Password required.
pass cnhawk
+OK logged in. (OK,pop 登录成功)
quit
+OK Bye-bye.
Connection closed by foreign host.
也可以使用任何其它的邮件客户端程序来测试,如foxmail、Outlook Express等等。
然后安装webmail
安装igenus
使用修改过的版本: http://218.6.128.194/igenus_docn.tar.gz
1.安装:
hawk # cd /usr/ports/www/apache2
hawk # make install
hawk# cd /usr/ports/www/mod_php4
hawk# make install
hawk# cd /var/mail
hawk# tar zxvf igenus_docn.tar.gz
hawk# edit /usr/local/apache/conf/httpd.conf
2.配置:
1)Group nobody、User nobody
修改为: Group postfix、User postfix
2)DocumentRoot "/usr/local/apache/htdocs"
修改为:DocumentRoot "/var/mail/webmail"
3) 查找 AddDefaultCharset ISO-8859-1
改为AddDefaultCharset GB2312 #中文支持
添加AddType application/x-httpd-php .php #php支持
4)修改config_inc.php文件
$CFG_BASEPATH = "/var/mail/webmail";
$CFG_MYSQL_HOST = ''localhost'';
$CFG_MYSQL_USER = ''postfix'';
$CFG_MYSQL_PASS = ''hawk'';(同以上密码,均可以自己修改)
$CFG_MYSQL_DB = ''mail'';
5) 编辑/usr/local/etc/php.ini,修改:
Cp /usr/local/etc/php.ini-dist /usr/local/etc/php.ini
register_globals = On
3.使用:
最后在浏览器的URL中输入:
http://IP 因为没有DNS 有了DNS就好了 可以直接定位域名
1. 修改/etc/php.ini
max_execution_time = 30 #改为60 (增加处理脚本的时间限制)
memory_limit = 8M #改为40M (这样才能发10M的附件)
post_max_size = 2M #改为10M
upload_max_filesize = 2M #改为10M
2. 修改/etc/httpd/conf.d/php.conf
SetOutputFilter PHP
SetInputFilter PHP
LimitRequestBody 524288 #把524288改为10485760
这里的 LimitRequestBody 524288 限定了上传附件的上限为512k, 将其改为10M
3. 修改/etc/postfix/main.cf, 添加如下语句:
message_size_limit = 14336000
postfix的默认值是10M, 但这指的是邮件正文和编码后附件的总和, 经过base64编码,附件的大小会增加35%左右, 因此这里设定可接受邮件的大小为14M
可以使用如下命令查看postfix的有关设定:
/usr/sbin/postconf | grep size
4. 重起apache和postfix.
剩下反病毒反垃圾了:)