本文版权归作者所有,如其他个人、第三方网站或媒体报刊等需转载全文或节选,为支持我们的工作,请务必注明如下信息:
如果因此而给您带来麻烦,请您原谅,谢谢合作。本文档以2005-07-25的早期文档为蓝本,以ports系统为基础。所涉及软件全部是OpenSource软件,版权以GPL为主,作为企业应用没有任何版权/法律问题。
编写本文的初衷,是给那些希望快速架设邮件系统而不想过多了解复杂的系统知识的网管/用户,为了使软件之间的结合更紧密,部分软件的配置及测试方面进行了增强改进,因此本文的一些操作步骤作者不能保证在其他场合能完全适用,敬请注意。
本文假定读者是在FreeBSD 6.3平台上安装,并具有一定的Unix平台 /FreeBSD平台系统经验,懂得ports基本命令及常规的系统操作,如文件的删除,目录创建,改名,和vi编辑器的基本使用等。
ExtMail Solution 是一个基于优秀开源软件的电子邮件系统解决方案,核心部件包括了Postfix, Amavisd-new, ClamAV, ExtMail 和ExtMan, Courier系列软件。是一个功能相对比较齐全的免费电子邮件系统。以下是其主要的特性列表:
整个邮件解决方案由如下软件组成:
| 功能模块 | 内容 | 备注 |
| 操作系统(OS) | FreeBSD | FreeBSD是一个优秀的unix操作系统,基于宽松的BSD协议 |
| 邮件传输代理(MTA) | Postfix | 使用2.4.x,ports中的postfix已经是最新的2.4版 |
| 数据库/目录服务 | OpenLDAP 2.3.x | 可选MySQL或其他LDAP ,本文以OpenLDAP为蓝本 |
| 邮件投递代理(MDA) | maildrop 2.0.x | 支持过滤和强大功能 |
| Web帐户管理后台 | ExtMan-0.2.3 | 支持无限域名、无限用户 |
| POP3 服务器 | Courier-IMAP | 支持pop3/pop3s/imap/imaps,功能强大,可根据需要选择 |
| WebMail 系统 | ExtMail-1.0.3 | 支持多语言、全部模板化,功能基本齐全 |
| 防病毒软件(Anti-Virus) | ClamAV 0.92 | 最热门的开源杀毒软件 |
| 内容过滤器 | Amavisd-new 2.5.x | Content-Filter软件,支持与clamav/sa的挂接 |
| 内容级别的反垃圾邮件工具 | SpamAssassin | 著名的SA,可以支持大量规则,但速度较慢 |
| SMTP认证库 | Cyrus SASL 2.1x | 标准的SASL实现库,可以支持Courier authlib |
| 其他数据认证库 | Courier Authlib 0.60 | authlib是maildrop, courier-imap等服务的关键部件 |
| 日志分析及显示 | mailgraph_ext | 在ExtMan中已经包含了 |
| Web 服务器 | Apache 2.2.x | 最新版的apache服务器,默认支持ssl模块 |
| maillist软件 | Mailman2.1.x | 功能强大的邮件列表软件,支持基于web的管理 |
操作系统的安装建议参考FreeBSD Handbook,在此仅给出链接,以避免不必要的重复劳动:
1,磁盘分区
由于是邮件系统,相关的日志和queue都会保存在var分区内,因此var分区要有足够的空间。以一块硬盘73G/内存2G的服务器为例,可做如下分区:
/ 512m swap 4096m /var 55g /tmp 512m /usr 13g(剩下所有的空间尽量保证有10G左右)
2,软件包的选择
我们的邮件系统是要对外服务的,所以尽可能少的选择软件包,安装时建议选择Minimal,然后进入Custom选择doc,info,man,src即可。
1,编辑/etc/rc.conf确保有如下内容:
sshd_enable="YES" named_enable="YES" sendmail_enable="NONE"编辑/etc/resolv.conf确保第一条nameserver记录是127.0.0.1,这样本地DNS缓存才有效,类似如下:
domain extmail.org nameserver 127.0.0.1 nameserver 202.106.0.20然后执行如下命令:
2,根据硬件的配置重新编译内核,编译内核的办法参考FreeBSD Handbook,这里只给出链接:
根据你的情况执行
整个系统的安装全过程都要求以root身份执行。并能够访问Internet。
su - cd /root fetch http://www.extmail.org/docs/extmail_solution_freebsd/config.tar.gz tar xvfz config.tar.gz
pw group add vmail -g 1000 pw user add vmail -u 1000 -g 1000 -s /sbin/nologin -d /dev/null
mkdir -p /var/domains/extmail.org/test/Maildir/new mkdir -p /var/domains/extmail.org/test/Maildir/cur mkdir -p /var/domains/extmail.org/test/Maildir/tmp chown -R vmail:vmail /var/domains/ chmod -R 700 /var/domains/
由于在安装过程中要使用ExtMan里面带的文件,因此在此先安装ExtMan。安装时根据个人需要选择MySQL或者LDAP支持。
在本文中,我们使用OpenLDAP来作为认证中心,供其他程序使用 。 OpenLDAP在邮件系统中处于核心的地位,他存储着非常重要的用户信息(用户名,密码,Homedir等等)。 当然您也可以选择使用MySQL来做为认证中心,但是LDAP协议本身的特点(良好的查询性能)以及 邮件系统拥有的特性(认证信息的不经常变动),决定了LDAP更适合使用在邮件系统中,他能给我们带来更好的性能。
安装时选择:
TCP_WRAPPERS BDB DYNAMIC_BACKENDS SLUPD
编辑/etc/hosts或者修改你的DNS服务器,增加如下两个域名。
192.168.1.111 ldap.extmail.org 192.168.1.111 ldap-master.extmail.org
拷贝extmail.schema到OpenLDAP的schema目录
编辑/usr/local/etc/openldap/slapd.conf文件,内容类似如下:
include /usr/local/etc/openldap/schema/core.schema include /usr/local/etc/openldap/schema/cosine.schema include /usr/local/etc/openldap/schema/nis.schema include /usr/local/etc/openldap/schema/extmail.schema pidfile /var/run/openldap/slapd.pid argsfile /var/run/openldap/slapd.args modulepath /usr/local/libexec/openldap moduleload back_bdb database bdb suffix "dc=extmail.org" rootdn "cn=Manager,dc=extmail.org" rootpw secret directory /var/db/openldap-data index objectClass eq index mail,active,virtualDomain,mailLocalAddress eq,pres
编辑/usr/local/etc/openldap/ldap.conf文件,内容类似如下:
BASE dc=extmail.org URI ldap://ldap.extmail.org ldap://ldap-master.extmail.org:389 SIZELIMIT 12 TIMELIMIT 15 DEREF never
编辑/etc/rc.conf,增加如下一行
启动并初始化LDAP
cp /usr/local/etc/openldap/DB_CONFIG.example /var/db/openldap-data/DB_CONFIG /usr/local/etc/rc.d/slapd start ldapadd -x -D 'cn=Manager,dc=extmail.org' -w secret -f /usr/local/www/extman/docs/init.ldif
OpenLDAP配置完成
Courier-IMAP是一个提供POP3、IMAP服务的程序,能够很方便的配置使其支持加密协议POP3s、IMAPs。并良好的支持Maildir。
安装时选择(如果你使用MySQL认证,则选择AUTH_MYSQL):
TRASHQUOTA AUTH_LDAP
编辑/usr/local/etc/authlib/authdaemonrc文件,内容类似如下:
authmodulelist="authldap" authmodulelistorig="authldap" daemons=5 authdaemonvar=/var/run/authdaemond subsystem=mail DEBUG_LOGIN=0 DEFAULTOPTIONS="wbnodsn=1" LOGGEROPTS=""增加/var/run/authdaemond的执行权限,在FreeBSD系统下,其他用户默认没有执行权限
LDAP_URI ldap://ldap.extmail.org LDAP_PORT 389 LDAP_PROTOCOL_VERSION 3 LDAP_BASEDN o=extmailAccount,dc=extmail.org LDAP_BINDDN cn=Manager,dc=extmail.org LDAP_BINDPW secret LDAP_TIMEOUT 5 LDAP_MAIL mail LDAP_FILTER (active=1) LDAP_GLOB_UID vmail LDAP_GLOB_GID vmail LDAP_HOMEDIR homeDirectory LDAP_MAILROOT /var/domains LDAP_MAILDIRQUOTA mailQuota LDAP_CRYPTPW userPassword LDAP_DEREF never LDAP_TLS 0
RANDFILE = /usr/local/share/courier-imap/pop3d.rand [ req ] default_bits = 1024 encrypt_key = yes distinguished_name = req_dn x509_extensions = cert_type prompt = no [ req_dn ] C=CN ST=BJ L=Bei Jing O=Extmail OU=Extmail CN=extmail.org emailAddress=chifeng@gmail.com [ cert_type ] nsCertType = server执行如下命令产生供POP3s使用的证书
拷贝一份配置文件
RANDFILE = /usr/local/share/courier-imap/imapd.rand [ req ] default_bits = 1024 encrypt_key = yes distinguished_name = req_dn x509_extensions = cert_type prompt = no [ req_dn ] C=CN ST=BJ L=Bei Jing O=Extmail OU=Extmail CN=extmail.org emailAddress=chifeng@gmail.com [ cert_type ] nsCertType = server执行如下命令产生供IMAP使用的证书
编辑/etc/rc.conf文件,添加如下行:
courier_authdaemond_enable="YES" courier_imap_pop3d_enable="YES" courier_imap_imapd_enable="YES" courier_imap_pop3d_ssl_enable="YES" courier_imap_imapd_ssl_enable="YES"这5行的作用分别是在开机时:启动authdaemond,启动pop3d,启动imapd,启动pop3d-ssl,启动imapd-ssl。也可以使用命令行来控制这些进程的启动或者停止。
/usr/local/etc/rc.d/courier-authdaemond start/stop /usr/local/etc/rc.d/courier-imap-pop3d start/stop /usr/local/etc/rc.d/courier-imap-imapd start/stop /usr/local/etc/rc.d/courier-imap-pop3d-ssl start/stop /usr/local/etc/rc.d/courier-imap-imapd-ssl start/stop
MTA在邮件系统中处于非常重要的位置,他负责接收其他人给你发的信,并且负责把你的信转发到目的地。 选择一个靠谱的MTA对建立邮件来说意义重大,因此我们使用Postfix!! :-)。另外MTA部分在邮件系统中的开发 难度是最高的,起到的作用也是最大的,因此我们也常拿MTA的名字来称呼自己的邮件系统,比如:我常说我的邮件系统是Postfix。
安装时选择(如果你使用MySQL验证,可以选择MYSQL):
PCRE SASL2 TLS OPENLDAP VDA TEST
编辑/etc/rc.conf,增加如下一行
mv /usr/sbin/sendmail /usr/sbin/sendmail.bak cp /usr/local/sbin/sendmail /usr/sbin/sendmail编辑/etc/periodic.conf,加入如下内容,禁掉sendmail的自动维护。
daily_clean_hoststat_enable="NO" daily_status_mail_rejects_enable="NO" daily_status_include_submit_mailq="NO" daily_submit_queuerun="NO"执行如下命令
postalias /etc/aliases chown postfix:postfix /etc/opiekeys postconf -e 'mydomain = extmail.org' postconf -e 'myhostname = mail.extmail.org' postconf -e 'myorigin = $mydomain' postconf -e 'virtual_mailbox_base = /var/domains' postconf -e 'virtual_uid_maps=static:1000' postconf -e 'virtual_gid_maps=static:1000'
执行如下命令对查询表进行配置
cp /usr/local/www/extman/docs/ldap_virtual_* /usr/local/etc/postfix/ postconf -e 'virtual_alias_maps = $alias_maps, ldap:/usr/local/etc/postfix/ldap_virtual_alias_maps.cf' postconf -e 'virtual_mailbox_maps = ldap:/usr/local/etc/postfix/ldap_virtual_mailbox_maps.cf' postconf -e 'virtual_mailbox_domains = ldap:/usr/local/etc/postfix/ldap_virtual_domains_maps.cf'
编辑/usr/local/lib/sasl2/smtpd.conf
pwcheck_method:authdaemond log_level:3 mech_list:PLAIN LOGIN authdaemond_path:/var/run/authdaemond/socket对postfix做如下配置使支持smtp认证
postconf -e 'smtpd_sasl_auth_enable=yes' postconf -e 'broken_sasl_auth_clients = yes' postconf -e 'smtpd_sasl_local_domain = $myhostname'
此处的反垃圾邮件只是在MTA级的一些预防垃圾邮件的设置,可根据实际情况以及自己的需要进行调整。
postconf -e 'smtpd_helo_required=yes' postconf -e 'smtpd_delay_reject=yes' postconf -e 'disable_vrfy_command=yes' postconf -e 'smtpd_client_restrictions = check_client_access hash:/usr/local/etc/postfix/client_access' postconf -e 'smtpd_helo_restrictions=reject_invalid_hostname,check_helo_access hash:/usr/local/etc/postfix/helo_access' postconf -e 'smtpd_sender_restrictions = reject_non_fqdn_sender, reject_unknown_sender_domain, check_sender_access hash:/usr/local/etc/postfix/sender_access' postconf -e 'smtpd_recipient_restrictions=permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination, reject_non_fqdn_recipient, reject_unknown_recipient_domain' postconf -e 'smtpd_data_restrictions=reject_unauth_pipelining' postconf -e 'header_checks = regexp:/usr/local/etc/postfix/head_checks' postconf -e 'body_checks = regexp:/usr/local/etc/postfix/body_checks' touch /usr/local/etc/postfix/head_checks touch /usr/local/etc/postfix/body_checks touch /usr/local/etc/postfix/client_access touch /usr/local/etc/postfix/sender_access touch /usr/local/etc/postfix/helo_access postmap /usr/local/etc/postfix/head_checks postmap /usr/local/etc/postfix/body_checks postmap /usr/local/etc/postfix/client_access postmap /usr/local/etc/postfix/sender_access postmap /usr/local/etc/postfix/helo_access
生成证书,在这里默认私钥的访问密码为123qwe98,请根据自己的情况决定,以后可能会用得到。
mkdir -p /usr/local/etc/postfix/certs/CA cd /usr/local/etc/postfix/certs/CA mkdir certs crl newcerts private echo "01" > serial touch index.txt cp /usr/src/crypto/openssl/apps/openssl.cnf .编辑openssl.cnf,确认dir参数的值是/usr/local/etc/postfix/certs/CA。然后继续执行如下命令,并根据情况输入信息。输入信息类似如下:
Country Name (2 letter code) [AU]:CN State or Province Name (full name) [Some-State]:BJ Locality Name (eg, city) []:Bei Jing Organization Name (eg, company) [Internet Widgits Pty Ltd]:Extmail Organizational Unit Name (eg, section) []:extmail Common Name (eg, YOUR name) []:extmail.org Email Address []:chifeng@gmail.com命令如下:
openssl req -new -x509 -keyout private/cakey.pem -out cacert.pem -days 3650 -config openssl.cnf openssl req -nodes -new -x509 -keyout mykey.pem -out myreq.pem -days 3650 -config openssl.cnf openssl x509 -x509toreq -in myreq.pem -signkey mykey.pem -out tmp.pem openssl ca -config openssl.cnf -policy policy_anything -out mycert.pem -infiles tmp.pem rm tmp.pem cp cacert.pem mycert.pem mykey.pem /usr/local/etc/postfix/certs/ cd /usr/local/etc/postfix/certs/ chown root:wheel cacert.pem mycert.pem chown root:postfix mykey.pem chmod 755 cacert.pem chmod 644 mycert.pem chmod 440 mykey.pem ln -s cacert.pem `openssl x509 -noout -hash < cacert.pem `.0
配置postfix支持TLS
postconf -e 'smtpd_use_tls=yes' postconf -e 'smtpd_tls_auth_only=no' postconf -e 'smtp_tls_CAfile = /usr/local/etc/postfix/certs/cacert.pem' postconf -e 'smtp_tls_cert_file = /usr/local/etc/postfix/certs/mycert.pem' postconf -e 'smtp_tls_key_file = /usr/local/etc/postfix/certs/mykey.pem' postconf -e 'smtpd_tls_CAfile=/usr/local/etc/postfix/certs/cacert.pem' postconf -e 'smtpd_tls_cert_file=/usr/local/etc/postfix/certs/mycert.pem' postconf -e 'smtpd_tls_key_file=/usr/local/etc/postfix/certs/mykey.pem' postconf -e 'smtpd_tls_received_header=yes' postconf -e 'smtpd_tls_loglevel=3' postconf -e 'smtpd_starttls_timeout=60s'
配置master.cf,添加如下信息
smtps inet n - n - - smtpd -o smtpd_tls_wrappermode=yes -o smtpd_sasl_auth_enable=yes -o smtpd_client_restrictions=permit_sasl_authenticated,reject
MDA-邮件分发代理。他从MTA那儿拿到信,然后存入您的邮箱里面。MDA在投递邮件到您的目录里面时,会先对邮件进行一些过滤, 过滤规则会根据您的配置文件来进行。1,进行全局过滤设置,读取/etc/maildroprc(Linux)或者/usr/local/etc/maildroprc(BSD), 根据配置该配置文件执行相应的操作,影响到所有用户;2,根据每个用户的配置进行过滤,读取$HOME/.mailfilter,根据每个用户 的设置进行相应的操作,仅影响单个用户。基于这样的特点,WEBMAIL通过编辑$HOME/.mailfilter可以实现一些特色化的东西, 比如:黑白名单、SPAM自动转入垃圾邮件夹、SMS提醒等等。
#maildrop unix - n n - - pipe
# flags=DRhu user=vmail argv=/usr/local/bin/maildrop -d ${recipient}
maildrop unix - n n - - pipe
flags=DRhu user=vmail:vmail argv=/usr/local/bin/maildrop -w 90 -d ${recipient}
postconf -e 'virtual_transport=maildrop:' postconf -e 'maildrop_destination_concurrency_limit=1' postconf -e 'maildrop_destination_recipient_limit=1'
logfile "/var/domains/maildrop.log"
#logfile "/var/log/maildrop.log"
TEST="/bin/test -f"
#
# Check for custom user .mailfilter file
#
CUSTOM_FILTER="$HOME/.mailfilter"
`$TEST $CUSTOM_FILTER && exit 1 || exit 0`
if ( $RETURNCODE == 0 )
{
to "$HOME/Maildir"
}
User vmail Group vmail
NameVirtualHost *:80
<VirtualHost *:80>
ServerName mail.extmail.org
DocumentRoot /usr/local/www/extmail/html/
ScriptAlias /extmail/cgi /usr/local/www/extmail/cgi/
Alias /extmail /usr/local/www/extmail/html/
ScriptAlias /extman/cgi "/usr/local/www/extman/cgi/"
Alias /extman "/usr/local/www/extman/html/"
<Location "/extman/cgi">
SetHandler cgi-script
Options +ExecCGI
AllowOverride All
</Location>
<Directory "/usr/local/www">
AllowOverride None
Options None
Order allow,deny
Allow from all
</Directory>
# SuexecUserGroup vmail vmail
</VirtualHost>
mkdir /usr/local/etc/apache22/certs/ cp /usr/local/etc/postfix/certs/*.pem /usr/local/etc/apache22/certs/编辑文件/usr/local/etc/apache22/Includes/extmail-ssl.conf,内容如下
Listen 443
AddType application/x-x509-ca-cert .crt
AddType application/x-pkcs7-crl .crl
SSLPassPhraseDialog builtin
SSLSessionCache shmcb:/var/run/ssl_scache(512000)
SSLSessionCacheTimeout 300
SSLMutex file:/var/run/ssl_mutex
<VirtualHost _default_:443>
DocumentRoot "/usr/local/www/extmail/html"
ServerName mail.extmail.org:443
ScriptAlias /extmail/cgi /usr/local/www/extmail/cgi/
Alias /extmail /usr/local/www/extmail/html/
ScriptAlias /extman/cgi "/usr/local/www/extman/cgi/"
Alias /extman "/usr/local/www/extman/html/"
ServerAdmin chifeng@gmail.com
ErrorLog /var/log/httpd-error.log
TransferLog /var/log/httpd-access.log
SSLEngine on
SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL
#SSLCertificateFile /usr/local/etc/apache22/server.crt
#SSLCertificateKeyFile /usr/local/etc/apache22/server.key
SSLCertificateFile /usr/local/etc/apache22/certs/mycert.pem
SSLCertificateKeyFile /usr/local/etc/apache22/certs/mykey.pem
<FilesMatch "\.(cgi|shtml|phtml|php)$">
SSLOptions +StdEnvVars
</FilesMatch>
<Directory "/usr/local/www/apache22/cgi-bin">
SSLOptions +StdEnvVars
</Directory>
BrowserMatch ".*MSIE.*" \
nokeepalive ssl-unclean-shutdown \
downgrade-1.0 force-response-1.0
CustomLog /var/log/httpd-ssl_request.log \
"%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"
#SuexecUserGroup vmail vmail
</VirtualHost>
重起一下apache
Extmail 是一个以perl语言编写,面向大容量/ISP级应用,免费的高性能Webmail软件。完整的支持Maildir++, 多字符、多语言支持,支持模版技术、方便的为自己定制界面等等。
SYS_CONFIG = /usr/local/www/extmail/ SYS_LANGDIR = /usr/local/www/extmail/lang SYS_TEMPLDIR = /usr/local/www/extmail/html SYS_SESS_DIR = /var/tmp/extmail/ SYS_LOG_TYPE = file SYS_USER_LANG = zh_CN SYS_USER_CHARSET = utf-8 SYS_AUTH_TYPE = ldap SYS_MAILDIR_BASE = /var/domains SYS_LDAP_BASE = dc=extmail.org SYS_LDAP_RDN = cn=Manager,dc=extmail.org SYS_LDAP_PASS = secret SYS_LDAP_HOST = ldap.extmail.org SYS_LDAP_ATTR_USERNAME = mail SYS_LDAP_ATTR_DOMAIN = virtualDomain SYS_LDAP_ATTR_PASSWD = userPassword SYS_LDAP_ATTR_QUOTA = mailQuota SYS_LDAP_ATTR_NDQUOTA = netdiskQuota SYS_LDAP_ATTR_HOME = homeDirectory SYS_LDAP_ATTR_MAILDIR = mailMessageStore执行如下命令
mkdir /var/tmp/extmail chown vmail:vmail /var/tmp/extmail/ chmod 700 /var/tmp/extmail touch /var/log/extmail.log chown vmail:vmail /var/log/extmail.log chown -R vmail:vmail /usr/local/www/extmail/
ExtMan是一个基于Web的邮件帐号管理系统。可以通过他来管理邮件帐号、管理员帐号和域名等,默认的超级用户是 root@extmail.org,密码是extmail*123* ExtMan还集成了mailgraph,可以ExtMan内看到整个邮件系统的相关状态流量图。 使用ExtMan来管理您的邮件系统将使工作变得更加轻松。之前我们已经安装了ExtMan,在此直接配置webman.cf即可。
SYS_CONFIG = /usr/local/www/extman/ SYS_LANGDIR = /usr/local/www/extman/lang SYS_TEMPLDIR = /usr/local/www/extman/html SYS_MAILDIR_BASE = /var/domains SYS_SESS_DIR = /var/tmp/extman/ SYS_PSIZE = 50 SYS_LANG = zh_CN SYS_DEFAULT_MAXQUOTA = 10000 SYS_DEFAULT_MAXALIAS = 10000 SYS_DEFAULT_MAXUSERS = 1000 SYS_DEFAULT_MAXNDQUOTA = 100 SYS_BACKEND_TYPE = ldap SYS_LDAP_BASE = dc=extmail.org SYS_LDAP_RDN = cn=Manager,dc=extmail.org SYS_LDAP_PASS = secret SYS_LDAP_HOST = localhost SYS_LDAP_ATTR_USERNAME = mail SYS_LDAP_ATTR_PASSWD = userPassword
mkdir /var/lib mkdir /var/tmp/extman/ chown –R vmail:vmail /var/tmp/extman/ chmod 700 /var/tmp/extman/ chmod 600 /usr/local/www/extman/webman.cf unlink /usr/local/www/extman/libs/HTML/KTemplate.pm cp /usr/local/www/extmail/libs/HTML/KTemplate.pm /usr/local/www/extman/libs/HTML/
cd /usr/ports/databases/rrdtool && make install clean cd /usr/ports/devel/p5-File-Tail && make install clean cd /usr/ports/devel/p5-Time-HiRes && make install clean安装mailgraph_ext
cp -Rfp /usr/local/www/extman/addon/mailgraph_ext/ /usr/local/mailgraph_ext /usr/local/mailgraph_ext/mailgraph-init start /usr/local/mailgraph_ext/qmonitor-init start
到目前为止,一个基本的邮件系统已经安装完成,他支持了smtp,pop3,imap,webmail。并且支持对应的SSL加密smtps,pop3s,imaps,https。
telnet localhost 110 Trying 127.0.0.1... Connected to localhost.localdomain (127.0.0.1). Escape character is '^]'. +OK Hello there. user test@extmail.org +OK Password required. pass test +OK logged in. list +OK POP3 clients that break here, they violate STD53. . quit +OK Bye-bye. Connection closed by foreign host.
通过以下命令获得test@extmail.org的用户名及密码的BASE64编码:
perl -e 'use MIME::Base64; print encode_base64("test\@extmail.org")'
dGVzdEBleHRtYWlsLm9yZw==
perl -e 'use MIME::Base64; print encode_base64("test")'
dGVzdA==
然后本机测试,其过程如下
telnet localhost 25 Trying 127.0.0.1... Connected to localhost.localdomain (127.0.0.1). Escape character is '^]'. 220 mail.extmail.org ESMTP Postfix - by extmail.org ehlo demo.domain.tld 250-mail.extmail.org 250-PIPELINING 250-SIZE 10240000 250-VRFY 250-ETRN 250-AUTH LOGIN PLAIN 250-AUTH=LOGIN PLAIN 250-ENHANCEDSTATUSCODES 250-8BITMIME 250 DSN auth login 334 VXNlcm5hbWU6 dGVzdEBleHRtYWlsLm9yZw== 334 UGFzc3dvcmQ6 dGVzdA== 235 2.0.0 Authentication successful quit 221 2.0.0 Bye最后出现235 Authentication Successful 表明认证成功了。
mail# telnet localhost 25 Trying ::1... Trying 127.0.0.1... Connected to localhost.localhostadmin. Escape character is '^]'. 220 mail.extmail.org ESMTP Postfix ehlo localhost 250-mail.extmail.org 250-PIPELINING 250-SIZE 10240000 250-ETRN 250-STARTTLS 250-AUTH LOGIN PLAIN 250-AUTH=LOGIN PLAIN 250-ENHANCEDSTATUSCODES 250-8BITMIME 250 DSN STARTTLS 220 2.0.0 Ready to start TLS ^] telnet> q Connection closed.
telnet连接本机的993,995端口出现如下提示:
telnet localhost 993 Trying ::1... telnet: connect to address ::1: Connection refused Trying 127.0.0.1... Connected to localhost.localhostadmin. Escape character is '^]'. ^] telnet> q Connection closed. telnet localhost 995 Trying ::1... telnet: connect to address ::1: Connection refused Trying 127.0.0.1... Connected to localhost.localhostadmin. Escape character is '^]'. ^] telnet> q Connection closed.也可以在OutLook中如下设置进行测试
http://mail.extmail.org https://mail.extmail.org
http://mail.extmail.org/extman https://mail.extmail.org/extman
amavisd-new是一个类似Mailscanner的解信的程序,他可以调用外部的杀毒/反垃圾来对邮件进行过滤,很方便的实现 病毒过滤,内容过滤。amavisd和mailscanner的不同在于,他使用SMTP协议通信,处理完后再回传给Postfix, 整个过程不会对Postfix造成任何结构上的影响。Mailscanner必须监视Postfix的Hold队列,采用比较暴力的做法。
安装时选择BDB MILTER SPAMASSASSIN FILE RAR UNRAR ARJ LHA ARC CAB RPM ZOO UNZOO LZOP FREEZE P7ZIP
amavisd_enable="YES"
$max_servers = 10;
$sa_spam_subject_tag = '[SPAM] ';
$mydomain = 'mail.extmail.org';
$myhostname = 'mail.extmail.org';
@local_domains_maps = qw(.);
$sa_tag_level_deflt = undef;
$sa_tag2_level_deflt = 5.0;
$sa_kill_level_deflt = 5.0;
$final_virus_destiny = D_DISCARD;
$final_banned_destiny = D_DISCARD;
$final_spam_destiny = D_DISCARD;
$virus_admin = "postmaster\@$mydomain";
$mailfrom_notify_admin = "postmaster\@$mydomain";
$mailfrom_notify_recip = "postmaster\@$mydomain";
$mailfrom_notify_spamadmin = "postmaster\@$mydomain";
@whitelist_sender_maps = read_hash("$MYHOME/white.lst");
@blacklist_sender_maps = read_hash("$MYHOME/black.lst");
$spam_quarantine_to = "spam\@$mydomain";
$virus_quarantine_to = "virus\@$mydomain";
$banned_quarantine_to = "spam\@$mydomain";
$hdrfrom_notify_admin = "Content Filter ";
执行如下操作
touch /var/amavis/white.txt touch /var/amavis/black.txt chown –R vscan:vscan /var/amavis/
smtp-amavis unix - - n - 4 smtp
-o smtp_data_done_timeout=1200
-o smtp_send_xforward_command=yes
-o disable_dns_lookups=yes
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_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
-o receive_override_options=
修改content_filter ,receive_override_options这两项,禁止地址展开/影射,否则遇到别名时会产生冗余邮件。
但是打开这一项receive_override_options后会和邮件列表程序相冲突,导致邮件列表的aliases不能打开。:(所以如果使用了邮件列表,则不要设置receive_override_options这一项。
postconf -e 'content_filter = smtp-amavis:[localhost]:10024' postconf -e 'receive_override_options = no_address_mappings'
Clamav是一个比较好的杀毒程序,他被amavisd调用,可以查杀所有常见的病毒,在邮件系统中我们用它来对邮件进行查毒,
ARC ARJ LHA UNZOO UNRAR
clamav_clamd_enable="YES" clamav_freshclam_enable="YES"修改/usr/local/etc/amavisd.conf,增加如下内容,使amavis-new对clamav的支持
['ClamAV-clamd',
\&ask_daemon, ["CONTSCAN {}\n", "/var/run/clamav/clamd"],
qr/\bOK$/, qr/\bFOUND$/,
qr/^.*?: (?!Infected Archive)(.*) FOUND$/ ],
chown –R vscan:vscan /var/run/clamav/ chown –R vscan:vscan /var/log/clamav/ chown –R vscan:vscan /var/db/clamav/启动clamav。clamav有2个daemon需要启动,一个是用来查病毒的clamd,另外一个是用来更新病毒库的freshclam,他们分别通过如下脚本启动。
/usr/local/etc/rc.d/clamav-clamd start /usr/local/etc/rc.d/clamav-freshclam start
开源软件中最好的内容过滤程序,做内容过滤的必选。
report_safe 1 use_bayes 0 auto_learn 0 bayes_auto_expire 1 skip_rbl_checks 1 use_razor2 0 use_dcc 0 use_pyzor 0 dns_available no lock_method flock
#!/bin/sh cd /tmp/ fetch -q http://www.ccert.edu.cn/spam/sa/Chinese_rules.cf mv Chinese_rules.cf /usr/local/share/spamassassin/ /usr/local/etc/rc.d/amavisd forcerestart > /dev/null增加执行权限
/usr/local/etc/rc.d/clamav-clamd restart /usr/local/etc/rc.d/amavisd restart /usr/local/etc/rc.d/postfix restart
telnet localhost 25 Trying 127.0.0.1... Connected to localhost.localdomain (127.0.0.1). Escape character is '^]'. 220 mail.extmail.org ESMTP Postfix - by extmail.org helo localhost 250 mail.extmail.org mail from:<chifeng@gmail.com> 250 2.1.0 Ok rcpt to:<test@extmail.org> 250 2.1.5 Ok data 354 End data with . X5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H* . 250 2.0.0 Ok: queued as BC24E85260 quit 221 2.0.0 Bye Connection closed by foreign host.maillog中出现类似如下日志则说明clamav和amavid-new正常工作
Aug 3 15:42:41 mail amavis[730]: (00730-01) Blocked INFECTED (Eicar-Test-Signature), LOCAL [127.0.0.1] [127.0.0.1]
Mailman是一个比较好的邮件列表程序,功能非常强大,提供完美的Web端,权限可以分散管理,多个开源组织都在使用。
POSTFIX CHINESE
touch /usr/local/mailman/data/aliases touch /usr/local/mailman/data/virtual-mailman postconf -e 'recipient_delimiter=+' postconf -e 'alias_maps=hash:/etc/aliases, hash:/usr/local/mailman/data/aliases' postalias /usr/local/mailman/data/aliases postconf -e 'virtual_alias_maps = ldap:/usr/local/etc/postfix/ldap_virtual_alias_maps.cf, hash:/usr/local/mailman/data/virtual-mailman' postalias /usr/local/mailman/data/aliases postmap /usr/local/mailman/data/virtual-mailman postconf -e 'default_privs = mailman' postfix reload
cd /usr/local/mailman bin/genaliases chown -R vmail:mailman /usr/local/mailman/data/aliases* chown -R vmail:mailman /usr/local/mailman/data/virtual-mailman* chmod 664 /usr/local/mailman/data/aliases* chmod 664 /usr/local/mailman/data/virtual-mailman* cp -Rfp icons/ cgi-bin/icons cp /usr/local/www/icons/powerlogo.gif cgi-bin/icons/修改管理员密码,在这里我默认为123qwe98
MTA = 'Postfix'
POSTFIX_STYLE_VIRTUAL_DOMAINS = ['lists.extmail.org']
add_virtualhost('lists.extmail.org','lists.extmail.org')
DEFAULT_EMAIL_HOST = 'lists.extmail.org'
DEFAULT_URL_HOST = 'lists.extmail.org'
DEFAULT_SERVER_LANGUAGE = 'zh_CN'
在文件/usr/local/etc/apache22/Includes/extmail.conf中添加如下内容。
<VirtualHost *:80>
ServerName lists.extmail.org
DocumentRoot /usr/local/mailman/cgi-bin/
ScriptAlias /mailman "/usr/local/mailman/cgi-bin/"
Alias /pipermail /usr/local/mailman/archives/public/
<Directory "/usr/local/mailman/archives/public/">
AddDefaultCharset Off
</Directory>
<Directory "/usr/local/mailman">
Options FollowSymLinks ExecCGI
AllowOverride None
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
http://lists.extmail.org/mailman/admin/mailman http://lists.extmail.org/mailman/listinfo/mailman http://lists.extmail.org/mailman/create更强大的功能在登陆列表的web管理界面后你能看到,比如调整显示界面为中文等等。
如果你的邮件服务器只打算使用pop3功能不打算使用更多,你可以如下这么做: 修改/etc/rc.conf,注释掉pop3s,imap,imaps对应的启动选项
courier_imap_pop3d_enable="YES" #courier_imap_imapd_enable="YES" #courier_imap_pop3d_ssl_enable="YES" #courier_imap_imapd_ssl_enable="YES"然后停止正在运行中的pop3s,imap,imaps进程
/usr/local/etc/rc.d/courier-imap-imapd-ssl.sh forcestop /usr/local/etc/rc.d/courier-imap-imapd.sh forcestop /usr/local/etc/rc.d/courier-imap-pop3d-ssl.sh forcestop
修改/usr/local/etc/postfix/master.cf,注释掉对应的smtps选项
#smtps inet n - n - - smtpd # -o smtpd_tls_wrappermode=yes # -o smtpd_sasl_auth_enable=yes # -o smtpd_client_restrictions=permit_sasl_authenticated,reject然后重新加载以下postfix
有时候为了安全,我们可能只能使用https,那么在用户连http://mail.extmail.org的时候,就要自动重定向到https://mail.extmail.org 做起来很简单,修改我们虚拟主机配置文件(extmail.conf),在虚拟主机配置内添加如下一条指令即可
启动postfix
postqueue –p mailq postqueue –p |tail修复队列以及任何权限错误
通过此文档,读者应该能够较容易地架设一个功能较齐全的电子邮件系统。当使用一段时间后,用户将发现这个系统还有很多比较粗糙的地方,不尽人意。日后,本文档将继续保持更新,逐步将一些高级的设置方法公布出来,争取ExtMail Solution更加完整,力求完美。