我们的目标是:用postfix为主建立一套邮件系统,然后用extmail&extman对这套邮件系统实现web管理。

官方文档:http://www.extmail.org/docs/extmail_solution_linux/

前情提要:

服务器ip:192.168.0.8
apache安装在/usr/local/apache,运行用户和组都叫www,uid和gid都是48
mysql安装在/usr/local/mysql,用户名root,密码sa,sock文件在/tmp/mysql.sock
extmail&extman将要被安装在/data/htdocs/extsuite目录下
mail的保存目录是/var/spool/mail

文中类似

cat >>xxoo<<’EOF’ xxx ooo 000 EOF

这的意思是用shell的管道和cat来建立一个新文件,或向已存在的文件追加一段文字,详尽的说明在这里。
要是你更信任vi或者emacs,复制中间的文本xxxooo000就行了。

前情提要介绍完毕,下面开始正文

一、建立一下必要的帐号和目录

groupadd postfix -g 2001
groupadd postdrop -g 2002
groupadd vmail -g 2003
useradd postfix -u 2002 -g postfix -G postdrop
useradd vmail -g 2002 -s /sbin/nologin

-G是属于多个组的意思了

建立保存email的目录

mkdir -pv /var/spool/mail
chown apache:apache /var/spool/mail
俺的apache是用apache用户跑的,所以归apache所有,否则extman不能自动建立域目录和用户目录。
不过postfix和courier-imap也将要对它进行操作,嗯…. 权限是个大问题,先放一边,要先能跑起来再说,”好读书不求甚解” T_T

二、extmail和extman

下载extmail和extman,其中extman的docs目录中有写得很好的和mysql进行关联postfix配置文件,自己敲多累啊。

将它们解包到/var/www/extsuite目录下,cd进入extman的docs目录,执行

/usr/local/mysql/bin/mysql -uroot -pshopex < extmail.sql /usr/local/mysql/bin/mysql -uroot -pshopex < init.sql

或者登陆mysql控制台,然后用source命令导入数据。

修改apache的配置文件,让它们跑起来,哈哈,我们先造好车外壳,等下再打造发动机,轮子…..
cat >> /usr/local/apache/conf/httpd.conf< NameVirtualHost *:80 ServerName mail.zzzrc.com DocumentRoot /data/htdocs/extsuite/extmail/html/ ScriptAlias /extmail/cgi /data/htdocs/extsuite/extmail/cgi ScriptAlias /extman/cgi /data/htdocs/extsuite/extman/cgi Alias /extmail /data/htdocs/extsuite/extmail/html Alias /extman /data/htdocs/extsuite/extman/html #SuexecUserGroup vuser vgroup AllowOverride None Options None Order allow,deny Allow from all Options +ExecCGI Options +ExecCGI EOF 如果想用fastcgi方式跑perl,推荐用nginx代替apache。nginx运行perl的配置方法请参考这里。下面给一个针对extman&extmail的nginx配置参考: cat >>/usr/local/nginx/conf/nginx.conf< server { listen 80; server_name mail.imox.me ; index index.html index.htm index.cgi; root /data/htdocs/extsuite/extmail/html; location ~ /(extmail|extman)/cgi/.*.cgi? { root /data/htdocs/extsuite; include perl_fcgi.conf; } location /extmail/ { alias /data/htdocs/extsuite/extmail/html/; } location /extman/ { alias /data/htdocs/extsuite/extman/html/; } access_log /var/log/nginx/mail.imox.me.log access; } EOF 接下来需要修改extmail和extmail的配置文件webmail.cf、webman.cf改 cd /data/htdocs/extsuite/extmail sed \'s//var/www//data/htdocs/\' webmail.cf.default > webmail.cf
sed -i ’s//home/domains//var/spool/mail/’ webmail.cf
sed -i ’s/db_user/root/’ webmail.cf
sed -i ’s/db_pass/shopex/’ webmail.cf
sed -i ’s//var/lib/mysql//tmp/’ webmail.cf
第一个sed是修正extmail的存放目录,和web服务器定义的文档路径一致。
第二个sed是修正邮件的存放的跟目录,要和下面安装的postfix设置的保持一致。
第三 ~ 第五个sed是修正mysql的连接帐号

