1.安装webmin
下载webmin-1.070.tar.gz
#tar zxvf webmin-1.070.tar.gz
#cd webmin-1.070
#./setup.sh
安装后可以对mysql数据库进行管理,比如添加用户,向表里添加数据。
2.数据库的设置
2.1、安装mysql数据库
本系统使用的是FreeBSD 4.7下ports安装的mysql数据库(当时使用原码安装时在安装postfix时出错,所以使用ports安装就解决了该问题)。
#cd /usr/ports/databases/mysql323-server/
#make install
#cd work/mysql-3.23.52/
#scripts/mysql_install_db
#cp support-files/my-medium.cnf /etc/my.cnf
#echo “/usr/local/bin/safe_mysqld --user=mysql &” >> /etc/rc.local
#/usr/local/bin/safe_mysqld --user=mysql & 启动mysql服务
2.2、设置数据库
2.2.1、添加mysql用户:
1、使用webmin->mysql数据库服务器->用户权限,添加用户postfix,密码postfix,主机localhost,并设置拥有相应的权限。
2、使用SQL语句添加用户:
#cd /usr/local/bin
#./mysql –D mysql –p
Password:
mysql>INSERT INTO user (host,user,password)
->VALUES (‘localhost’,‘postfix’,’’);
Query OK. I row affected (0.00 sec)
mysql>UPDATA user SET password=password(‘postfix’)
->WHERE user=’postfix’;
Rows matched: 1 Changed: 1 Warnings: 0
mysql>FLUSH PRIVILEGES;
Query OK. 0 rows affected (0.01 sec)
mysql>GRANT select,insert,update on mail.* TO postfix
Query OK. 0 rows affected (0.01 sec)
mysql>exit
2.2.2、向数据库中添加表
#cd /usr/local/bin/
#ee postfix.sql
CREATE DATABASE;
GRANT ALL ON mail.* mail@localhost IDENTIFIED BY “postfix”;
FLUSH PRIVILEGES;
use mail;
CREATE TABLE forward (
username varchar(255) NOT NULL default ‘’, //本机地址
forward_addr varchar(255) default NULL, //转发地址
PRIMARY KEY (username)
) TYPE=MyISAM;
CREATE TABLE transport (
domain varchar(255) NOT NULL default ‘’, //邮件域
transport varchar(icon_cool.gif default NULL, //处理方式
PRIMARY KEY (domain)
) TYPE=MyISAM;
CREATE TABLE users (
username varchar(128) NOT NULL default ‘’, //用户名
domain varchar(128) NOT NULL default ‘’, //邮件域
address varchar(128) NOT NULL default ‘’, //邮件地址
password varchar(128) NOT NULL default ‘’, //用户密码(明文)
uid int(6) NOT NULL default ‘1024’, //uid
gid int(6) NOT NULL default ‘1024’, //gid
home varchar(255) NOT NULL default ‘/’, //home目录
maildir varchar(255) NOT NULL default ‘’, //maildir目录
quota varchar(255) NOT NULL default ‘’, //邮箱容量
mailok tinyint(3) NOT NULL default ‘1’,
bool1 tinyint(3) NOT NULL default ‘1’,
bool2 tinyint(3) NOT NULL default ‘1’,
PRIMARY KEY (address),
UNIQUE KEY address (address),
KEY address_2 (address)
) TYPE=MyISAM;
输入完毕后保存退出。
#./mysql –u postfix –p < postfix.sql
#password:postfix
2.2.3、向表中添加数据
#/usr/local/bin
#./mysql –u postfix –p
password:******
mysql>use mail
mysql>INSERT INTO transport (domain,transport)
->VALUES (’localhost.com’,’virtual:’);
mysql>INSERT INTO users (username,domain,address,password,uid,gid,
home,maildir,quota,mailok,bool1,bool2)
->VALUES (‘test’,’localhost.com’,’test.localhost.com’,
’test’,’1024’,’1024’,’/’,
’/var/postfix_mail/test/Maildir/’,’5000000’,’1’,’1’,’1’);
mysql>exit
3.安装CYRUS-SASL
#tar –zxvf cyrus-sasl-1.5.27
#cd cyrus-sasl-1.5.27
#./configure --with-pwcheck=/var/pwcheck --enable-login
--enable-plain
#make
#make install
#echo /usr/local/lib/ >> /etc/ld.so.conf
#echo /usr/local/lib/mysql/ >> /etc/ld.so.conf
#ldconfig
#cp /usr/local/include/* /usr/include
#cp /usr/local/lib/lib*.* /usr/lib
#ln –s /usr/local/lib/sasl /usr/lib/sasl
#ln –s /usr/local/include/mysql /usr/include/mysql
#ln –s /usr/local/lib/mysql /usr/lib/mysql
在/usr/local/lib/sasl下建立文件smtpd.conf,添加一下内容:
pwcheck_method:mysql
mysql_user:postfix
mysql_passwd:postfix
mysql_host:localhost
mysql_database:mail
mysql_table:users
mysql_uidcol:address
mysql_pwdcol:password
4.安装和设置postfix
4.1、安装postfix
4.4.1、编译/etc/rc.conf,设置sendmail_enable=”NO”
#mv /usr/bin/newaliases /usr/bin/newaliases.OFF
#mv /usr/bin/mailq /usr/bin/mailq.OFF
#mv /usr/sbin/sendmail /usr/sbin/sendmail.OFF
#pw groupadd postfix –g 1024
#pw groupadd postdrop –g 1025
#pw useradd postfix –u 1024 –g postfix
#echo ‘postfix:root’ >> /etc/aliases
4.4.2、安装postfix和相应的quota补丁
#tar zxvf postfix-1.1.11.tar.gz
#patch < postfix-1.1.11_quota_maildirsize.patch
#make –f Makefile.init makefiles ‘CCARGS=-DUSE_SASL_AUTH –DHAS_MYSQL –I/usr/include/mysql’ ‘AUXLIBS=-L/usr/lib/mysql –lmysqlclient –lasal –lz –lm’
#make
#make install 按照默认路径一路回车就可以安装成功postfix,如果出错,在提示“tempdir”时输入:/tmp,这样一般就可以通过。
4.2、设置postfix
postfix默认安装到/etc/postfix目录下,设置文件也在这
#cd /etc/postfix
4.2.1、编译主配置文件main.cf
#ee main.cf 添加如下内容
#Base configure
myhostname = mail.localhost.com //本机的机器名
mydomain = local.com //域名
mynetworks = 127.0.0.0/8 192.168.0.0/16 //允许不经smtp认证能发信的ip段
home_mailbox = Maildir/ //使用的邮箱格式为Maildir/
smtpd_banner = Welcome to localhost.com mail system! //smtp的欢迎信息
#Mysql configure
transport_maps = mysql:/etc/postfix/transport.cf //指定那些域的邮件可以被postfix收下来
virtual_mailbox_base =/ //指定用户邮箱所在的根目录
virtual_uid_maps = mysql:/etc/postfix/ids.cf //指定postfix帐号的ID
virtual_gid_maps = mysql:/etc/postfix/gds.cf //指定postfix组的ID
virtual_mailbox_maps = mysql:/etc/postfix/users.cf //指定用户邮箱的目录
virtual_maps = mysql:/etc/postfix/forward.cf //指定自动转发邮件的设置
#Quota configure
message_size_limit = 5000000 //单个邮件大小的限制
virtual_mailbox_limit = 5000000 //默认的邮箱大小
virtual_mailbox_limit_maps = mysql:/etc/postfix/quota.cf //每个用户的邮箱大小
virtual_mailbox_limit_override = yes //是否允许覆盖默认的邮箱大小
#smtp configure
smtpd_sasl_auth_enable = yes
smtpd_sasl_local_domain = $myhostname
smtpd_recipient_restrictions = permit_mynetworks permit_sasl_authenticated permit_auth_destination reject
smtpd_sasl_security_options = noanonymous
smtpd_client_restrictions = permit_sasl_authenticated
inet_interfaces = all //监听所有端口
inet_interfaces = 192.168.80.21 //是外面的用户也可以发送邮件
4.2.2、查看master.cf文件必须包含下面一行
virtual unix - n n - - virtual
4.2.3、编译transport.cf
#touch transport.cf
#ee transport.cf 添加如下内容
user = postfix
password = postfix
dbname = mail
table = transport
select_field = transport
where_field = domain
hosts = localhost
4.2.4、编译ids.cf
#touch ids.cf
#ee ids.cf
user = postfix
password = postfix
dbname = mail
table = users
select_field = uid
where_field = address
hosts = localhost
4.2.5、编译gds.cf
#touch gds.cf
#ee gds.cf
user = postfix
password = postfix
dbname = mail
table = users
select_field = gid
where_field = address
hosts = localhost
4.2.6、编译forward.cf
#touch forward.cf
#ee forward.cf
user = postfix
password = postfix
dbname = mail
table = forward
select_field = forward_addr
where_field = username
hosts = localhost
4.2.7、编译users.cf
#touch users.cf
#ee users.cf
user = postfix
password = postfix
dbname = mail
table = users
select_field = maildir
where_field = address
hosts = localhost
4.2.8、编译quota.cf
#touch quota.cf
#ee quota.cf
user = postfix
password = postfix
dbname = mail
table = users
select_field = quota
where_field = address
hosts = localhost
4.3、启动postfix
#/usr/sbin/postfix start
postfix/postfix-script: starting the Postfix mail system
#echo “/usr/sbin/postfix start” >> /etc/rc.local
#telnet localhost 25
Connected to localhost.localhost.com.
Escape character is ‘^]’.
220 Welcome to localhost mail system!
4.4、测试postfix
4.4.1、建立mail邮件存放目录
#cd /var
#mkdir postfix_mail
#chown –R postfix:postfix /var/postfix_mail
4.4.2、使用客户端发邮件
此时可以使用客户端的foxmail或者outlook向用户test.localhost.com发送邮件,然后到/var/postfix/test/Maildir/下查看邮件,如果能收到说明SMTP已经工作正常了,如果有问题仔细检查自己的每个步骤。
5.安装设置courier-imap
5.1、安装courier-imap
#cd /usr/ports/mail/courier-imap
#make
#cd work/courier-imap-1.5.3
#./configure –with-db=db –without-socks –disable-root-check
#make
#make install
#/usr/lib/courier-imap/libexec/authlib/authdaemon start
#echo “/usr/lib/courier-imap/libexec/authlib/authdaemon start” >> /etc/rc.local
5.2、添加用户
#cd /usr/local/bin
#./mysql –D mysql –p
password:*******
mysql>INSERT INTO user (host,user,password)
->VALUES (‘localhost’,’courier’,’’);
mysql>UPDATA user SET password=password(‘haha’)
->WHERE user=’courier’;
mysql>FLUSH PRIVILEGES;
mysql>GRAN select,insert,update on mail.* TO courier;
mysql>exit
5.3、设置courier-imap
#cd /usr/lib/courier-imap/etc
#cp authdaemonrc.dist authdaemonrc
#cp authmysqlrc.dist authmysqlrc
#cp imapd.dist imapd
#cp imapd-ssl.dist imapd-ssl
#cp pop3d.dist pop3d
#cp pop3d-ssl pop3d-ssl
#ee pop3d
prefix=/usr/lib/courier-imap
exec_prefix=/usr/lib/courier-imap
sbindir=”/usr/lib/courier-imap/sbin”
PIDFILE=/var/run/pop3d.pid
MAXDAEMONS=40
MAXPERIP=4
AUTHMODULES=”authdaemon”
AUTHMODULES_ORIG=”authdaemon”
POP3AUTH=””
POP3AUTH_ORIG=”LOGIN CRAM-MD5 CRAM-SHA1”
POP3AUTH_TLS=””
POP3AUTH_TLS_ORIG=”LOGIN PLAIN”
PORT=110
ADDRESS=0
TCPDOPTS=”-nodnslookup -noidentlookup”
POP3DSTART=YES
#ee imapd
IMAPDSTART=YES
#ee authdaemonrc
authmodulelist=”authmysql authpam”
authmodulelistorig=”authcustom authcram authuserdb authmysql authpam”
daemons=5
version=”authdaemond.mysql”
authdaemonvar=”/usr/lib/courier-imap/var/authdaemon”
#ee authmysqlrc
MYSQL_SERVER localhost
MYSQL_USERNAME courier
MYSQL_PASSWORD haha
MYSQL_SOCKET /tmp/mysql.sock
MYSQL_PORT 3306
MYSQL_OPT 0
MYSQL_DATABASE mail
MYSQL_USER_TABLE users
#MYSQL_CRYPT_PWFIELD password
MYSQL_CLEAR_PWFIELD password
MYSQL_UID_FIELD uid
MYSQL_GID_FIELD gid
MYSQL_LOGIN_FIELD address
MYSQL_HOME_FIELD home
MYSQL_NAME_FIELD username
MYSQL_MAILDIR_FIELD maildir
MYSQL_QUOTA_FIELD quota
MYSQL_WHERE_CLAUSE mailok=1
#cd ..
#ln -s /usr/lib/courier-imap/libexec/imapd.rc imapd
#ln -s /usr/lib/courier-imap/libexec/pop3d.rc pop3d
#./imapd start
#echo “/usr/lib/courier-imap/imap start” >> /etc/rc.local
#./pop3d start
#echo “/usr/lib/courier-imap/pop3 start” >> /etc/rc.local
#netstat –an | grep LISTEN
tcp4 0 0 *:110 *:* LISTEN
tcp46 0 0 *:110 *:* LISTEN
tcp4 0 0 *:143 *.* LISTEN
tcp46 0 0 *.143 *.* LISTEN
#telnet localhost 110
Trying 127.0.0.1...
Connected to localhost.cw-isquare.com.
Escape character is ‘^]’.
+OK Hello there
#quit
#telnet localhost 143
*OK Courier-IMAP ready. Copyright 1998-2002 Double Precision, Inc. See COPYING for distribution information.
#quit
5.安装设置sqwebmail
5.1、安装sqwebmail-3.5.0-cn.tar.gz
#tar zxvf sqwebmail-3.5.0.tar.gz
#cd sqwebmail-3.5.0
#./configure --without-authpam –with-db=db --enable-webpass=no --without-authpwd --without-authshadow
#make configure-check
#make
#make install-strip
#make install-configure
#/usr/local/share/sqwebmail/libexec/authlib/authdaemond start
#echo “/usr/local/share/sqwebmail/libexec/authlib/authdaemond start” >> /etc/rc.local
5.2、配置sqwebmail-3.5.0
5.2.1、安装apache
#tar apache_1.3.22.tar.gz
#cd apache_1.3.22
#./configure –prefix=/usr/local/apache
#make
#make install
5.2.2、设置sqwebmail
#cd /usr/local/share/sqwebmail
#ee authdaemonrc
authmodulelist=”authmysql authpam”
authmodulelistorig=”authcustom authcram authuserdb authmysql authpam”
daemons=5
version=”authdaemond.mysql”
authdaemonvar=”/usr/local/share/sqwebmail/var/authdaemon”
#ee authmysqlrc
MYSQL_SERVER localhost
MYSQL_USERNAME courier
MYSQL_PASSWORD haha
MYSQL_SOCKET /tmp/mysql.sock
MYSQL_PORT 3306
MYSQL_OPT 0
MYSQL_DATABASE mail
MYSQL_USER_TABLE users
#MYSQL_CRYPT_PWFIELD password
MYSQL_CLEAR_PWFIELD password
MYSQL_UID_FIELD uid
MYSQL_GID_FIELD gid
MYSQL_LOGIN_FIELD address
MYSQL_HOME_FIELD home
MYSQL_NAME_FIELD username
MYSQL_MAILDIR_FIELD maildir
MYSQL_QUOTA_FIELD quota
MYSQL_WHERE_CLAUSE mailok=1
5.2.3、测试sqwebmail-3.5.0
在客户端的浏览器的地址栏输入
http://mail.localhost.com/cgi-bin/sqwebmail
输入用户名和密码就可以登录进去收发邮件了。
注意:用户名一定要输入全称,也就是连域名一起输入。
5.2.4、设置apache页面跳转
#cd /usr/local/apache/htdocs
#touch index.html
#ee index.html
<meta http-equiv=”refresh” content=”0;URL=http://mail.localhost
.com/cgi-bin/sqwebmail?index=1”>
现在就可以直接在IE的地址栏输入:
http://mail.localhost.com
来访问sqwebmail了
这篇文章没有加入smtp认证,上次有个朋友在帖子里说过加认证的方法,由于没有时间,所以我就没有试。还有没有邮件列表的问题,我找不到解决的方法,如果有朋友看到这篇文章请把smtp认证和邮件列表功能补充一下,这要就比较完整了。在此我先表示感谢~
文章来源于领测软件测试网 https://www.ltesting.net/
版权所有(C) 2003-2010 TestAge(领测软件测试网)|领测国际科技(北京)有限公司|软件测试工程师培训网 All Rights Reserved
北京市海淀区中关村南大街9号北京理工科技大厦1402室 京ICP备2023014753号-2
技术支持和业务联系:info@testage.com.cn 电话:010-51297073