linux 下 搭建邮件邮件服务器(Postfix+Dovecot)(三) 使用 maildrop 投递邮件
linux 下 搭建邮件邮件服务器(Postfix+Dovecot)(三) 使用 maildrop 投递邮件
十六、配置postfix使用maildrop投递邮件
maildrop是一个使用C++编写的用来代替本地MDA的带有过滤功能邮件投递代理,是courier邮件系统组件之一。它从标准输入接受信息并投递到用户邮箱;maildrop既可以将邮件投递到mailboxes格式邮箱,亦可以将其投递到maildirs格式邮箱。同时,maildrop可以从文件中读取入站邮件过滤指示,并由此决定是将邮件送入用户邮箱或者转发到其它地址等。和procmail不同的是,maildrop使用结构化的过滤语言,因此,邮件系统管理员可以开发自己的过滤规则并应用其中。
我们在此将使用maildrop来代替postfix自带的MDA,并以此为基础扩展后文的邮件杀毒和反垃圾邮件功能的调用;在此可能会修改前文中的许多设置,请确保您的设置也做了相应的修改。
1、安装maildrop前准备
将courier-authlib的头文件及库文件(参考第八部分的第四小节)链接至/usr目录(编译maildrop时会到此目录下找此些相关的文件):
# ln -sv /usr/local/courier-authlib/bin/courierauthconfig /usr/bin # ln -sv /usr/local/courier-authlib/include/* /usr/include
# vim /etc/ld.so.conf.d/courier-authlib.conf /usr/local/courier-authlib/lib/courier-authlib
# yum install pcre-devel -y
2、安装Courier-Unicode
字符集库文件,相当于RPM方式安装的courier-authlib-devel包,不安装这个会导致编译maildrop时报错:
# wget http://jaist.dl.sourceforge.net/project/courier/courier-unicode/1.1/courier-unicode-1.1.tar.bz2 # tar jxvf courier-unicode-1.1.tar.bz2 # cd courier-unicode-1.1 # ./configure # make # make install
# ls /usr/local/lib libcourier-unicode.a libcourier-unicode.so libcourier-unicode.so.1.0.0 libunicode.la libunicode.so.1 libcourier-unicode.la libcourier-unicode.so.1 libunicode.a libunicode.so libunicode.so.1.0.0
# vim /etc/ld.so.conf.d/courier-unicode.conf /usr/local/lib
# ldconfig -v
3、安装maildrop-2.7.2
# groupadd -g 1001 vmail # useradd -g vmail -u 1001 -M -s /sbin/nologin vmail
# tar jxvf maildrop-2.7.2.tar.bz2 # cd maildrop-2.7.2 ./configure --enable-sendmail=/usr/sbin/sendmail --enable-trusted-users=‘root vmail‘ --enable-syslog=1 --enable-maildirquota --enable-maildrop-uid=1001 --enable-maildrop-gid=1001 --with-trashquota --with-dirsync # make # make install
4、新建其配置文件/etc/maildroprc文件,首先指定maildrop的日志记录位置:
# vim /etc/maildroprc
添加:
VERBOSE=5 logfile "/var/log/maildrop.log" to "$HOME/Maildir"
# touch /var/log/maildrop.log # chown vmail.vmail /var/log/maildrop.log
5、配置Postfix
编辑master.cf
# vim /etc/postfix/master.cf
启用如下两行
maildrop unix - n n - - pipe flags=DRhu user=vmail argv=/usr/local/bin/maildrop -d ${recipient}
注意:定义transport的时候,即如上两行中的第二行,其参数行必须以空格开头,否则会出错。
编辑main.cf
# vim /etc/postfix/main.cf virtual_transport = virtual 修改为: virtual_transport = maildrop
将下面两项指定的UID和GID作相应的修改:
virtual_uid_maps = static:2525 virtual_gid_maps = static:2525 修改为: virtual_uid_maps = static:1001 virtual_gid_maps = static:1001
6、编辑/etc/authmysqlrc
# vim /etc/authmysqrc MYSQL_UID_FIELD 2525 MYSQL_GID_FIELD ‘2525‘ 更改为: MYSQL_UID_FIELD 1001 MYSQL_GID_FIELD 1001
注意:没有此处的修改,maildrop可能会报告 “signal 0x06”的错误报告。
7、编辑# /etc/httpd/conf/httpd.conf,修改运行用户:
# vim /etc/httpd/conf/httpd.conf 如果启用了suexec的功能,则将虚拟主机中指定的 SuexecUserGroup postfix postfix 修改为: SuexecUserGroup vmail vmail
如果没有使用上面的功能,则修改User和Group指令后的用户为vmail
将前文中的如下项
User postfix Group postfix 修改为: User vmail Group vmail
8、将用户邮件所在的目录/var/mailbox和extman的临时目录/tmp/extman的属主和属组指定为vmail
#chown -R vmail.vmail /var/mailbox #chown -R vmail.vmail /tmp/extman
将CGI文件的属主和属组指定为vmail
# chown -R vmail.vmail /var/www/extsuite/extmail/cgi/ # chown -R vmail.vmail /var/www/extsuite/extman/cgi/
9、修改extman的主配置文件中的默认用户ID和组ID,确保其为类似如下内容
# vim /var/www/extsuite/extman/webman.cf SYS_DEFAULT_UID = 1001 SYS_DEFAULT_GID = 1001
10、验正邮件投递
# /etc/init.d/courier-authlib restart # /etc/init.d/httpd restart # /etc/init.d/postfix restart
接下来重新启动postfix和apache,进行发信测试后,如果日志中的记录类同以下项,则安装成功
Jul 6 16:36:26 localhost postfix/qmgr[20145]: 02FD42600D2: from=<zyz20140618@126.com>, size=2292, nrcpt=1 (queue active) Jul 6 16:36:26 localhost postfix/smtpd[20549]: disconnect from m15-112.126.com[220.181.15.112] Jul 6 16:36:26 localhost postfix/pipe[20634]: 02FD42600D2: to=<zyz2@10fei3.top>, relay= maildrop , delay=0.31, delays=0.2/0/0/0.11, dsn=2.0.0, status=sent (delivered via maildrop service)
测试能否发送电邮:
# echo "test"|maildrop -V 9 -d zyz2@10fei3.top maildrop: authlib: groupid=1001 maildrop: authlib: userid=1001 maildrop: authlib: logname=zyz2@10fei3.top, home=/var/mailbox/10fei3.top/zyz2, mail=(default) maildrop: Changing to /var/mailbox/10fei3.top/zyz2 Message envelope sender=MAILER-DAEMON Tokenized ; Tokenized string: "VERBOSE" Tokenized = Tokenized string: "5" Tokenized ; Tokenized logfile Tokenized string: "/var/log/maildrop.log" Tokenized ; Tokenized to Tokenized string: "$HOME/Maildir" Tokenized ; Tokenized eof /etc/maildroprc(2): VERBOSE="5"
十七、maidrop问题解决
报错1:
configure: error: pcre.h not found - install PCRE from www.pcre.org
解决:
# yum install pcre-devel -y
报错2:
configure: error: The Courier Unicode Library 1.2 appears not to be installed. You may need to install a separate development subpackage, in addition to the main package
解决:
安装Courier-Unicode
字符集库文件,相当于RPM方式安装的courier-authlib-devel包,不安装这个会导致编译maildrop时
# wget http://jaist.dl.sourceforge.net/project/courier/courier-unicode/1.1/courier-unicode-1.1.tar.bz2 # tar jxvf courier-unicode-1.1.tar.bz2 # cd courier-unicode-1.1 # ./configure # make # make install
报错3:
# maildrop -v maildrop: error while loading shared libraries: libunicode.so.1: cannot open shared object file: No such file or directory
解决:
# ls /usr/local/lib libcourier-unicode.a libcourier-unicode.so libcourier-unicode.so.1.0.0 libunicode.la libunicode.so.1 libcourier-unicode.la libcourier-unicode.so.1 libunicode.a libunicode.so libunicode.so.1.0.0
# vim /etc/ld.so.conf.d/courier-unicode.conf /usr/local/lib
# ldconfig -v
报错4:
Jul 6 14:27:58 localhost postfix/pipe[19853]: 531AE260200: to=<zyz2@10fei3.top>, relay=maildrop, delay=1057, delays=1057/0.01/0/0.07, dsn=4.3.0, status=deferred (temporary failure. Command output: /usr/local/bin/maildrop: Unable to change to home directory.
# echo "test"|maildrop -V 10 -d zyz2@10fei3.top maildrop: authlib: groupid=1001 maildrop: authlib: userid=1001 maildrop: authlib: logname=zyz2@10fei3.top, home=/var/mailbox10fei3.top/zyz2, mail=(default) maildrop: Changing to /var/mailbox10fei3.top/zyz2 maildrop: Unable to change to home directory.
解决:
检查/etc/authmysqlrc MYSQL_HOME_FIELD concat(‘/var/mailbox/‘,homedir) MYSQL_MAILDIR_FIELD concat(‘/var/mailbox/‘,maildir) 我因为配置成 MYSQL_MAILDIR_FIELD concat(‘/var/mailbox‘,maildir) 所以导致 maildrop: authlib: logname=zyz2@10fei3.top, home=/var/mailbox10fei3.top/zyz2, mail=(default)
报错5:
Jul 6 14:35:59 localhost postfix/pipe[20149]: AAE7C260202: to=<zyz2@10fei3.top>, relay=maildrop, delay=0.28, delays=0.25/0/0/0.03, dsn=4.3.0, status=deferred (temporary failure. Command output: /usr/local/bin/maildrop: Unable to open mailbox. )
# echo "test"|maildrop -V 9 -d zyz2@10fei3.top maildrop: authlib: groupid=1001 maildrop: authlib: userid=1001 maildrop: authlib: logname=zyz2@10fei3.top, home=/var/mailbox/10fei3.top/zyz2, mail=(default) maildrop: Changing to /var/mailbox/10fei3.top/zyz2 Message envelope sender=MAILER-DAEMON Tokenized ; Tokenized string: "VERBOSE" Tokenized = Tokenized string: "5" Tokenized ; Tokenized logfile Tokenized string: "/var/log/maildrop.log" Tokenized ; Tokenized ; Tokenized eof /etc/maildroprc(2): VERBOSE="5" maildrop: Unable to open mailbox.
解决:
to "$HOME$DEFAULT" 改为: to "$HOME/Maildir" # vim /etc/maildroprc #SHELL="/bin/sh" VERBOSE=5 logfile "/var/log/maildrop.log" to "$HOME/Maildir"