下面是修改extman的,extman负责邮箱管理

cd data/htdocs/extsuite/extman
sed -i ’s//var/www//data/htdocs/’ webman.cf
sed -i ’s//home/domains//var/spool/mail/’ webman.cf
sed -i ’s/db_user/root/’ webman.cf
sed -i ’s/db_pass/shopex/’ webman.cf
sed -i ’s//var/lib/mysql//tmp/’ webman.cf
sed -i ’s/SYS_DEFAULT_UID = 1000/SYS_DEFAULT_UID = 48/’ webman.cf
sed -i ’s/SYS_DEFAULT_GID = 1000/SYS_DEFAULT_GID = 48/’ webman.cf
LDAP的统统注释掉了,最后给extman创建保持session的目录

mkdir -pv /tmp/extman && chmod 0777 /tmp/extman
建邮件存放目录

pushd /data/htdocs/extsuite/extman/tools
./maildirmake.pl /var/spool/mail/extmail.org/postmaster/Maildir
chown -R www:www /var/spool/mail/extmail.org
popd
改一下本地的hosts文件,用浏览器打开http://mail.imox.me应该可以看到extmail的界面。

http://mail.zzzforerver.com/extman/可以登录邮件系统管理后台,初始账号是:

root@extmail.org
extmail*123*

如果页面提示缺少perl的模块,根据extmail的错误提示,一一补齐:
perl -MCPAN -e shell 
或者上http://www.cpan.org/找也很快,安装方法都很简单

perl Makefile.PL && make && make test && make install

Unix::Syslog not found, please install it first! (in cleanup) Undefined subroutine &Ext::Logger::do_closelog called at /var/www/extsuite/extmail/libs/Ext/Logger.pm line 86.
报这个错误是缺少syslog
安装方法
perl -MCPAN -e shell
cpan>install Unix::Syslog

或者用 cpan -i Unix::Syslog 安装都一样

Can’t locate DBI.pm in @INC (@INC contains: /var/www/extsuite/extman/libs /usr/lib/perl5/site_perl/5.8.8/i386-linux-thread-multi /usr/lib/perl5/site_perl/5.8.8 /usr/lib/perl5/site_perl /usr/lib/perl5/vendor_perl/5.8.8/i386-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.8 /usr/lib/perl5/vendor_perl /usr/lib/perl5/5.8.8/i386-linux-thread-multi /usr/lib/perl5/5.8.8 .) at /var/www/extsuite/extman/libs/Ext/Mgr/MySQL.pm line 13. BEGIN failed–compilation aborted at /var/www/extsuite/extman/libs/Ext/Mgr/MySQL.pm line 13. Compilation failed in require at /var/www/extsuite/extman/libs/Ext/Mgr.pm line 37.

缺少DBI DBD
Extman登录进去就报下面这个错:
Need AUTH code! at /var/www/extsuite/extman/libs/Ext/Cmd/Client.pm line 12.
解决办法是在webman.cf里增加一行:
SYS_CMDSERVER_AUTHCODE = eExXtTMmAaiIlL

然后浏览“系统信息”的时候提示“Peer info not know”,下面信息全无。
又在webman.cf里增加一行:
SYS_CMDSERVER_SOCK = /var/run/extmail/cmdserver.sock

初始化cpan的时候一路回车,到这里的时候写上相应的,和选择源
Parameters for the ‘perl Makefile.PL’ command?
Typical frequently used settings:

PREFIX=~/perl non-root users (please see manual for more hints)

Your choice: []
Parameters for the ‘make’ command?
Typical frequently used setting:

-j3 dual processor system

Your choice: [] -j3
Parameters for the ‘make install’ command?
Typical frequently used setting:

UNINST=1 to always uninstall potentially conflicting files

Your choice: [-j3] UNINST=1

没有底层程序的支援,现在这个webmail啥都干不了,下面开始打造实际干活的东东。

