---szx2007 感谢anthonyfeng
功能:虚拟域、虚拟用户、POP3、POP3S、SMTP、SMTPS、IMAP、IMAPS、防毒、防SPAM、网页邮件功能。
涉及的软件
1.centos4.4
2.Mysql 系统自带
用于存储虚拟域、虚拟用户等信息。
3.Apache 系统自带
运行网页邮件SquirrelMail和PostfixAdmin时使用。
4.PHP 系统自带
运行网页邮件SquirrelMail和PostfixAdmin时使用。
5.Cyrus-sasl 系统自带
实现带验证的SMTP时使用。
6.courier-authlib-0.58.tar.tar 编译安装
实现带验证的SMTP时使用。
7. postfix-2.4.0-5.mysql.sasl2.notls.rhel4.i386.rpm
http://www.proficuous.com/postfix/RHEL4/postfix_2.4/2.4.0/下载后自行安装
一个MTA,centos4.4自带Postfix的不支持SSL及Mysql,所以需要安装新的。
8.PostfixAdmin
本BLOG有.自行安装.
虚拟域、虚拟用户等信息是放在Mysql内的,安装PostfixAdmin后,就可以用浏览器管理这些信息。
9.SquirrelMail 一个基于IMAP的Webmail客户端。
官方网站:http://www.squirrelmail.org/
最简单的是在安装OS时安装它,MTA配好之后即可使用:http://192.168.0.214/webmail.
10.Dovecot 系统自带
提供POP3,POP3S,IMAP,IMAPS功能。
11.F-prot 从http://www.f-prot.com下载自行安装
Linux workstation 版个人使用是免费的
提供杀毒功能,据闻速度和病毒库比开源的Clamav好。
12.SpamAssassin 系统自带
提供过滤垃圾邮件功能。
13.MailScanner 从http://www.sng.ecs.soton.ac.uk/mailscanner/下载
Postfix使用MailScanner调用f-prot 与SpamAssassin
配置过程
1.基本软件安装
安装centos4.4,使用服务器模式安装,语系为简体中文。关闭SE Linux,配置网卡,使其能访问Internet。
安装的包包括:
万维网服务器
mysql & php 相关的
邮件服务器:SquirrelMail perl-cyrus
SQL数据库:全部。
下载其它需要的软件。
2.配置PostfixAdmin、Mysql、Apache
[root@mail]# service mysqld start
[root@mail]# service httpd start
设置Mysql和Apache自动启动
[root@localhost]# chkconfig --level 35 mysqld on
[root@localhost]# chkconfig --level 35 httpd on
同时修改apache的httpd.conf里默认语言为zh_CN,编码为gb2312.
前台域名为mail2.51autotest.cn,虚拟主机目录为/var/www/html/squirrelmail
后台域名为admin2.51autotest.cn,虚拟主机目录为/var/www/html/postfixadmin22
修改httpd.conf,增强APACHE安全性。
iptables开80 443(用户修改邮箱密码时用该端口) 110(POP3收信)和25(发信)端口.
-------------------postfixadmin------------------------------------------------
[root@mail html]#rz //上传postfixadmin-2.1.0.tgz到当前目录
[root@mail html]# tar xzvf postfixadmin-2.1.0.tgz //解压到当前目录
[root@mail html]# ln -s postfixadmin-2.1.0/ postfixadmin22 //做个连接
[root@mail html]# chown -R apache.apache postfixadmin-2.1.0/ //修改所有者为httpd用户
[root@mail html]#cd postfixadmin22
[root@mail postfixadmin22]#chmod 640 admin/*.php //设置权限增加安全性
[root@mail postfixadmin22]#chmod 640 images / *.png
[root@mail postfixadmin22]#chmod 640 languages/*.lang
[root@mail postfixadmin22]#chmod 640 templates/*.tpl
[root@mail postfixadmin22]#chmod 640 users/ *.php
[root@mail postfixadmin22]#mysql -u root -p321456 < DATABASE_MYSQL.TXT //导入数据库当然了.
[root@mail postfixadmin22]#cp config.inc.php.sample config.inc.php //复制配置文件
[root@mail postfixadmin22]#vi config.inc.php
找这行$CONF[’default_language’] = ’en’
改为$CONF[’default_language’] = ’cn’ //让postfixadmin支持中文
找到 $CONF[’domain_in_mailbox’] = ’YES’
改为$CONF[’domain_in_mailbox’] = ’NO’ // If you don’t want to have the domain in your mailbox set this to ’NO’.
[root@mail postfixadmin]# mv motd-admin.txt motd-admin.txt.move //删除烦人的提示,当然喽,你也可以自已写一些说明性的文字!
#下面的设置需要注意
[root@mail postfixadmin22]#vi /etc/httpd/conf/httpd.conf
在110行左右加入以下内容,加强安全性,要不每个人不经认证都可以用*postfixadmn了!
<Directory "/var/www/html/postfixadmin22/admin" >
Options FollowSymLinks
DirectoryIndex index.php
AllowOverride None
AuthType Basic
authname Private
authuserfile /var/www/html/postfixadmin22/szxkey
require valid-user
Order allow,deny
Allow from all
</Directory>
注意szxkey是我的密码档文件名。
#touch /var/www/html/postfixadmin22/szxkey
#htpasswd -c szxkey admin22 //添加用户admin22
New password:
Re-type new password:
Adding password for user admin
打开浏览器访问 http://192.168.0.214/postfixadmin22/admin 测试该目录安全性.
打开浏览器访问 http://192.168.0.214/postfixadmin22,
然后按提示增加两个虚拟域名d1.com 和 d2.com,增加两个虚拟用户a@d1.com,b@d2.com。
补充:-----------
postfixAdmin自动发欢迎信给刚开通的邮箱:
#vi /var/www/html/pa/config.inc.php
;
Hi:
Welcome to your ...
把这里的英文改成中文即可.
-----------------
3.安装Postfix
先删除sendmail:
[root@localhost]# rpm –e sendmail –nodeps
[root@localhost]# groupadd postfix
[root@localhost]# groupadd postdrop
[root@localhost]#useradd postfix -g postfix -c "Postfix user" -d /dev/null -s /sbin/nologin
[root@localhost]# rpm -ivh postfix-2.4.0-5.mysql.sasl2.notls.rhel4.i386.rpm
[root@localhost]# cd postfix-2.4.0
编辑/etc/postfix/main.cf 为以下内容(建议先复制到文本文件编辑格式后再贴进去)
#=====================BASE=========================
myhostname = mail2.51autotest.cn
mydomain = 51autotest.cn
myorigin = $mydomain
mydestination = $myhostname localhost localhost.$mydomain
mynetworks = 192.168.1.0/24 127.0.0.0/8
inet_interfaces = all
home_mailbox = Maildir/
#=====================Vritual Mailbox settings=========================
virtual_mailbox_base = /var/spool/mail
virtual_mailbox_maps = mysql:/etc/postfix/mysql_virtual_mailbox_maps.cf
virtual_mailbox_domains = mysql:/etc/postfix/mysql_virtual_domains_maps.cf
virtual_alias_domains = //????
virtual_alias_maps = mysql:/etc/postfix/mysql_virtual_alias_maps.cf
virtual_uid_maps = static:501 //运行后面的命令就知道其UID,GID:grep postfix /etc/passwd
virtual_gid_maps = static:502
virtual_transport = virtual
maildrop_destination_recipient_limit = 1
maildrop_destination_concurrency_limit = 1
#====================QUOTA========================
message_size_limit = 14336000 //附件最大14M
virtual_mailbox_limit = 102400000
virtual_create_maildirsize = yes
virtual_mailbox_extended = yes
virtual_mailbox_limit_maps = mysql:/etc/postfix/mysql_virtual_mailbox_limit_maps.cf
virtual_mailbox_limit_override = yes
virtual_maildir_limit_message = 对不起,已经超出了邮箱最大容量。
virtual_overquota_bounce = yes
#====================SASL========================
broken_sasl_auth_clients = yes
smtpd_recipient_restrictions =
permit_mynetworks,permit_sasl_authenticated,reject_invalid_hostname,reject_non_fqdn_hostname,reject_unknown_sender_domain,reject_non_fqdn_sender,reject_non_f
qdn_recipient,reject_unknown_recipient_domain,reject_unauth_pipelining,reject_unauth_destination,permit
smtpd_sasl_auth_enable = yes
smtpd_sasl_local_domain = $myhostname
smtpd_sasl_security_options = noanonymous
smtpd_sasl_application_name = smtpd
smtpd_banner=$myhostname ESMTP "Version not Available"
readme_directory = no
sample_directory = /etc/postfix
sendmail_path = /usr/sbin/sendmail
html_directory = no
setgid_group = postdrop
command_directory = /usr/sbin
manpage_directory = /usr/local/man
daemon_directory = /usr/libexec/postfix
newaliases_path = /usr/bin/newaliases
mailq_path = /usr/bin/mailq
queue_directory = /var/spool/postfix
mail_owner = postfix
编辑/etc/postfix/mysql_virtual_alias_maps.cf 为以下内容
user = postfix
password = postfix
hosts = localhost
dbname = postfix
table = alias
select_field = goto
where_field = address
编辑/etc/postfix/mysql_virtual_domains_maps.cf 为以下内容
user = postfix
password = postfix
hosts = localhost
dbname = postfix
table = domain
select_field = description
where_field = domain
编辑/etc/postfix/ mysql_virtual_mailbox_limit_maps.cf 为以下内容
user = postfix
password = postfix
hosts = localhost
dbname = postfix
table = mailbox
select_field = quota
where_field = username
编辑/etc/postfix/ mysql_virtual_mailbox_maps.cf 为以下内容
user = postfix
password = postfix
hosts = localhost
dbname = postfix
table = mailbox
select_field = maildir
where_field = username
推荐对mysql比较了解的人更改默认的postfix连接密码!默认数据名为postfix,用户名密码都是postfix!!!!
4.配置SMTP 认证
编辑 /usr/lib/sasl2/smtpd.conf 为以下内容
pwcheck_method: authdaemond
log_level: 3
mech_list: plain login
authdaemond_path:/usr/local/courier-authlib/var/spool/authdaemon/socket
安装Courier authentication library
[root@localhost]# tar jxf courier-authlib-0.58.tar.bz2
[root@localhost]# cd courier-authlib-0.58
[root@localhost courier-authlib-0.58]# ./configure --prefix=/usr/local/courier-authlib --without-authpam --without-authldap --without-authpwd --without-
authshadow --without-authvchkpw --without-authpgsql --with-authmysql --with-mysql-libs=/usr/lib/mysql --with-mysql-includes=/usr/include/mysql --with-redhat
--with-authmysqlrc=/usr/local/courier-authlib/etc/authmysqlrc --with-authdaemonrc=/usr/local/courier-authlib/etc/authdaemonrc CFLAGS="-march=i686 -O2 -
fexpensive-optimizations" CXXFLAGS="-march=i686 -O2 -fexpensive-optimizations"
[root@localhost courier-authlib-0.58]# make
[root@localhost courier-authlib-0.58]# make install
[root@localhost courier-authlib-0.58]# chmod 755 /usr/local/courier-authlib/var/spool/authdaemon
[root@localhost courier-authlib-0.58]# cp /usr/local/courier-authlib/etc/authdaemonrc.dist /usr/local/courier-authlib/etc/authdaemonrc
修改/usr/local/courier-authlib/etc/authdaemonrc 文件 ?????
authmodulelist="authmysql"
authmodulelistorig="authmysql"
daemons=10
编辑/usr/local/courier-authlib/etc/authmysqlrc 为以下内容,其中501,502 为postfix 用户的UID和GID。 ????
MYSQL_SERVER localhost
MYSQL_USERNAME postfix
MYSQL_PASSWORD postfix
MYSQL_SOCKET /var/lib/mysql/mysql.sock
MYSQL_DATABASE postfix
MYSQL_USER_TABLE mailbox
MYSQL_CRYPT_PWFIELD password
MYSQL_UID_FIELD ’501’
MYSQL_GID_FIELD ’502’
MYSQL_LOGIN_FIELD username
MYSQL_HOME_FIELD concat(’/var/spool/mail/’,maildir)
MYSQL_MAILDIR_FIELD concat(’/var/spool/mail/’,maildir)
MYSQL_NAME_FIELD name
# cp courier-authlib.sysvinit /etc/init.d/courier-authlib
# chmod 755 /etc/init.d/courier-authlib
# chkconfig --add courier-authlib
# chkconfig --level 35 courier-authlib on
手动启动服务:
# service courier-authlib start
此时你已经拥有一台带验证的SMTP 服务器,用Outlook测试一下吧,用户名采用usename@domainName.com 形式。
5.增加SSL功能,配置SMTPS服务 //???postfix-2.4.0-5.mysql.sasl2.notls.rhel4.i386.rpm里无不支持tls,待研究。
在/etc/postfix/main.cf 增加以下内容
smtp_use_tls = yes
smtpd_use_tls = yes
smtp_tls_note_starttls_offer = yes
smtpd_tls_key_file = /etc/ssl/smtpd.pem
smtpd_tls_cert_file = /etc/ssl/smtpd.pem
smtpd_tls_CAfile = /etc/ssl/smtpd.pem
smtpd_tls_loglevel = 1
smtpd_tls_received_header = yes
smtpd_tls_session_cache_timeout = 3600s
tls_random_source = dev:/dev/urandom
生成证书
# mkdir /etc/ssl
# cd /etc/ssl
# openssl req -new -x509 -nodes -out smtpd.pem -keyout smtpd.pem -days 3650
重新启动postfix
# postfix reload
这时SMTPS功能应该能正常工作了。有能力测试的网友们请验证一下这功能,因为使用SMTPS + Outlook 时有一错误提示。
6.配置Dovecot
增加IMAP,IMAPS,POP3,POP3S功能
由于Dovecot 是系统自带的,配置两个文件,再生成证书就可以了。
编辑 /etc/dovecot.conf 为以下内容
base_dir = /var/run/dovecot/
protocols = imap imaps pop3 pop3s
imap_listen = [::]
pop3_listen = [::]
ssl_disable = no
ssl_cert_file = /etc/ssl/certs/imapd.pem
ssl_key_file = /etc/ssl/private/imapd.pem
ssl_parameters_file = /var/run/dovecot/ssl-parameters.dat
login_dir = /var/run/dovecot-login
login = imap
login = pop3
mbox_locks = fcntl
auth = default
auth_mechanisms = plain
auth_user = root
default_mail_env = maildir:/var/spool/mail/%u/
auth_userdb = mysql /etc/dovecot-mysql.conf
auth_passdb = mysql /etc/dovecot-mysql.conf
first_valid_uid = 501
编辑 /etc/dovecot-mysql.conf 为以下内容
db_host = localhost
db_port = 3306
db_unix_socket = /var/lib/mysql/mysql.sock
db = postfix
db_user = postfix
db_passwd = postfix
db_client_flags = 0
default_pass_scheme = PLAIN-MD5
password_query = SELECT password FROM mailbox WHERE username = ’%u’
user_query = SELECT maildir, 501 AS uid, 502 AS gid FROM mailbox WHERE username = ’%u’
生成证书
# mkdir /etc/ssl/certs
# mkdir /etc/ssl private
# cd /usr/share/doc/dovecot-0.99.11/
# sh mkcert.sh
启动Dovecot 服务
# service dovecot start
# chkconfig --level 35 dovecot on
顺利的话,此时SMTP、SMTPS、POP3、POP3S已经配置完成。
补充:
-------------------
如果不需要SSL ,修改 protocols = imap pop3
以下应该要删除
ssl_disable = no
ssl_cert_file = /etc/ssl/certs/imapd.pem
ssl_key_file = /etc/ssl/private/imapd.pem
ssl_parameters_file = /var/run/dovecot/ssl-parameters.dat
---------------------
7.配置SquirrelMail网页邮件
最简单的方案,用浏览器访问 http://192.168.0.214/webmail 。
下面是手动安装方案设置以实现更多功能。
squirrelmail汉化包安装
#tar zxvf zh_CN-1.4.4-20050122.tar
./install
会提示:Please enter path to your squirrelmail installation:
我们输入squirrelmail的安装路径:/var/www/html/squirrelmail
在配置squirrelmail之前先下载三个插件:
Quota Usage Version 1.3
# wget http://www.squirrelmail.org/countdl.php?fileurl=http%3A%2F%2Fwww.squirrelmail.org%2Fplugins%2Fquota_usage-1.3-1.2.7.tar.gz
Compatibility Version 1.3
# wget http://www.squirrelmail.org/countdl.php?fileurl=http%3A%2F%2Fwww.squirrelmail.org%2Fplugins%2Fcompatibility-1.3.tar.gz
Change MySQL Password Version 3.2
# wget http://www.squirrelmail.org/countdl.php?fileurl=http%3A%2F%2Fwww.squirrelmail.org%2Fplugins%2Fchange_mysqlpass-3.2-1.2.8.tar.gz
把这三个插件解压到squirrelmail的plugin目录下并设置权限。
# tar -zxvf quota_usage-1.3-1.2.7.tar.gz -C /var/www/html/squirrelmail/plugins/
# tar -zxvf compatibility-1.3.tar.gz -C /var/www/html/squirrelmail/plugins/
# tar -zxvf change_mysqlpass-3.2-1.2.8.tar.gz -C /var/www/html/squirrelmail/plugins/
第一个插件是用来显示邮箱的使用情况的;第二个和第三个插件是用来修改密码的。
如果不想装这些插件,请跳过。
配置Quota Usage
# cd /var/www/html/squirrelmail/plugins/quota_usage
# cp config.php.sample config.php
配置Change MySQL Password
# cd /var/www/html/squirrelmail/plugins/change_mysqlpass
# cp config.php.sample config.php
# vi config.php
更改如下几个变量:
$mysql_database = 'postfix';
$mysql_table = 'mailbox';
$mysql_userid_field = 'username';
$mysql_password_field ='password';
$mysql_manager_id = 'postfix';
$mysql_manager_pw = 'postfix';
$mysql_unixcrypt = 0;
$mysql_MD5crypt = 1;密码是MD5加密的所以参数设置为1;
$use_ssl_for_password_change = 0;
配置squirrelmail
# cd /var/www/html/squirrelmail
# ./configure
进入10. Languages
把1. Default Language : 的en_US改成zh_CN。
进入8. Plugins,添加这三个插件
注意:
如果修改config.php参数还不行就安装zh_CN-1.4.4插件.
#tar zxvf zh_CN-1.4.4.gz /var/www/html/squirrelmail/
#./install
修改mail目录所属和权限:
#chown postfix.postfix /var/spool/mail
#chmod 766 /var/spool/mail
打开浏览器输入http://192.168.0.5/squirrelmail/,用b@d2.com登陆,你将会在屏幕的左上角看到邮箱的使用情况,??????
现在你还可以用选项中的change passwd修改你的密码了
不过这个模块是英文的,如果你想改成中文的,可以自己修改,squirrelmail网站上有介绍。或者请参考:
http://datastrategy.org/number5/archives/000241.html
由于安全原因,设置权限
# chown -R apache.apache /var/www/html/squirrelmail/data/
# chmod 730 -R /var/www/html/squirrelmail/data/
补充:-----------
SquirrelMail做为web平台,发现它的Drafts、Sent、Trash三个邮箱名还是英文的,需要汉化下更友好:
左边的邮箱目录在left_main.php中,打开它,增加一个function
#vi left_main.php
;
;
// --Add by szx 200709
function rename_subbox($mailboxstr, $oldname, $newname) {
$len0=strlen($mailboxstr);
$len1=strlen($oldname);
if (strpos($mailboxstr, $oldname, $len0-$len1)==$len0-$len1) {
return substr($mailboxstr, 0, $len0-$len1).$newname;
}
else
return $mailboxstr;
}
// --end of Anjo’s function
;
;
然后找到这一段
if ($special_color) {
$line .= "<font color=\"$color[11]\">";
}
if ( $mailbox == ’INBOX’ ) {
$line .= _("INBOX");
} else {
$line .= str_replace(array(’ ’,’<’,’>’),array(’ ’,’<’,’>’),$mailbox);
}
在它后面加上:
//-- By Anjo, for translate "Drafts", "Sent" and "Trush"
$line = rename_subbox($line, "Drafts", "草稿箱");
$line = rename_subbox($line, "Sent", "发件箱");
$line = rename_subbox($line, "Trash", "回收站");
注意:修改过配置文件left_main.php后建立的新邮件里没有重复的.旧的有.
-----------------
补充:-------------
squirrelmail允许的最大附件参数修改
#vi /etc/php.ini
max_execution_time=600 ;//改为600(增加处理脚本的时间限制)
max_input_time=600 ;//最大输出时间600s
memory_limit=32M ;//改为32M(这样才能转发10M以下的附件,太大的转发时无法打开页面)
post_max_size=32M ;//php可接收的post的大小
file_uploads=on ;//允许上传文件
upload_max_filesize=12M ;//写信界面显示的附件最大为12M
如果使用Postfix 作为后台邮件服务器,还需要修改main.cf
message_size_limit = 14336000 (附件大小,14M,实际为10M的文件)
virtual_mailbox_limit = 102400000 (邮箱空间100M)
virtual_create_maildirsize = yes
virtual_mailbox_extended = yes
注意:修改完设置后重启httpd 和postfix.
补充:---------
使用IE登入 SquirrelMail 下载中文附件时文件名乱码问题(其他浏览器无此问题)的解决:
#vi /var/www/html/squirrelmail/src/download.php
102 $filename = charset_encode($filename,$default_charset,false) //在这行下面添加下面的内容
103 $filename = iconv("gb2312","utf-8",$filename) //加入此行
---------------
8.配置杀毒、过滤SPAM功能
如果你打算将杀毒、过滤SPAM功能安排在各个客户端,以下是不必要操作的。
安装f-prot
从http://files.f-prot.com/files/linux-x86/fp-linux-ws.rpm ;下载
# rpm -ivh fp-linux-ws.rpm
该软件会自动更新病毒库,时间较长。
补充:冰岛F-Port杀毒软件,具有即时病毒扫描、定期病毒扫描、自定义病毒扫描等功能。
这是一个简单使用的抗滤过性病原体的工具,将透过发现及移动的病毒入侵中,保护你的资料。
可以发觉出数万不寻常及有害的计算机害虫。除了存取和要求扫描外,此工具也包含更新功能,
自动的得到最新的病毒码程序。任何新的病毒都可以直接的加入到查觉数据库及解毒数据库。更新及病毒扫描可以自动的排程执行。
启动SpamAssassin
# service spamassassin start
# chkconfig --level 35 spamassassin on
安装、配置MailScanner
# tar xzf MailScanner-4.48.4-2.rpm.tar.gz
# cd MailScanner-4.48.4-2
# ./install.sh
修改 /etc/MailScanner/MailScanner.conf
Run As User = postfix
Run As Group = postfix
Incoming Queue Dir = /var/spool/postfix/hold
Outgoing Queue Dir = /var/spool/postfix/incoming
MTA = postfix
Virus Scanners = f-prot
Always Include SpamAssassin Report = yes
Use SpamAssassin = yes
Required SpamAssassin Score = 4
SpamAssassin User State Dir = /var/spool/MailScanner/spamassassin
SpamAssassin Install Prefix = /usr/bin
SpamAssassin Local Rules Dir = /etc/MailScanner
让Postfix 调用MailScanner,在/etc/postfix/main.cf 加入以下一行
header_checks = regexp:/etc/postfix/header_checks
编辑/etc/postfix/header_checks 为以下内容
/^Received:/ HOLD
修正权限
# chown postfix.postfix /var/spool/MailScanner/incoming
# chown postfix.postfix /var/spool/MailScanner/quarantine
启用
# postfix stop
# service MailScanner start
# chkconfig --level 35 MailScanner on
注:--------
MailScanner 会自动启动Postfix。
mailscanner 安裝好以後他就會有一些附屬的小程式,
用來幫你更新安裝時所選用的防毒軟體的病毒碼,
然而我個人是比較偏好 f-prot 官方附的,
既然官方有的東西當然是用官方的好囉,
所以我把:/etc/cron.hourly/update_virus_scanners 備份起來然後刪除,
並且自己在 /etc/crontab 裡面加入這樣一行:
00 9 * * * root /usr/local/f-prot/tools/check-updates.pl -cron
就是每天早上九點用官方的更新程式去更新。
--------------
测试SpamAssassin
发一封邮件带如下内容,接收后,标题应该带有标记:
XJS*C4JDBQADN1.NSBN3*2IDNEN*GTUBE-STANDARD-ANTI-UBE-TEST-EMAIL*C.34X
测试f-prot
手动升级病毒库:# /usr/local/f-prot/tools/check-updates.pl
访问http://www.webmail.us/testvirus,申请寄一封带virus 的邮件寄到自己的邮箱
也可以到這邊下載安全的測試用病毒寄給自己試試看:
http://www.eicar.org/anti_virus_test_file.htm
9.配置完成