编译比较搞的地方也就是指定sasl库和mysql库的地址了,只要对了一般就不会有问题,我的MySQL是编译安装的

-I/usr/local/mysql/include
-L/usr/local/mysql/lib

ls一下上面的目录保证分别有.h和.so文件就可以了
三、 courier-authlib

官方网址:http://www.courier-mta.org/download.php#authlib

./configure –without-authuserdb –without-authpam –without-authldap –without-authpwd –without-authshadow –without-authvchkpw –without-authpgsql –without-authcustom –with-authmysql –with-mysql-libs=/usr/local/lib/mysql –with-mysql-includes=/usr/local/include/mysql –with-mailuser=postfix –with-mailgroup=postfix –with-redhat
这个包要在非root的环境下编译,configure和make以后再切换到root环境下make install
配置authdaemon进程
cat >>/usr/local/etc/authlib/authdaemonrc< authmodulelist="authmysql" authmodulelistorig="authmysql" daemons=1 authdaemonvar=/var/spool/authdaemon DEBUG_LOGIN=0 DEFAULTOPTIONS="" LOGGEROPTS="" EOF 配置authdaemon和MySQL的关联 cat >>/usr/local/etc/authlib/authmysqlrc< MYSQL_SERVER 127.0.0.1 MYSQL_SOCKET /tmp/mysql.sock MYSQL_DATABASE extmail MYSQL_USERNAME extmail MYSQL_PASSWORD extmail MYSQL_USER_TABLE mailbox MYSQL_LOGIN_FIELD username MYSQL_CRYPT_PWFIELD password MYSQL_CLEAR_PWFIELD clearpwd MYSQL_UID_FIELD uidnumber MYSQL_GID_FIELD gidnumber MYSQL_HOME_FIELD homedir MYSQL_MAILDIR_FIELD maildir MYSQL_NAME_FIELD name MYSQL_QUOTA_FIELD quota MYSQL_WHERE_CLAUSE active=\'1\' #DEFAULT_DOMAIN clans.cn EOF 启动courier-authlib /usr/local/sbin/authdaemond start 验证一下 : [root@zzz sbin]# pwd /usr/local/sbin [root@zzz sbin]# authtest -s login postmaster@extmail.org Authentication succeeded. Authenticated: postmaster@extmail.org (uid 1000, gid 1000) Home Directory: extmail.org/postmaster Maildir: extmail.org/postmaster/Maildir/ Quota: 104857600S Encrypted Password: $1$phz1mRrj$3ok6BjeaoJYWDBsEPZb5C0 Cleartext Password: (none) Options: (none) [root@zzz sbin]# s login是要测试登陆验证服务的一下,postmaster@extmail.org要和extmail库中mailbox表username字段的值对应,并且clearpw是空白。如果成功说明我们的authmysqlrc是正确,否则就要在authdaemonrc中将DEBUG_LOGIN的值设为5,然后在/var/log中看mail.log中的错误提示信息上Google查原因。 安装maildrop ./configure --enable-sendmail=/usr/sbin/sendmail --enable-trusted-users=\'root vmail\' --enable-syslog=1 --enable-maildirquota --enable-syslog=1 --enable-maildirquota --enable-maildrop-uid=2002 --enable-maildrop-gid=2001 --with-trashquota --with-dirsync CPPFLAGS="-D_FILE_OFFSET_BITS=64" vi /etc/maildroprc logfile "/var/mailbox/maildrop.log" to "$HOME/Maildir" 三、cyrus-sasl-2.x 官方地址:http://ftp.andrew.cmu.edu/pub/cyrus-mail/ ./configure --enable-plain --enable-cram --enable-digest --enable-login --enable-sql --disable-anon --disable-ntlm --disable-gssapi --disable-krb4 --disable-otp --disable-srp --disable-srp-setpass --with-authdaemond=/usr/local/var/spool/authdaemon/socket --with-mysql=/usr/local/mysql --with-mysql-includes=/usr/local/mysql/include --with-mysql-libs=/usr/local/mysql/lib make make install ln -sv /usr/local/lib/sasl2 /usr/lib/sasl2 cat >>/usr/local/lib/sasl2/smtpd.conf< pwcheck_method: authdaemond log_level: 7 mech_list: PLAIN LOGIN authdaemond_path: /usr/local/var/spool/authdaemon/socket EOF log_level设这么高是为了方便调试,正式运行要调小一点。 四、postfix 官方地址: http://www.postfix.org make tidy make makefiles \'CCARGS=-DHAS_MYSQL -I/usr/local/mysql/include -DUSE_SASL_AUTH -DUSE_CYRUS_SASL -I/usr/local/include/sasl\' \'AUXLIBS=-L/usr/local/mysql/lib -lmysqlclient -lm -lz -L/usr/local/lib -lsasl2\' make make install 如有有报这样的错误 bin/postconf: error while loading shared libraries: libsasl2.so.2: cannot open shared object file: No such file or directory 执行命令 ln -sv /usr/local/lib/libsasl2.so.2 /usr/lib/libsasl2.so.2 然后再make install 系统会问你很多问题,一路回车就行了。设置一下postfix的别名 mv /etc/aliases /etc/aliases.old ln -s /etc/postfix/aliases /etc/aliases echo \'root: me@imox.me\'>>/etc/postfix/aliases
/usr/bin/newaliases
postfix主配置文件

cat >> /etc/postfix/main.cf<<\'EOF\' #turn it to 1 in produce environment debug_peer_level = 2 inet_interfaces = all mail_owner = postfix setgid_group = postdrop unknown_local_recipient_reject_code = 550 mydomain = imox.me myhostname = mail.imox.me mydestination = $myhostname,localhost.$mydomain,localhost myorigin = $mydomain alias_maps = hash:/etc/aliases command_directory = /usr/sbin config_directory = /etc/postfix daemon_directory = /usr/libexec/postfix mailq_path = /usr/bin/mailq manpage_directory = /usr/local/man newaliases_path = /usr/bin/newaliases queue_directory = /var/spool/postfix sample_directory = /etc/postfix sendmail_path = /usr/sbin/sendmail html_directory = no readme_directory = no virtual_transport = virtual virtual_alias_maps = mysql:/etc/postfix/mysql_virtual_alias_maps.cf virtual_mailbox_domains = mysql:/etc/postfix/mysql_virtual_domains_maps.cf virtual_mailbox_maps = mysql:/etc/postfix/mysql_virtual_mailbox_maps.cf virtual_uid_maps = static:1003 virtual_gid_maps = static:1002 virtual_mailbox_base = /var/spool/mail virtual_mailbox_limit = 102400000 virtual_minimum_uid = 1005 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_fqdn_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 "Land moon Version" EOF 其中的virtual_uid_maps和vitrual_gid_maps是vmail的uid和gid 如果你细心的话会发现上面的EOF是被单引号引起了的,原因是我们的文本里有$myhostname这样的变量,要用单引表示其只是一个普通文本,不是变量 配置好postfix和mysql中extmail库的链接 cat >>/etc/postfix/mysql_virtual_alias_maps.cf< user = root password = shopex hosts = localhost dbname = extmail table = alias select_field = goto where_field = address additional_conditions = AND active = \'1\' EOF cat >>/etc/postfix/mysql_virtual_domains_maps.cf< user = root password = shopex hosts = localhost dbname = extmail table = domain select_field = domain where_field = domain additional_conditions = AND active = \'1\' EOF cat >>/etc/postfix/mysql_virtual_mailbox_maps.cf< user = root password = shopex hosts = localhost dbname = extmail table = mailbox select_field = maildir where_field = username additional_conditions = AND active = \'1\' EOF 设置目录权限 chown postfix:postfix /var/spool/postfix/ -R chown root:root /var/spool/postfix chown postfix:postdrop /var/spool/postfix/public chown postfix:postdrop /var/spool/postfix/maildrop 启动postfix postfix start 看看/var/log/mail.log有没有错误,如果没有就ok了,验证一下: perl -e \'use MIME::Base64; print encode_base64("用户名@saunix.cn")\' eHh4QHNob3BleC5jbg== (返回值等下认证用的) perl -e \'use MIME::Base64; print encode_base64("密码")\' eHh4 telnet 192.168.0.8 25 220 mail.zzzrc.com ESMTP “Land moon Version” ehlo localhost 250-mail.zzzrc.com 250-PIPELINING 250-SIZE 10240000 250-VRFY 250-ETRN 250-AUTH PLAIN LOGIN 250-AUTH=PLAIN LOGIN 250-ENHANCEDSTATUSCODES 250-8BITMIME 250 DSN auth login 334 VXNlcm5hbWU6 eHh4QHNob3BleC5jbg== 334 UGFzc3dvcmQ6 eHh4 235 2.0.0 Authentication successful 验证成功!postmaster@extmail.org和extmail必须用base64编码才能和服务器交流,可以这么搞: 五、Courier-IMAP 官方地址:http://www.courier-mta.org/download.php ./configure --enable-plain --enable-cram --enable-digest --enable-login --enable-sql --disable-anon --disable-ntlm --disable-gssapi --disable-krb4 --disable-otp --disable-srp --disable-srp-setpass --with-authdaemond=/usr/local/var/spool/authdaemon/socket --with-mysql=/usr/local --with-mysql-includes=/usr/local/include/mysql --with-mysql-libs=/usr/local/lib/mysql make make install cp /usr/lib/courier-imap/etc/imapd.dist /usr/lib/courier-imap/etc/imapd cp /usr/lib/courier-imap/etc/imapd-ssl.dist /usr/lib/courier-imap/etc/imapd-ssl cp /usr/lib/courier-imap/etc/pop3d.dist /usr/lib/courier-imap/etc/pop3d cp /usr/lib/courier-imap/etc/pop3d-ssl.dist /usr/lib/courier-imap/etc/pop3d-ssl 配置Courier-IMAP,为用户提供pop3服务: sed -i \'s/POP3DSTART=NO/POP3DSTART=yes/\' /usr/lib/courier-imap/etc/pop3d IMAP服务的配置类似。 cp courier-imap.sysvinit /etc/rc.d/init.d/imapd chmod +x /etc/rc.d/init.d/imapd cd /etc/rc.d/rc3.d ln -sv ../init.d/imapd S75imapd 启动 /etc/rc.d/init.d/imapd start 验证imap telnet 192.168.0.8 110 +OK Hello there. user postmaster@extmail.org +OK Password required. pass extmail +OK logged in. 遇到的错误 ec 26 02:27:44 localhost postfix/trivial-rewrite[6447]: fatal: mysql:/etc/postfix/mysql_virtual_alias_maps.cf(0,lock|fold_fix): table lookup problem Dec 26 02:27:45 localhost postfix/master[6444]: warning: process /usr/libexec/postfix/trivial-rewrite pid 6447 exit status 1 Dec 26 02:27:45 localhost postfix/pickup[6446]: 7928A710283: uid=502 from= Dec 26 02:27:45 localhost postfix/master[6444]: warning: /usr/libexec/postfix/trivial-rewrite: bad command startup — throttling 原因是postfix是运行在chroot环境中无法找到 连接配置文件中 hosts = localhost 都改成 hosts = 127.0.0.1 用tcp方式去连接, http://ubuntuforums.org/archive/index.php/t-251119.html Recipient address rejected: User unknown in local recipient table; apache改用postfix帐号来运行 pop3信取不下来 三个地方用户身份要统一 apache运行用户(/usr/local/apache2_webmail/conf/httpd.conf ) User postfix Group postfix postfix运行用户(/etc/mail.cf) virtual_uid_maps = static:2002 virtual_gid_maps = static:2001 authlib运行用户(/usr/local/etc/authlib/authmysqlrc) MYSQL_UID_FIELD 2002 MYSQL_GID_FIELD 2001

哟?不错哎 订阅小米的RSS Feeds 回去慢慢看^_^