设为首页 收藏本站
查看: 3683|回复: 0

[经验分享] postfix-webmail,Dovecot,centos;qmail

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2015-9-15 09:47:55 | 显示全部楼层 |阅读模式
  ...
  http://www.oschina.net/news/41674/postfix-2101
  下载:
  ftp://ftp.porcupine.org/mirrors/postfix-release/official/postfix-2.9.7.tar.gz
ftp://ftp.porcupine.org/mirrors/postfix-release/official/postfix-2.10.1.tar.gz
  ########################################################
  
  
  http://db.nipusa.net/mysql/a-112.html
  图
  http://zhangxylinux.blog.iyunv.com/5041623/930452
  本文将给大家演示最新源码编译搭建邮件服务器,需要用到的包组如下,postfix-2.9.3.tar.gz,mysql-5.5.24-linux2.6-i686.tar.gz,courier-authlib.0.64.0.tar.bz2,dovecot-2.1.3.tar.gz ,extmail-1.2.tar.gz,extman-1.1.tar.gz,Unix-Syslog-1.1.tar.gz,  Time-HiRes-1.9721.tar.gz。


工欲善其事,必先利其器。准备工作一定要做充分,为后边的搭建成功做好保证,邮件服务器严重依赖DNS服务器,搭建好DNS服务器是必须的,这里就给出DNS的简单配置,配置邮件服务器才是重点。

  • [iyunv@mail ~]# vim /var/named/zzu.com.db   #正向区域及内容配置  
  • $TTL 600   
  • @    IN   SOA   ns.zzu.com.    admin.zzu.com. (  
  •                  2012071201  
  •                  15M  
  •                  5M  
  •                  1W  
  •                  1D)  
  • @       IN NS  ns.zzu.com.  
  •         IN MX 10 mail.zzu.com.  
  • mail    IN A     192.168.0.100  
  • ns      IN A  192.168.0.100  
  • www     IN A  192.168.0.100  
  • pop3    IN CNAME mail  
  • smtp    IN CNAME  mail  
  •   
  • [iyunv@mail ~]# vim /var/named/192.168.0.db     #反向区域及内容  
  • $TTL 600  
  • @       IN SOA    ns.zzu.com.  admin.zzu.com. (  
  •             2012071201  
  •             30M  
  •             15M  
  •             1W  
  •             1D)  
  •            IN   NS  ns.zzu.com.  
  • 100       IN   PTR mail.zzu.com.  
  • 100       IN   PTR www.zzu.com.  

除了DNS服务器,还依赖于一些rpm包,也先列举如下,用到的时候直接装上,httpd, mysql, dovecot, perl-DBD-MySQL, libtool-ltdl, libtool-ltdl-devel, expect和开发环境的rpm包组的准备 Development Libraries,Development Tools,Legacy Software Development,X Software Development。
务必修改一下主机名,邮件服务主机名很重要,到/etc/sysconfig/network下修改主机名,最好与mail服务器同名。ok!准备完成。
因为一个操作系统上不能同时有两个进程提供邮件服务,此处就关闭sendmail,使用postfix。

  • [iyunv@mail ~]# service sendmail stop  
  • [iyunv@mail ~]# chkconfig sendmail off  
  • [iyunv@mail ~]# service saslauthd start  
  • [iyunv@mail ~]# chkconfig saslauthd on  

1.编译安装mysql-5.5.24-linux2.6-i686

1.1提供数据存放位置/mydata/data 新建用户以安全方式运行进程.建议把mysql安装在一个逻辑卷上,对数据的管理更加的方便。

  • [iyunv@localhost ~]# mkdir -pv /mydata/data  
  • mkdir: created directory `/mydata'  
  • mkdir: created directory `/mydata/data'  
  • [iyunv@localhost ~]# groupadd -r mysql    #创建mysql组合用户并修改/mydata/data/所有者为mysql
  • [iyunv@localhost ~]# useradd -g mysql -r -s /sbin/nologin -M -d /mydata/data mysql  
  • [iyunv@localhost ~]# chown -R mysql:mysql /mydata/data,

1.2,编译安装并初始化mysql-5.5.24

  • [iyunv@localhost ~]# tar xf mysql-5.5.24-linux2.6-i686.tar.gz -C   
  • /usr/local  
  • [iyunv@localhost ~]# cd /usr/local  
  • [iyunv@localhost local]# ln -sv mysql-5.5.24-linux2.6-i686/ mysql  
  • create symbolic link `mysql' to `mysql-5.5.24-linux2.6-i686/'  
  • [iyunv@localhost local]# cd mysql  
  • [iyunv@localhost mysql]# ls  
  • COPYING         README  data  include  man         
  • scripts  sql-bench  INSTALL-BINARY  bin     docs  lib      mysql-test  share   support- files  
  • [iyunv@localhost mysql]# chown -R mysql:mysql .  
  • [iyunv@localhost mysql]# scripts/mysql_install_db  --user=mysql --datadir=/mydata/data  
  • [iyunv@localhost mysql]# chown -R root  .  

1.3 为mysql提供主配置文件,和sysv服务脚本,方便mysql的管理。

  • [iyunv@localhost mysql]# cp support-files/my-large.cnf  /etc/my.cnf  
  • [iyunv@localhost mysql]# vim /etc/my.cnf   
  • [iyunv@localhost mysql]# cp support-files/mysql.server  /etc/rc.d/init.d/mysqld  
  • [iyunv@localhost mysql]# chkconfig --add mysqld  #添加服务之服务列表
  • [iyunv@localhost mysql]# chkconfig mysqld on     #设置开机自动启动
  • [iyunv@localhost mysql]# service mysqld start  
  • Starting MySQL......                                    [  OK  ]  

1.4 此时只是启动了mysql服务。但是mysql命令还不能正常使用,下面为系统增加mysql的相关命令。

  • [iyunv@localhost mysql]# ln -sv /usr/local/mysql/include/ /usr/include/mysql  
  • create symbolic link `/usr/include/mysql' to `/usr/local/mysql/include/'  
  • [iyunv@localhost mysql]# echo '/usr/local/mysql/lib/' >  /etc/ld.so.conf.d/mysql.conf  
  • #输出mysql的库文件给系统库查找路径
  • [iyunv@localhost mysql]# cat etc/ld.so.conf.d/mysql.conf  
  • /usr/local/mysql/lib/  
  • [iyunv@localhost mysql]# ldconfig       #重新载入系统库
  • [iyunv@localhost ~]# vim /etc/profile   #修改PATH变量,使mysql命令生效
  • [iyunv@localhost ~]# export PATH=$PATH:/usr/local/mysql/bin #使PATH立即生效,最好不要使用source
  • [iyunv@localhost ~]# mysql              #mysql 命令可以 正常使用
  • Welcome to the MySQL monitor.  Commands end with ; or \g.  
  • Your MySQL connection id is 1  
  • Server version: 5.5.24-log MySQL Community Server (GPL)  
  • Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights   
  • reserved.  
  • Oracle is a registered trademark of Oracle Corporation and/or its  
  • affiliates. Other names may be trademarks of their respective owners.  
  • Type 'help;' or '\h' for help. Type '\c' to clear the  
  • current input   
  • statement.  
  • mysql>   

mysql配置完毕,下面安装配置postfix-2.9.3。

2.编译安装postfix-2.9.3。

2.1创建postfix用户和组,且指定GID最好为大于1000的数值。

  • # groupadd -g 2525 postfix  
  • # useradd -g postfix -u 2525 -s /sbin/nologin -M postfix  
  • # groupadd -g 2526 postdrop  
  • # useradd -g postdrop -u 2526 -s /sbin/nologin -M postdrop  

2.2 编译安装postfix

  • [iyunv@localhost ~]# tar xf postfix-2.9.3.tar.gz   
  • [iyunv@localhost ~]# cd postfix-2.9.3  
  • [iyunv@localhost postfix-2.9.3]#  make makefiles 'CCARGS=-DHAS_MYSQL - I/usr/local/mysql/include -DUSE_SASL_AUTH - DUSE_CYRUS_SASL - I/usr/include/sasl  -DUSE_TLS ' 'AUXLIBS=-L/usr/local/mysql/lib - lmysqlclient -lz -lm -L/usr/lib/sasl2 -lsasl2  -lssl -lcrypto'  
  • [iyunv@localhost postfix-2.9.3]# make  
  • [iyunv@localhost postfix-2.9.3]# make  install   
  • Please specify the prefix for installed file names. Specify this ONLY
  • if you are building ready-to-install packages for distribution to  
  • OTHER
  • machines. See PACKAGE_README for instructions.
  • install_root: [/]  
  • Please specify a directory for scratch files while installing Postfix.  
  • You
  • must have write permission in this directory.
  • tempdir: [/root/postfix-2.9.3]  
  • Please specify the final destination directory for installed Postfix
  • configuration files.
  • config_directory: [/etc/postfix]  
  • Please specify the final destination directory for installed Postfix
  • administrative commands. This directory should be in the command  
  • search
  • path of adminstrative users.
  • command_directory: [/usr/sbin]  
  • Please specify the final destination directory for installed Postfix
  • daemon programs. This directory should not be in the command search  
  • pathof any users.
  • daemon_directory: [/usr/libexec/postfix]  
  • Please specify the final destination directory for Postfix-writable
  • data files such as caches or random numbers. This directory should not
  • be shared with non-Postfix software.
  • data_directory: [/var/lib/postfix]  
  • Please specify the destination directory for the Postfix HTML
  • files. Specify "no" if you do not want to install these files.
  • html_directory: [no]  
  • Please specify the owner of the Postfix queue. Specify an account with
  • numerical user ID and group ID values that are not used by any other
  • accounts on the system.
  • mail_owner: [postfix]  
  • Please specify the final destination pathname for the installed  
  • Postfix
  • mailq command. This is the Sendmail-compatible mail queue listing  
  • command.
  • mailq_path: [/usr/bin/mailq]  
  • Please specify the destination directory for the Postfix on-line  
  • manual
  • pages. You can no longer specify "no" here.
  • manpage_directory: [/usr/local/man]  
  • Please specify the final destination pathname for the installed  
  • Postfix
  • newaliases command. This is the Sendmail-compatible command to build
  • alias databases for the Postfix local delivery agent.
  • newaliases_path: [/usr/bin/newaliases]  
  • Please specify the final destination directory for Postfix queues.
  • queue_directory: [/var/spool/postfix]  
  • Please specify the destination directory for the Postfix README
  • files. Specify "no" if you do not want to install these files.
  • readme_directory: [no]  
  • Please specify the final destination pathname for the installed  
  • Postfix
  • sendmail command. This is the Sendmail-compatible mail posting  
  • interface.
  • sendmail_path: [/usr/sbin/sendmail]  
  • Please specify the group for mail submission and for queue management
  • commands. Specify a group name with a numerical group ID that is
  • not shared with other accounts, not even with the Postfix mail_owner
  • account. You can no longer specify "no" here.
  • setgid_group: [postdrop]  

此处配置相关含义不一一解释,其含义也不难理解,路径可以自己指定,也可以选择默认。下面一定要生成二进制文件,对服务器的性能有大大的提高,不要忽略这步骤

  • [iyunv@localhost postfix-2.9.3]# newaliases

2.3 为postfix提供SysV服务脚本/etc/rc.d/init.d/postfix

  • [iyunv@localhost postfix-2.9.3]# vim /etc/rc.d/init.d/postfix
  • [iyunv@localhost postfix-2.9.3]# chmod +x /etc/rc.d/init.d/postfix
  • [iyunv@localhost postfix-2.9.3]# chkconfig  --add postfix
  • [iyunv@localhost postfix-2.9.3]# chkconfig  postfix on
  • [iyunv@localhost postfix-2.9.3]# service postfix start
  • Starting postfix:                                          [  OK  ]
  • [iyunv@localhost postfix-2.9.3]#  
  • 查看日志和开放端口
  • [iyunv@localhost postfix-2.9.3]# tail /var/log/maillog
  • Jul 13 07:30:55 localhost postfix/postfix-script[4231]: starting the Postfix mail system
  • Jul 13 07:30:55 localhost postfix/master[4232]: daemon started --  
  • version 2.9.3, configuration /etc/postfix

查看开放端口 DSC0000.png

服务脚本代码如下

  • #!/bin/bash  
  • ## postfix      Postfix Mail Transfer Agent  
  • ## chkconfig: 2345 80 30  
  • # description: Postfix is a Mail Transport Agent, which is the program \  
  • #  that moves mail from one machine to  
  • another.  
  • # processname: master  
  • # pidfile: /var/spool/postfix/pid/master.pid  
  • # config: /etc/postfix/main.cf  
  • # config: /etc/postfix/master.cf  
  •   
  • # Source function library.  
  • . /etc/rc.d/init.d/functions  
  • # Source networking configuration.  
  • . /etc/sysconfig/network  
  • #Check that networking is up.  
  • [ $NETWORKING = "no" ] && exit 3  
  •   
  • [ -x /usr/sbin/postfix ] || exit 4  
  • [ -d /etc/postfix ] || exit 5  
  • [ -d /var/spool/postfix ] || exit 6  
  • RETVAL=0  
  • prog="postfix"  
  •   
  • start() {  
  •     # Start daemons.  
  •     echo -n $"Starting postfix: "  
  •         /usr/bin/newaliases >/dev/null 2>&1  
  •     /usr/sbin/postfix start 2>/dev/null 1>&2 &&  

  • success || failure $"$prog start"  
  •     RETVAL=$?  
  •     [ $RETVAL -eq 0 ] && touch  

  • /var/lock/subsys/postfix  
  •         echo  
  •     return $RETVAL  
  • }  
  • stop() {  
  •   # Stop daemons.  
  •     echo -n $"Shutting down postfix: "  
  •     /usr/sbin/postfix stop 2>/dev/null 1>&2 && success  

  • || failure $"$prog stop"  
  •     RETVAL=$?  
  •     [ $RETVAL -eq 0 ] && rm -f  

  • /var/lock/subsys/postfix  
  •     echo  
  •     return $RETVAL  
  • }  
  • reload() {  
  •     echo -n $"Reloading postfix: "  
  •     /usr/sbin/postfix reload 2>/dev/null 1>&2 &&  

  • success || failure $"$prog reload"  
  •     RETVAL=$?  
  •     echo  
  •     return $RETVAL  
  • }  
  • abort() {  
  •     /usr/sbin/postfix abort 2>/dev/null 1>&2 &&  
  • success || failure $"$prog abort"  
  •     return $?  
  • }  
  • flush() {  
  •     /usr/sbin/postfix flush 2>/dev/null 1>&2 &&  
  • success || failure $"$prog flush"  
  •     return $?  
  • }  
  • check() {  
  •     /usr/sbin/postfix check 2>/dev/null 1>&2 &&  

  • success || failure $"$prog check"  
  •     return $?  
  • }  
  • restart() {  
  •     stop  
  •     start  
  • }  
  • # See how we were called.  
  • case "$1" in  
  •   start)  
  •     start  
  •     ;;  
  •   stop)  
  •     stop  
  •     ;;  
  •   restart)  
  •     stop  
  •     start  
  •     ;;  
  •   reload)  
  •     reload  
  •     ;;  
  •   abort)  
  •     abort  
  •     ;;  
  •   flush)  
  •     flush  
  •     ;;  
  •   check)  
  •     check  
  •     ;;  
  •   status)  
  •     status master  
  •     ;;  
  •   condrestart)  
  •     [ -f /var/lock/subsys/postfix ] && restart || :  
  •     ;;  
  •   *)  
  •     echo $"Usage: $0 {start|stop|restart|reload|
  • abort|flush|check|status|condrestart}"  
  •     exit 1  
  • esac  
  • exit $?  
  • # END  


postfix文件配置规则给顺便提一提,1、在postfix的配置文件中,参数行和注释行是不能处在同一行中的;2、任何一个参数的值都不需要加引号,否则,引号将会被当作参数值的一部分来使用;3、每修改参数及其值后执行 postfix reload 即可令其生效;但若修改了inet_interfaces,则需重新启动postfix;4、如果一个参数的值有多个,可以将它们放在不同的行中,只需要在其后的每行前多置一个空格即可;postfix会把第一个字符为空格或tab的文本行视为上一行的延续;

  • [iyunv@localhos~]# vim /etc/postfix/main.cf  
  • myhostname = mail.zzu.com  
  • myorigin = zzu.com  
  • mydomain = zzu.com  
  • mydestination = $myhostname, localhost.$mydomain,  localhost, $mydomain  
  • mynetworks = 192.168.0.0/24, 127.0.0.0/8  
  • inet_interfaces = all  

在postfix的配置文件main.cf中做如上的改动,就可以发送和接收邮件,先来测试一下收发信件,再介绍一下各自的含义。

  • #先添加两个用户  
  • [iyunv@localhost ~]# useradd user1  
  • [iyunv@localhost ~]# useradd user2  
  • [iyunv@localhost ~]# echo "redhat" |passwd --stdin user1  
  • [iyunv@localhost ~]# echo "redhat" |passwd --stdin user2  
  • #收发信件  
  • [iyunv@localhost ~]# telnet mail.zzu.com 25  
  • Trying 192.168.0.100...  
  • Connected to mail.zzu.com (192.168.0.100).  
  • Escape character is '^]'.  
  • 220 mail.zzu.com ESMTP Postfix  
  • helo mail.zzu.com  
  • 250 mail.zzu.com  
  • mail from:user1@zzu.com  
  • 250 2.1.0 Ok  
  • rcpt to:user2@zzu.com  
  • 250 2.1.5 Ok  
  • data  
  • 354 End data with <CR><LF>.<CR><LF>  
  • Subject hello  
  • . 250 2.0.0 Ok: queued as E0B2113DAD6  
  • quit  
  • 221 2.0.0 Bye  
  • Connection closed by foreign host.  
  • #user2 接受成功  
  • [iyunv@mail ~]# su - user2  
  • [user2@mail ~]$ mail  
  • Mail version 8.1 6/6/93.  Type ? for help.  
  • "/var/spool/mail/user2": 1 message 1 new  
  • >N  1 user1@zzu.com         Fri Jul 13 08:12  13/435   
  • & 1  
  • Message 1:  
  • From user1@zzu.com  Fri Jul 13 08:12:17 2012  
  • X-Original-To: user2@zzu.com  
  • Delivered-To: user2@zzu.com  
  • Date: Fri, 13 Jul 2012 08:10:37 +0800 (CST)  
  • From: user1@zzu.com  
  • Subject hello  
  查看一下日志,,要有查看日志的好习惯哦
DSC0001.png

  • myorigin参数用来指明发件人所在的域名,即做发件地址伪装;
  • mydestination参数指定postfix接收邮件时收件人的域名,即您的postfix系统要接收到哪个域名的邮件;
  • myhostname 参数指定运行postfix邮件系统的主机的主机名,默认情况下,其值被设定为本地机器名;
  • mydomain 参数指定您的域名,默认情况下,postfix将
  • myhostname的第一部分删除而作为mydomain的值;
  • mynetworks 参数指定你所在的网络的网络地址,postfix系统根据其值来区别用户是远程的还是本地的,如果是本地网络用户则允许其访问;
  • inet_interfaces 参数指定postfix系统监听的网络接口;
  2.4 为postfix开启基于cyrus-sasl的认证功能

  • [iyunv@mail ~]# postconf  -a  
  • cyrus  
  • dovecot  

验正postfix是否支持cyrus风格的sasl认证,如果您的输出为以上结果,则是支持的,其实很简单,在main.cf中添加如下内容。

  • [iyunv@mail ~]# vim /etc/postfix/main.cf #增加如下内容  
  • 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  
  • smtpd_sasl_auth_enable = yes  
  • smtpd_sasl_local_domain = $myhostname  
  • smtpd_sasl_security_options = noanonymous  
  • smtpdsmtpdsmtpd_sasl_application_name = smtpd  
  • smtpd_banner = Welcome to our $myhostname  
  • ESMTP,Warning: Version not Available!  
  • [iyunv@mail ~]# vim /usr/lib/sasl2/smtpd.conf  #添加下边两行
  •    pwcheck_method: saslauthd  
  •    mech_list: PLAIN LOGIN  
  • [iyunv@mail ~]# /usr/sbin/postfix reload  
  • /usr/sbin/postconf: warning: /etc/postfix/main.cf: unused parameter:   
  • smtpdsmtpdsmtpd_sasl_application_name=smtpd  
  • postfix/postfix-script: refreshing the Postfix mail system  
  • [iyunv@mail ~]# vim /etc/postfix/main.cf  
  • #去掉network指定的内容,现在就基于用户认证了  
  • [iyunv@mail ~]# telnet mail.zzu.com 25  
  • Trying 192.168.0.100...  
  • Connected to mail.zzu.com (192.168.0.100).  
  • Escape character is '^]'.  
  • 220 Welcome to our mail.zzu.com ESMTP,Warning: Version not Available!  
  • ehlo mail.zzu.com  
  • 250-mail.zzu.com  
  • 250-PIPELINING  
  • 250-SIZE 10240000  
  • 250-VRFY  
  • 250-ETRN  
  • 250-AUTH LOGIN PLAIN  
  • 250-AUTH=LOGIN PLAIN  
  • 250-ENHANCEDSTATUSCODES  
  • 250-8BITMIME  
  • 250 DSN  
  • quit  
  • 221 2.0.0 Bye  
  • Connection closed by foreign host.  
  • 发邮件测试  
  • [iyunv@mail ~]# telnet mail.zzu.com 25  
  • Trying 192.168.0.100...  
  • Connected to mail.zzu.com (192.168.0.100).  
  • Escape character is '^]'.  
  • 220 Welcome to our mail.zzu.com ESMTP,Warning: Version not Available!  
  • AUTH LOGIN  
  • 334 VXNlcm5hbWU6  
  • cmVkaGF0            #使用base64编码 echo -n "redhat" | openssl base64  
  • 334 UGFzc3dvcmQ6  
  • cmVkaGF0  
  • 235 2.7.0 Authentication successful  
  • mail from:redhat@zzu.com  
  • 250 2.1.0 Ok  
  • rcpt to:user1@zzu.com  
  • 250 2.1.5 Ok  
  • data  
  • 354 End data with <CR><LF>.<CR><LF>  
  • hello  
  • .
  • 250 2.0.0 Ok: queued as 7B98E13DADA  #基于验证,并能发信成功
  • quit  
  • 221 2.0.0 Bye  
  • Connection closed by foreign host.  

postfix也已经搭建完毕,并且可以基于sasl来进行验证。为了实现基于courier-authlib来进行认证登录时的用户名和密码,我们就来编译安装一下courier-authlib
3.编译安装courier-authlib
安装之前确保libtool-ltdl, libtool-ltdl-devel,已安装上。
3.1 解压并编译安装courier-authlib

  • [iyunv@mail ~]# tar jxvf courier-authlib-0.64.0.tar.bz2
  • [iyunv@mail ~]# cd courier-authlib-0.64.0
  • [iyunv@mail courier-authlib-0.64.0]# ./configure \
  • >     --prefix=/usr/local/courier-authlib \
  • >     --sysconfdir=/etc \
  • >     --without-authpam \
  • >     --without-authshadow \
  • >     --without-authvchkpw \
  • >     --without-authpgsql \
  • >     --with-authmysql \
  • >     --with-mysql-libs=/usr/local/mysql/lib \
  • >     --with-mysql-includes=/usr/local/mysql/include \
  • >     --with-redhat \
  • >     --with-authmysqlrc=/etc/authmysqlrc \
  • >     --with-authdaemonrc=/etc/authdaemonrc \
  • >     --with-mailuser=postfix \
  • >     --with-mailgroup=postfix \
  • >     --with-ltdl-lib=/usr/lib \
  • >     --with-ltdl-include=/usr/include
  • [iyunv@mail courier-authlib-0.64.0]# make &&make install

其中有两行务必要解释一下,因为咱们是编译安装的mysql,编译安装的mysql和rpm包安装路径不一样,所以 --with-mysql-libs=/usr/local/mysql/lib \   和  --with-mysql-includes=/usr/local/mysql/include \ 这两行一点要跟现在mysql安装路径相对应,否则编译时将会出错。
3.2 修改配置文件

  • [iyunv@mail ~]# chmod 755 /usr/local/courier-authlib/var/spool/authdaemon/
  • [iyunv@mail ~]# cp /etc/authdaemonrc.dist  /etc/authdaemonrc
  • [iyunv@mail ~]# cp /etc/authmysqlrc.dist  /etc/authmysqlrc
  • [iyunv@mail ~]# vim /etc/authdaemonrc  
  •    authmodulelist="authmysql"  #认证机制为mysql
  •    authmodulelistorig="authmysql"
  •    daemons=10

3.2基于mysql来认证用户的账号和密码
请参照下边内容进行修改

  • [iyunv@mail ~]# vim /etc/authmysqlrc
  • MYSQL_SERVER localhost
  • MYSQL_PORT 3306      #  指定你的mysql监听的端口,这里使用默认的3306
  • MYSQL_USERNAME  extmail      #这时为后文要用的数据库的所有者的用户名
  • MYSQL_PASSWORD extmail        # 密码
  • MYSQL_SOCKET  /tmp/mysql.sock #套接字文件,编译安装的mysql默认在/tmp下
  • MYSQL_DATABASE  extmail
  • MYSQL_USER_TABLE  mailbox
  • MYSQL_CRYPT_PWFIELD  password
  • MYSQL_UID_FIELD  '2525'  #GID 一定要与前边的组ID相一致  
  • MYSQL_GID_FIELD  '2525'
  • MYSQL_LOGIN_FIELD  username
  • MYSQL_HOME_FIELD  concat('/var/mailbox/',homedir)
  • MYSQL_NAME_FIELD  name
  • MYSQL_MAILDIR_FIELD  concat('/var/mailbox/',maildir)# 路径可以相应的修改

3.4 提供sysv服务脚本,方便courier-authlib服务的管理,

  • [iyunv@mail ~]# cd courier-authlib-0.64.0
  • [iyunv@mail courier-authlib-0.64.0]# cp courier-authlib.sysvinit  /etc/rc.d/init.d/courier-authlib
  • [iyunv@mail courier-authlib-0.64.0]#  chmod +x   /etc/rc.d/init.d/courier-authlib
  • [iyunv@mail courier-authlib-0.64.0]# chkconfig  --add courier-authlib
  • [iyunv@mail courier-authlib-0.64.0]# chkconfig  courier-authlib on
  • [iyunv@mail courier-authlib-0.64.0]# service courier-authlib start
  • Starting Courier authentication services: authdaemond
  • #进程已启动,服务开启

3.5配置postfix和courier-authlib

  • [iyunv@mail ~]# mkdir -pv /var/mailbox
  • [iyunv@mail ~]# chown -R postfix /var/mailbox
  • [iyunv@mail ~]# vim /usr/lib/sasl2/smtpd.conf  
  •   pwcheck_method: authdaemond
  •   log_level: 3 #日志级别,先调试为3,方便查看调试信息,成功后设为1
  •   mech_list:PLAIN LOGIN
  •   authdaemond_path:/usr/local/courier-authlib/var/spool/authdaemon/socket
  •   

3.6 让postfix支持虚拟域和虚拟用户

  • 1、编辑/etc/postfix/main.cf,添加如下内容:
  • ##Virtual Mailbox Settings###
  • virtual_mailbox_base = /var/mailbox
  • 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:2525
  • virtual_gid_maps = static:2525
  • virtualvirtual_transport = virtual
  • maildrop_destination_recipient_limit = 1
  • maildrop_destination_concurrency_limit = 1
  • ###QUOTA Settings###
  • message_size_limit = 14336000
  • virtual_mailbox_limit = 20971520
  • 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 = Sorry, the user's maildir has  
  • overdrawn his diskspace quota, please Tidy your mailbox and try again  
  • later.
  • virtual_overquota_bounce = yes

此处只需要把相关的内容增加到/etc/postfix/main.cf即可但是一定要检查/etc/postfix/mysql_virtual_mailbox_maps.cf,etc/postfix/mysql_virtual_domains_maps.cf,/etc/postfix/mysql_virtual_alias_maps.cf三个文件是否存在,如果不存在,请手动将三个文件cp到/etc/postfix下。我就是在配置中遇到这样的问题,结果不能正常发送邮件。
3.7利用extman中的数据文件导入数据库

  • [iyunv@mail ~]# tar xf extman-1.1.tar.gz  
  • [iyunv@mail ~]# cd extman-1.1/docs   
  • [iyunv@mail docs]# mysql -u root -p < extmail.sql
  • #会遇到错误,编辑extmail.sql 执行:%s@TYPE=MyISM@ENGINE=MyISAM@g 就可以导入了。
  • #这是因为现在我们编译mysql版本较高的原因,语法格式有所改进,执行上边的命令之后就可以了
  • [iyunv@mail docs]# mysql -u root -p < init.sql
    [iyunv@mail docs]# mysql
  • Welcome to the MySQL monitor.  Commands end with ; or \g.
  • Your MySQL connection id is 16
  • Server version: 5.5.24-log MySQL Community Server (GPL)
  • Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights  
  • reserved.
  • Oracle is a registered trademark of Oracle Corporation and/or its
  • affiliates. Other names may be trademarks of their respective
  • owners.
  • Type 'help;' or '\h' for help. Type '\c' to clear the current input  

  • statement.

  • mysql> use extmail;
  • Database changed
  • mysql> show tables;
  • +-------------------+
  • | Tables_in_extmail |
  • +-------------------+
  • | alias             |
  • | domain            |
  • | domain_manager    |
  • | mailbox           |
  • | manager           |
  • +-------------------+
  • 5 rows in set (0.00 sec)

  • mysql>  
  • 3、授予用户extmail访问extmail数据库的权限
  • mysql> GRANT all privileges on extmail.* TO extmail@localhost  IDENTIFIED BY 'extmail';
  • mysql> GRANT all privileges on extmail.* TO extmail@127.0.0.1 IDENTIFIED BY 'extmail';
  • [iyunv@mail ~]# vim /etc/postfix/main.cf
  • [iyunv@mail ~]# service postfix restart
  • Shutting down postfix:                                    [  OK  ]
  • Starting postfix:                                         [  OK  ]
  • #此时不要忘记执行FLUSH PRIVILEGES ;来时用户和密码立即生效

此时就可以给予虚拟域发送邮件了,所以还要编辑main.cf注释掉myhostname, mydestination, mydomain, myorigin几个以前的配置。
4.dovecot的安装与配置
4.1安装配置dovecot
dovecot也可以源码安装,但是新版的功能并没有多大改进,所以,此处就使用rpm包来安装,但是,dovecot是有依赖关系的,建议使用yum源来进行安装。

  • [iyunv@mail ~]# yum install dovecot -y

  • # vi /etc/dovecot.conf
  • mail_location = maildir:/var/mailbox/%d/%n/Maildir # 宏 %d 代表域名  %n 代表用户名   
  • auth default {
  •     mechanisms = plain
  •     passdb sql {
  •         args = /etc/dovecot-mysql.conf
  •     }
  •     userdb sql {
  •         args = /etc/dovecot-mysql.conf
  •     }
  • #启用mysql认证,但关闭passwd pam { } 段

  • # vim /etc/dovecot-mysql.conf                  
  • driver = mysql  # 数据库驱动为mysql
  • connect = host=localhost dbname=extmail user=extmail password=extmail
  • default_pass_scheme = CRYPT
  • password_query = SELECT username AS user,password AS password FROM mailbox WHERE username = '%u'                             
  • user_query = SELECT maildir, uidnumber AS uid, gidnumber AS gid FROM mailbox WHERE username = '%u'

  • 接下来启动dovecot服务:
  • # service dovecot start
  • # chkconfig dovecot on
  • #如果不成功,我们可以启动日志,通过日志来排除错误原因,以后的工作中也要建立这样的思想哦。
  • #启用日志很简单,只要启用log_path= ;即可

5.安装Extmail-1.2
5.1 解压并提供配置文件

  • # tar zxvf extmail-1.2.tar.gz
  • # mkdir -pv /var/www/extsuite
  • # mv extmail-1.2 /var/www/extsuite/extmail
  • # cp /var/www/extsuite/extmail/webmail.cf.default   /var/www/extsuite/extmail/webmail.cf

5.2 修改配置文件,根据提供的内容做相应的修改,因为内容比较多,将内容提供如下,

  • #vi /var/www/extsuite/extmail/webmail.cf

  • 部分修改选项的说明:
  • SYS_MESSAGE_SIZE_LIMIT = 5242880
  • 用户可以发送的最大邮件
  • SYS_USER_LANG = en_US
  • 语言选项,可改作:
  • SYS_USER_LANG = zh_CN
  • SYS_MAILDIR_BASE = /home/domains
  • 此处即为您在前文所设置的用户邮件的存放目录,可改作:
  • SYS_MAILDIR_BASE = /var/mailbox
  • SYS_MYSQL_USER = db_user
  • SYS_MYSQL_PASS = db_pass
  • 以上两句句用来设置连接数据库服务器所使用用户名、密码和邮件服务器用到的数据库,这里修改为:
  • SYS_MYSQL_USER = extmail
  • SYS_MYSQL_PASS = extmail
  • SYS_MYSQL_SOCKET = /var/lib/mysql/mysql.sock
  • 修改为:
  • SYS_MYSQL_SOCKET = /tmp/mysql.sock
  • SYS_MYSQL_HOST = localhost
  • 指明数据库服务器主机名,这里默认即可
  • SYS_MYSQL_TABLE = mailbox
  • SYS_MYSQL_ATTR_USERNAME = username
  • SYS_MYSQL_ATTR_DOMAIN = domain
  • SYS_MYSQL_ATTR_PASSWD = password
  • 以上用来指定验正用户登录里所用到的表,以及用户名、域名和用户密码分别对应的表中列的名称;这里默认即可
  • SYS_AUTHLIB_SOCKET = /var/spool/authdaemon/socket
  • 此句用来指明authdaemo socket文件的位置,这里修改为:
  • SYS_AUTHLIB_SOCKET = /usr/local/courier-authlib/var/spool/authdaemon/socket

此时要提供web环境就需要安装apache此处也不使用源码编译安装最新版了,内容太多了,并建立虚拟主机,详细虚拟主机的搭建您也很熟练了,如果你还不太了解请参看我的推荐博文《教您玩转apache和虚拟主机》。

  • [iyunv@mail conf]# vim /etc/httpd/conf/httpd.conf
  • <VirtualHost *:80>
  • ServerName mail.zzu.com
  • DocumentRoot /var/www/extsuite/extmail/html/
  • ScriptAlias /extmail/cgi /var/www/extsuite/extmail/cgi
  • Alias /extmail /var/www/extsuite/extmail/html
  • SuexecUserGroup postfix postfix
  • </VirtualHost>
  • #修改 cgi执行文件属主为apache运行身份用户
  • [iyunv@mail conf]# chown -R postfix.postfix /var/www/extsuite/extmail/cgi/
  • 如果您没有打开apache服务器的suexec功能,也可以使用以下方法解决:
  • # vi /etc/httpd/httpd.conf
  • User postfix
  • Group postfix

  • <VirtualHost *:80>
  • ServerName mail.zzu.com
  • DocumentRoot /var/www/extsuite/extmail/html/
  • ScriptAlias /extmail/cgi /var/www/extsuite/extmail/cgi
  • Alias /extmail /var/www/extsuite/extmail/html
  • </VirtualHost>

6.编译安装Unix-Syslog-1.1.tar.gz 解决依赖关系

  • [iyunv@mail ~]# tar zxvf Unix-Syslog-1.1.tar.gz  
  • [iyunv@mail ~]# cd Unix-Syslog-1.1
  • [iyunv@mail Unix-Syslog-1.1]# ls
  • Artistic  MANIFEST  Makefile.PL  Syslog.pm  test.pl
  • Changes   META.yml  README       Syslog.xs
  • [iyunv@mail Unix-Syslog-1.1]# perl Makefile.PL  


  • [iyunv@mail Unix-Syslog-1.1]#make &&make install
  • [iyunv@mail Unix-Syslog-1.1]# service httpd restart
  • Stopping httpd:                                            [  OK  ]
  • Starting httpd:                                            [  OK  ]
  • [iyunv@mail Unix-Syslog-1.1]# chkconfig httpd on  

依赖关系解决了此时就可以访问extmail页面了。
7.安装配置Extman-1.1
7.1解压,并移动文件夹到/var/www/extsuite/下

  • # tar zxvf  extman-1.1.tar.gz
  • # mv extman-1.1 /var/www/extsuite/extman

7.2 修改配置文件

  • # cp /var/www/extsuite/extman/webman.cf.default  /var/www/extsuite/extman/webman.cf
  • # vim /var/www/extsuite/extman/webman.cf
  • SYS_MAILDIR_BASE = /home/domains
  • 此处即为您在前文所设置的用户邮件的存放目录,可改作:
  • SYS_MAILDIR_BASE = /var/mailbox
  • SYS_DEFAULT_UID = 1000
  • SYS_DEFAULT_GID = 1000
  • 此两处后面设定的ID号需更改为前而创建的postfix用户和postfix组的id号,本文使用的是2525,因此,上述两项需要修改为:
  • SYS_DEFAULT_UID = 2525
  • SYS_DEFAULT_GID = 2525
  • SYS_MYSQL_USER = webman
  • SYS_MYSQL_PASS = webman
  • 修改为:
  • SYS_MYSQL_USER = extmail
  • SYS_MYSQL_PASS = extmail

修改cgi目录的属组为postfix,并脚本别名添加至虚拟主机以便能正常访问extman

  • # chown -R postfix.postfix /var/www/extsuite/extman/cgi/
  • 在apache的主配置文件中Extmail的虚拟主机部分,添加如下两行
  • ScriptAlias /extman/cgi /var/www/extsuite/extman/cgi
  • Alias /extman /var/www/extsuite/extman/html

7.3创建其运行时所需的临时目录,并修改其相应的权限

  • [iyunv@mail ~]# mkdir  -pv  /tmp/extman
  • [iyunv@mail ~]# chown postfix.postfix  /tmp/extman

重新启动apache服务器,就可以访问extmail了, DSC0002.png

但是进去之后会要求输入验证码,因为此处没有安装配置php,所以就不支持动态网页,无法显示验证码,此处就只简单配置了apache,在lnmp的环境下可以支持验证码显示,去除验证码可以编辑webman.cf 修改SYS_CAPTCHA_ON = 1为SYS_CAPTCHA_ON = 0 就可以去除验证码了。如果没有安装perl-DBD-MySQL rpm包的话,缺少支持的模块也不能顺利的进入管理界面,如下 DSC0003.png

此包需要依赖mysql,所以也使用yum源来安装,此时执行

  • [iyunv@mail www]# yum install perl-DBD-mysql -y 就可以了
DSC0004.png

可以使用默认的用户名和密码进入extman后台管理页面 ,可以对虚拟域和用户账号的管理,默认管理帐号为:root@extmail.org  密码为:extmail*123* DSC0005.png

此时可以试着使用extman的管理界面增加虚拟域,申请用户,以及发送邮件了 DSC0006.png DSC0007.png DSC0008.png

DSC0009.png

此处我注册了两个账号,zhangsan@zzu.com 和lisi@zzu.com 分别登陆邮箱,给对方发送邮件 DSC00010.png

使用lisi的账号给zhansan@zzu.com发送邮件 DSC00011.png DSC00012.png

zhangsan@zzu.com 收到李四发来的邮件,图片就不多放,extman图形界面的管理模式大家很快就会掌握配置。 DSC00013.png

还是那句话,要学会多观察日志,看一下日志。 DSC00014.png


此时postfix就算是大功告成了,用了一天半夜的时间完成了实验和博客,一个人在错误与摸索中前进,终于还是完成了postfix邮件服务器的搭建,但在实际运用中还要做相应的改进与优化。步骤之繁杂,代码之繁多,加上知识有限,未免会有什么错误之处,你发现之后请您留言,我会及时更正,不断完善,从一无所知到满腹经纶,不断学习,不断完善才是学习之道。希望对您有帮助,精彩博文继续推出,希望大家继续关注。。。。
  本文出自 “章小鱼儿_linux” 博客,请务必保留此出处http://zhangxylinux.blog.iyunv.com/5041623/930452
  
  ##########################################################
  
  http://www.gretheer.com/2013/06/64-centos-linux-postfix-email-smtp.html
  该文章由博主原创,有疑问的朋友请直接留言。
需求说明
  这次想要做的功能,只是为了给客户发送订阅邮件,也就是只有发送邮件,没有接收邮件的功能。如果不需要接收邮件的功能,尽量关闭接收外来邮件功能,危害多多。比如,大量垃圾邮件的涌入会爆满你的磁盘,安全方面也会存在隐患。
  以前发送邮件一直都在用 Sendmail 服务,最近看到 Postfix,研究了下,发现比较 Sendmail 安装配置简单,而且效率非常高。公司最近也在开发邮件营销的功能,所以细心研究了下 Postfix 的安装和配置。
Postfix 介绍
  postfix是Wietse Venema想要为使用最广泛的sendmail提供替代品的一个尝试。在Internet世界中,大部分的电子邮件都是通过sendmail来投递的,大约有100万用户使用sendmail,每天投递上亿封邮件。这真实一个让人吃惊的数字。Postfix试图更快、更容易管理、更安全,同时还与sendmail保持足够的兼容性。
  Postfix 邮件服务相对于 Sendmail 邮件服务而言,效率更高。Postfix 邮件系统完全兼容 Sendmail,下面来具体说说它的优点:
  1. Postfix 是免费的。因为它试图让更多的网络用户使用它,所以它是免费的。
  2. Postfix 比 Sendmail 更快,官方说大约可以快上3倍,本人没有测试过,一台运行 Postfix 的台式 PC 机,每天可以收发上百万封邮件。(这也是本人选择它的目的)
  3. 兼容性好,Postfix 与 Sendmail 完全兼容,这样 Sendmail 用户就可以很容易的把服务迁移到 Postfix 上。
  4. Postfix 的健壮性。Postfix 被设计成在重负荷之下仍然可以正常工作。当系统运行超出了可用的内存或磁盘空间时,Postfix 会自动减少运行进程的数目。当处理的邮件数目增长时,Postfix 运行的进程不会跟着增加。
  5. Postfix 的灵活性。Postfix 是由超过一打的小程序组成的,每个程序完成特定的功能。你可以通过配置文件设置每个运行程序的参数。
  6. Postfix 的安全性更高。Postfix 具有多层防御结构,可以有效地抵御恶意入侵者。如大多数的 Postfix 程序可以运行在较低的权限之下,不可以通过网络访问与安全性相关的本地投递程序等。(使用较低权限的用户执行程序会大大提高系统的安全性)
添加MX记录
  由于MX记录添加后,可能生效要等待一段时间(通常为数分钟或数十分钟,也可能马上生效),所以在安装配置前,我们首先为域名添加MX记录。添加方法也会因域名ISP的不同而不同,但大致信息如下:
主机记录记录类型记录值MX优先级TTLmailA192.168.1.1-600@MXmail.example.com.10600  mail为别名,10为优先度。这个别名指向服务器的IP地址。(如有疑问或需要帮忙请直接留言求助)
  DNSPOD设置示例:

忙碌的松鼠-64位 CentOS 6.4 Linux系统 搭建 Postfix 邮件服务
  确认MX记录的添加是否生效的方法:
  命令如下:



1[iyunv@example.com ~]# host example.com

2example.com has address 192.168.1.1

3example.com mail is handled by 10 mail.example.com.

4[iyunv@example.com ~]#
Postfix 安装
  1. CentOS 6.0 以上版本 默认已经安装 Postfix服务 并随着系统的启动而启动。(CentOS 6.0 以上版本请直接略过本节,直接查看如何配置)
  2. CentOS 6.0 以下或RedHat的系统,它默认安装及启动的是 Sendmail 服务,这里我们要先关闭它,并配置为不随着系统的启动而启动,命令如下:



1service sendmail stop

2chkconfig sendmail off
  3. yum 安装 Postfix 软件包,命令如下:



1yum -y install postfix
  安装完成后我们可以用命令查看其相关路径和文件,命令如下:



1rpm -ql postfix
  4. 配置 Postfix 的相关文件,它的主要配置文件为 /etc/postfix/mail.cf。
修改任何配置文件前,请先备份一下,以防修改失败后无法恢复。(这是个好习惯哦)



1# 备份配置文件

2cp /etc/postfix/main.cf /etc/postfix/main.cf.bak



1vi /etc/postfix/main.cf
  设置运行 Postfix 服务的邮件主机的主机名、域名,如下所示:



1# main.cf 第77行附近

2myhostname = mail.example.com



1# main.cf 第85行附近

2mydomain = example.com
  设置由本机寄出的邮件所使用的域名或主机名称,如下所示:



1# main.cf 第102行附近,这里使用的是 mydomain 的值,也可以自己设置值,如:myrogin = example.com

2myorigin = $mydomain
  设置 Postfix 服务监听的网络接口,如下所示:



1# main.cf 第119行附近,填写 localhost,只允许通过 localhost 或 127.0.0.1 发送

2# 如果邮件服务器是专门为其它服务器服务的,请直接填写 all,如

3# inet_interfaces = all

4inet_interfaces = localhost
  设置可接收邮件的主机名称或域名,如下所示:



1# main.cf 第167行附近,我的需求是只发送邮件,不接收外来邮件,所以填写 localhost

2mydestination = localhost
  设置可转发哪些网络的邮件,如下所示:



1# main.cf 第270行附近,主转发本机的

2mynetworks = 127.0.0.0/8, hash:/etc/postfix/access
  设置可转发哪些网域(当然这个也必须能由DNS正常解析才行)的邮件,此选项针对上下级MTA而言,区别于 Postfix 的 access,一般选择默认选项即可,如下所示:



1# main.cf 第301行附近

2relay_domains = $mydestination
  5. 配置完成后,我们检查一下 Postfix 语法,然后启动它。
用以下命令检查 Postfix 服务的语法:



1/usr/sbin/postconf -n
  启动 Postfix 邮件,并配置为自启动服务:



1service postfix start

2chkconfig postfix on
测试发送邮件
  简单的用命令行的方式,给自己发送一封邮件,命令如下:



1# example@126.com 换成自己的邮箱地址

2echo 'test' | mail -s 'test' example@126.com
  效果图:

忙碌的松鼠-64位 CentOS 6.4 Linux系统 搭建 Postfix 邮件服务
  稍后,我会发布关于 配置 Postfix 启用 SMTP 的认证机制
  该文章由博主原创,有疑问的朋友请直接留言。
  http://www.gretheer.com/2013/06/64-centos-linux-postfix-smtp-auth.html
Postfix 的安装
  本博客已经有 Postfix 的安装教程,在此就不再重复。
Linux 下安装 Postfix 教程,请看:
www.gretheer.com/2013/06/64-centos-linux-postfix-email-smtp.html
配置 Postfix 启用 SMTP 认证
  1. 安装 cyrus-sasl 软件包,它牵涉的依赖关系包比较多,命令如下:



1yum -y install cyrus-sasl*
  命令的结果显示,如下:



01Loaded plugins: fastestmirror, security

02Loading mirror speeds from cached hostfile

03 * epel: ftp.kddilabs.jp

04Setting up Install Process

05Package cyrus-sasl-lib-2.1.23-13.el6_3.1.x86_64 already installed and latest version

06Package cyrus-sasl-ntlm-2.1.23-13.el6_3.1.x86_64 already installed and latest version

07Package cyrus-sasl-plain-2.1.23-13.el6_3.1.x86_64 already installed and latest version

08Package cyrus-sasl-md5-2.1.23-13.el6_3.1.x86_64 already installed and latest version

09Package cyrus-sasl-2.1.23-13.el6_3.1.x86_64 already installed and latest version

10Package cyrus-sasl-devel-2.1.23-13.el6_3.1.x86_64 already installed and latest version

11Package cyrus-sasl-ldap-2.1.23-13.el6_3.1.x86_64 already installed and latest version

12Package cyrus-sasl-sql-2.1.23-13.el6_3.1.x86_64 already installed and latest version

13Package cyrus-sasl-gssapi-2.1.23-13.el6_3.1.x86_64 already installed and latest version

14Nothing to do
  因为我已经安装过了,所以显示的是 Nothing to do,你第一次安装,会有几个 Complete。
  我们可以用以下命令启动 saslauthd 服务,并配置成自启动服务:



1service saslauthd start

2chkconfig saslauthd on
  2. 添加下列内容到主配置文件,让 Postfix 启用 SMTP 认证,代码如下:



1# 把此代码添加到 /etc/postfix/main.cf 最后

2# smtp

3smtpd_sasl_auth_enable = yes

4smtpd_sasl_local_domain = ''

5smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination

6broken_sasl_auth_clients = yes

7smtpd_client_restrictions = permit_sasl_authenticated

8smtpd_sasl_security_options = noanonymous
  完成以上步骤后,全新加载配置,命令如下:



1postfix reload
测试
  使用 phpmailer 测试 Postfix 的 SMTP 是否有效,代码如下:
  phpmailer 请自行下载,下载地址: github.com/Synchro/PHPMailer
  PHP 测试代码:
  test.php



01<?php

02set_time_limit (0);

03

04require_once('./class.phpmailer.php');

05

06// 测试发送附件专用

07$tmp_file = '/tmp/test.jpg';

08

09$mail = new PHPMailer(true);

10

11// 是否为 SMTP 认证

12$mail->IsSMTP();

13

14try {

15    // 服务器 IP,程序在本地使用,所以填写 127.0.0.1,

16    $mail->Host       = "127.0.0.1";

17    // 调试模式关闭

18    $mail->SMTPDebug  = 0;

19    // 是否开户 SMTP 认证

20    $mail->SMTPAuth   = true;

21    // SMTP 认证用户名,此处填写系统用户名,可以专门创建一个普通用户用于发送邮件

22    $mail->Username   = "username";

23    // SMTP 认证用户密码,此处填写与系统用户名对应的系统用户密码

24    $mail->Password   = 'password';

25    // 设置邮件内容字符集,防止中文乱码

26    $mail->CharSet = 'UTF-8';

27    // 接收邮件地址

28    $mail->AddAddress('abcdef@126.com', '忙碌的松鼠');

29    // 设置我的邮件地址

30    $mail->SetFrom('info@example.com', '忙碌的松鼠');

31    // 邮件标题

32    $mail->Subject = '欢迎大家关注 忙碌的松鼠';

33    // 邮件内容,可以是HTML代码

34    $mail->MsgHTML('欢迎大家关注 忙碌的松鼠 博客,博客地址:http;//www.gretheer.com');

35    // 添加附件

36    $mail->AddAttachment($tmp_file);

37    // 发送

38    $mail->Send();

39} catch (Exception $e) {

40    // 报错信息

41    echo $mail->ErrorInfo;

42}

43?>
  注意:
1. 可以在命令行下测试,最好使用普通用户测试。



1php test.php
  2. 用浏览器访问PHP文件测试时,如果没有接收到邮件,看是否是PHP文件权限问题,包括PHP文件内,include,require 等包含的文件的权限。
  该文章由博主原创,有疑问的朋友请直接留言。
  ---------------------------------------------------------------------------------------------------------
  http://www.iewb.net/index.php/qg/4062.html
  前些日子Google+上一个本地的网友Email给我,说是老板让他做一个邮件服务器,他搞了十多天了还没搞定,让我帮下忙,今天把过程分享下,希望对学习做邮件服务器的新手朋友有点帮助。
  
  相关环境:
  Centos6.2  有公网IP(省了映射了),域名MX记录解析已经完成,要求能让客户端使用POP3/IMAP收发邮件,另外他们老板还有个要求让我无视了,那就是想要个和126邮箱一样的webmail。看他要求过分我就告诉他可以给他带个webmail不过要收费8000,并且界面肯定和126这样的邮箱没法比。你妈,还真以为网上什么东西都能下载到…
  开工,安装软件先:
  yum install postfix , dovecot
  修改下postfix的配置文件main.cf,修改前备份是个好习惯哦。
  cp /etc/postfix/main.cf main.cf.bak
  vi /etc/postfix/main.cf
  我爱死Yum了,有了Yum腰不酸、腿不疼,安装软件不费劲。
  需要修改的内容如下:
  myhostname =                  //主机名(mail.test.com) mydomain =                        //你的域名(test.com) myorigin = $mydomain  //去掉前面#号就可以 inet_interfaces = all       //最新版默认就是这个,如果你下载的版本前面带#,请去掉 mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain    //添加一个$mydomain mynetworks = 127.0.0.0/8, 192.168.6.0/24              //根据你的情况配置网段 relay_domains = $mydestination                               //默认就是这样,如果你也是的话不用修改 home_mailbox = Maildir/                                              //去掉前面#
  其实配置完这些这台服务器已经可以收发邮件了,我们先关闭iptables和selinux测试下。
  service postfix start
  mail -s "This ia the first test mail" caoqiguang@gmail.com</etc/hosts
  在其它电脑上一看,正常收到邮件,都不用telnet下25端口了。
  当然这离老板的要求还有些距离,我们还要配置下pop3和imap。
  编辑/etc/postfix/main.cf,在最下方增加如下代码启用sasl认证。
  smtpd_sasl_type = dovecot smtpd_sasl_path = private/auth smtpd_sasl_auth_enable = yes smtpd_recipient_restrictions =  permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination broken_sasl_auth_clients = yes
  对于dovecot的配置文件dovecot.conf其实不用做其它修改,只需加入以下代码即可:
  auth default { socket listen { client { path = /var/spool/postfix/private/auth mode = 0660 user = postfix group = postfix }  } mechanisms = plain login }

我看了下网上的一些教程,都好像要修改很多东西似的,其实不用,很多都不重要,一个比较重要的就是要在protocols项的后面加上pop3,其实这个现在的版本官方配置就已经是这样了。


  启动dovecot,telnet了下110和143都正常,于是

chkconfig dovecot on chkconfig postfix on

  然后跑到windows服务器上使用foxmail测试,正常收发信,完工。在他公司一共呆了一个小时左右,真正部署Mail服务器用时5分钟。当然这是个非常简易的服务器,没有配置垃圾邮件过滤和病毒过滤,也没给他安装webmail,不过没收钱嘛,更多其它的功能让他们自己搞去吧。  ==========================================================
  
  
  http://my.oschina.net/luobo/blog/73772
  在unix下发送邮件并一定需要安装postfix这类大型的smtp服务器软件,用msmtp就很好地解决unix下发邮件的问题。但既然把《Postfix权威指南》看了不下10遍却又依然解决不了postfix的架设问题实在让人火大。
  
  先来说说我为什么选择postfix来作为邮件服务器的原因。在决定安装postfix前我比较了几种流行的邮件服务器解决方案,postfix、 sendmail、qmail、exim等。sendmail和qmail据说很老了,要么很久没更新,要么配置复杂,exim倒不错,是debian下 的推荐邮件服务器,但是担心与debian结合的太过紧密会影响它在其它平台上的表现,所以即便在debian下通过dpkg系列命令就可搭建 smarthost类型的邮件服务器也只好作罢。最后的选择是postfix。
  
  再说说与postfix的相遇经历,呵呵,真的是很偶然,以前上大学的时候经常去图书馆看IT方面的书,图书馆里放置it书籍的那几排书架我闭着眼 睛都能说出哪本书在什么位置(呵呵,开玩笑呢)。有一排书架上放的是邮件服务器架设的书籍,上面有介绍qmail、postfix、sendmail、 exchange等等的书。因为《Postfix 权威指南》这本书比较新,所以想当然地认为介绍的内容应该与最新版本的Postfix是一致的吧。虽然后面发现其实这本书上介绍的很多配置项已经过时了, 最新版本的postfix体现的方便特性没有在此本书上反映出来,不过除去这一缺点这本书整体来说还是不错的。
  前面说了这么多的铺垫,现在才进入正题。
  第一,generic选项
  这个选项是用来控制smtp对话过程中mail from问题的。很多邮件系统,比如163的smtp服务,要求smtp对话过程中的mail from的回答必须为163域名的邮箱。这个mail from是一个基本的反垃圾邮件的功能。当然仅靠mail from显然阻止不了太多的垃圾邮件的,最多用来磨炼一下像我这样的菜鸟。
  在一些老版本的postfix中没有generic这个选项就比较麻烦了,得用规划表(canonial ? sender_canonial?)对发件人地址进行重写,这个是不仅对smtp对话过程中的mail from地址(即信封地址)进行改写,还会改写邮件中的From:地址。所以还是用新版本的postfix比较好。
  第二,relay_host选项
  设置smtp代理地址,如果要用163邮箱代发自己的邮件,要在163上注册一个邮箱,再把realy_host选项设为163的smtp服务地址。
  你是否需要设relay_host选项。如果你的电脑没有独立ip(很贵,不是一般人能买得起)或没有自己的域名(搞到这个可能没那么难)那就要设 realy_host了。而且很多relay_host都要求进行sasl认证,这就要求有用户名、密码什么的了。我对sasl服务的架设没了解过,这里 不谈。
  第三,postmap
  在用postmap生成规划表或别名表的时候一定要加上要生成的表的类型,main.cf中相应配置变量的表类型要与postmap生成表的时候的类型一致。
  比如:
  # postmap hash:generic
  在main.cf中:
  generic = hash:generic
  
好了,以上就是postfix配置过程中的一些心得。第三点是我纠结了很长时间的一个问题,现在看来很可笑。其它的fetchmail啊,mutt啊什么的就不谈了。
  ps1:mutt配m3m看html附件中有中文的邮件,lynx真心蛋痛。
  ps2:发现blogbus的html编辑器竟带有快捷键,键的绑定与bash里的是一致的。这个功能真心不错,很geek。
  ===========================================================================
  
  http://db.nipusa.net/mysql/a-2347.html
  CenTOS 5下面用自带的RPM包安装基于Postfix的邮件系统(MySQL) (Postfix+Mysql+Dovecot+Extmail+Extman+Mailscanner+Spamassassin+Clamav) Author:汪洋 Nickname:ruochen / ruochen0926 Date:20070927 Version:1.0 Contact: E-Mail:ruochen0926(at)gmail.com  QQ:967409 Blog:http://ruochen.cublog.cn/ Note:参考了网上很多网友的帖子,都比较零散,不一一列出,如果在安装或者使用过程中有疑问,请到我的blog跟帖,我会尽快回复
  目录: 目标:配置一个功能齐全的Mail系统 1)安装需要的软件包 2)DNS相关配置 2.1)建立正向反向和MX记录 2.2)测试DNS配置 3)安装Postfix 4)配置Postfix 4.1)配置Postfix的主配置文件 /etc/postfix/main.cf 4.2)配置Postfix虚拟用户的配置文件 5)配置dovecot (IMAP/IMAPS/POP3/POP3S) 5.1)配置dovecot的主配置文件/etc/dovecot.conf 5.2)配置dovecot的mysql认证配置文件 6)测试发信认证及收信 6.1)LOGIN登录测试 6.2)pop3收信测试 7)安装Extmail-1.0.2 7.1)解压安装 7.2)修改Extmail主配置文件 7.3)APACHE相关配置 7.4)Extmail依赖关系的解决 8)安装Extman-0.2.2 8.1)解压安装 8.2)修改Extman的主配置文件 8.3)APACHE相关配置 9)开启Apache/Mysql/Bind,并让他们自启动 10)安装反垃圾SpamAssassin 11)安装反病毒Clamav 12)安装MailScanner
  
  1)安装需要的软件包 Mysql部分 [iyunv@mailtest /]# rpm -qa|grep mysql mysql-connector-odbc-3.51.12-2.2 mysql-devel-5.0.22-2.1 mysql-server-5.0.22-2.1 mod_auth_mysql-3.0.0-3.1 php-mysql-5.1.6-15.el5 mysql-5.0.22-2.1 libdbi-dbd-mysql-0.8.1a-1.2.2
  Http部分 [iyunv@mailtest /]# rpm -qa|grep http httpd-2.2.3-6.el5.centos.1
  Php部分 [iyunv@mailtest /]# rpm -qa|grep php php-mysql-5.1.6-5.el5 php-5.1.6-5.el5 php-mbstring-5.1.6-5.el5 php-common-5.1.6-5.el5 php-cli-5.1.6-5.el5 php-pdo-5.1.6-5.el5 php-gd-5.1.6-5.el5
  Perl部分 [iyunv@mailtest noarch]# rpm -qa|grep perl perl-HTML-Tagset-3.10-2.1.1 perl-Digest-HMAC-1.01-15 perl-HTML-Parser-3.56-1 perl-Sys-Hostname-Long-1.4-1 perl-Net-DNS-0.59-1.fc6 perl-XML-SAX-0.14-5 perl-IO-stringy-2.108-1 perl-DBI-1.56-1 perl-5.8.8-10 mod_perl-2.0.2-6.1 perl-Socket6-0.19-3.fc6 perl-IO-Socket-INET6-2.51-2.fc6 perl-IO-String-1.08-1.1.1 perl-Convert-ASN1-0.20-1.1 perl-TimeDate-1.16-3 perl-MIME-tools-5.420-1 perl-DBD-SQLite-1.13-1 perl-BSD-Resource-1.28-1.fc6.1 perl-DBD-MySQL-3.0007-1.fc6 perl-IO-Zlib-1.04-4.2.1 perl-Digest-SHA1-2.11-1.2.1 perl-Archive-Tar-1.30-1.fc6 perl-IO-Socket-SSL-1.01-1.fc6 perl-LDAP-0.33-3.fc6 perl-libwww-perl-5.805-1.1.1 perl-MailTools-1.71-1 perl-Convert-TNEF-0.17-1 perl-Filesys-Df-0.90-1 perl-URI-1.35-3 perl-Compress-Zlib-1.42-1.fc6 perl-Net-IP-1.25-2.fc6 perl-XML-NamespaceSupport-1.09-1.2.1 perl-Net-CIDR-0.11-1 perl-Archive-Zip-1.16-1 perl-String-CRC32-1.4-2.fc6 perl-Net-SSLeay-1.30-4.fc6 perl-Convert-BinHex-1.119-2
  Spamassassin部分 [iyunv@mailtest /]# rpm -qa|grep spamassassin spamassassin-3.1.7-4.el5
  Dovecot部分 [iyunv@mailtest /]# rpm -qa|grep dovecot dovecot-1.0-1.2.rc15.el5  #imap imaps pop3 pop3s
  Cyrus-sasl部分 [iyunv@mailtest /]# rpm -qa|grep cyrus-sasl cyrus-sasl-lib-2.1.22-4 cyrus-sasl-plain-2.1.22-4 cyrus-sasl-devel-2.1.22-4 cyrus-sasl-2.1.22-4 cyrus-sasl-md5-2.1.22-4 cyrus-sasl-sql-2.1.22-4
  
  Spamassassin所依赖的包 perl-Archive-Tar-1.30-1.fc6.noarch.rpm     perl-IO-Socket-SSL-1.01-1.fc6.noarch.rpm perl-Compress-Zlib-1.42-1.fc6.i386.rpm      perl-IO-Zlib-1.04-4.2.1.noarch.rpm perl-Digest-HMAC-1.01-15.noarch.rpm         perl-Net-DNS-0.59-1.fc6.i386.rpm perl-Digest-SHA1-2.11-1.2.1.i386.rpm        perl-Net-IP-1.25-2.fc6.noarch.rpm perl-HTML-Parser-3.55-1.fc6.i386.rpm        perl-Net-SSLeay-1.30-4.fc6.i386.rpm perl-HTML-Tagset-3.10-2.1.1.noarch.rpm      perl-Socket6-0.19-3.fc6.i386.rpm perl-IO-Socket-INET6-2.51-2.fc6.noarch.rpm
  
  Postfix所依赖的包 db4-devel-4.3.29-9.fc6.i386.rpm e2fsprogs-devel-1.39-8.el5.i386.rpm krb5-devel-1.5-17.i386.rpm zlib-devel-1.2.3-3.i386.rpm openssl-devel-0.9.8b-8.3.el5.i386.rpm mysql-devel-5.0.22-2.1.i386.rpm cyrus-sasl-devel-2.1.22-4.i386.rpm
  gcc所依赖的包 libgomp-4.1.1-52.el5.i386.rpm gcc-4.1.1-52.el5.i386.rpm
  其他软件包 perl-libwww-perl-5.805-1.1.1.noarch.rpm avahi-compat-howl-0.6.16-1.el5.i386.rpm openldap-servers-sql-2.3.27-5.i386.rpm perl-LDAP-0.33-3.fc6.noarch.rpm kernel-devel-2.6.18-8.el5.i686.rpm elfutils-libelf-0.125-3.el5.i386.rpm elfutils-libelf-devel-0.125-3.el5.i386.rpm rpm-build-4.4.2-37.el5.i386.rpm
  建议安装与系统管理相关的两个包 nmap-4.11-1.1.i386.rpm sysstat-7.0.0-3.el5.i386.rpm 下面的两个软件包用于clamav的数字签名 gmp-devel-4.1.4-10.el5 gmp-4.1.4-10.el5
  
  2)DNS相关配置 2.1)建立正向反向和MX记录 [iyunv@mailtest ~]# cat /var/named/named.test.hk $TTL 86400 @                         IN          SOA        test.hk.         test1.test.hk  (                                                 1997022700 ; Serial                                                 28800      ; Refresh                                                 14400      ; Retry                                                 3600000    ; Expire                                                 86400 )    ; Minimum                         IN          NS         mailtest test.hk.                IN          MX  5      mail.test.hk. mail                    IN          A          10.10.119.204 mailtest                IN          A          10.10.119.204 [iyunv@mailtest ~]# cat /var/named/named.10.10.119 $TTL 86400 @                         IN          SOA        test.hk.         test1.test.hk  (                                       1997022700 ; Serial                                       28800      ; Refresh                                       14400      ; Retry                                       3600000    ; Expire                                       86400 )    ; Minimum                      IN             NS      mailtest 204                  IN             PTR     mail.test.hk. 204                  IN             PTR     mailtest.test.hk. [iyunv@mailtest ~]# hostname mailtest.test.hk
  2.2)测试DNS配置 [iyunv@mailtest ~]# nslookup mail.test.hk Server:         10.10.119.204 Address:        10.10.119.204#53
  Name:   mail.test.hk Address: 10.10.119.204
  [iyunv@mailtest ~]# nslookup mailtest.test.hk Server:         10.10.119.204 Address:        10.10.119.204#53
  Name:   mailtest.test.hk Address: 10.10.119.204
  [iyunv@mailtest ~]# nslookup 10.10.119.204 Server:         10.10.119.204 Address:        10.10.119.204#53
  204.119.10.10.in-addr.arpa      name = mail.test.hk. 204.119.10.10.in-addr.arpa      name = mailtest.test.hk.
  [iyunv@mailtest ~]# ping mailtest.test.hk PING mailtest.test.hk (10.10.119.204) 56(84) bytes of data. 64 bytes from mailtest.test.hk (10.10.119.204): icmp_seq=1 ttl=64 time=0.793 ms 64 bytes from mailtest.test.hk (10.10.119.204): icmp_seq=2 ttl=64 time=0.046 ms 64 bytes from mailtest.test.hk (10.10.119.204): icmp_seq=3 ttl=64 time=0.040 ms
  --- mailtest.test.hk ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 2002ms rtt min/avg/max/mdev = 0.040/0.293/0.793/0.353 ms [iyunv@mailtest ~]# ping mail.test.hk PING mail.test.hk (10.10.119.204) 56(84) bytes of data. 64 bytes from mail.test.hk (10.10.119.204): icmp_seq=1 ttl=64 time=0.395 ms 64 bytes from mail.test.hk (10.10.119.204): icmp_seq=2 ttl=64 time=0.037 ms 64 bytes from mail.test.hk (10.10.119.204): icmp_seq=3 ttl=64 time=0.038 ms
  --- mail.test.hk ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 2001ms rtt min/avg/max/mdev = 0.037/0.156/0.395/0.169 ms
  Note:DNS的配置错误多看Bind的日志文件/var/log/messages
  3)安装Postfix 虽然CentOS 5自带Postfix,但因为其不支持SSL及Mysql/LDAP,所以我们需要自行编译
  [iyunv@mailtest /]# rpm -e sendmail --nodeps   #卸载系统自带的sendmail [iyunv@mailtest /]# groupadd postfix    #添加postfix用户 [iyunv@mailtest /]# groupadd postdrop    #添加postdrop组 [iyunv@mailtest /]# useradd postfix -g postfix -G postdrop -c "Postfix User" -d /dev/null -s /sbin/nologin #添加postfix用户 [iyunv@mailtest /]# mkdir -pv /tmp/postfix   #建立postfix的临时目录 [iyunv@mailtest /]# chown -R postfix.postfix /tmp/postfix #给postfix的临时目录相关权限 [iyunv@mailtest /]# mkdir -pv /home/domains/   #建立虚拟邮件用户的邮件存放目录 [iyunv@mailtest /]# chown -R postfix.postfix /home/  #给虚拟邮件用户的邮件存放目录相关权限 [iyunv@mailtest /]# tar zxvf postfix-2.4.6.tar.gz        #解压postfix包 [iyunv@mailtest /]# cd postfix-2.4.6          #进入postfix解压目录 [iyunv@mailtest postfix-2.4.5]# make -f Makefile.init makefiles 'CCARGS=-DHAS_MYSQL -I/usr/include/mysql -DUSE_TLS -DUSE_CYRUS_SASL -DUSE_SASL_AUTH -I/usr/include/sasl -DHAS_LDAP' 'AUXLIBS=-L/usr/lib/mysql -lmysqlclient -lz -lm -L/usr/lib -lssl -lcrypto -lsasl2 -L/usr/lib/openldap -llber -lldap'  
  #配置编译环境支持sasl/tls/mysql/ldap.相关编译参数参考readme文件 #在64bit的机器上安装,要将参数里面的lib换成lib64      
  [iyunv@mailtest postfix-2.4.6]# make  #编译postfix [iyunv@mailtest postfix-2.4.6]# make install #安装postfix文件到相应目录并配置 Note:make install命令后的所有问题都直接敲回车键即可。最好能改下临时目录到/tmp/postfix
  生成别名二进制文件,这个步骤如果忽略,会造成postfix效率极低: [iyunv@mailtest postfix-2.4.6]#  newaliases
  4)配置Postfix 4.1)配置Postfix的主配置文件 /etc/postfix/main.cf #=====================BASE========================= myhostname = mail.test.hk     #postfix服务的邮件主机的主机名,建虚拟域时不要建这个同名的 mydomain = test.hk      #postfix服务的邮件主机的域名 myorigin = $mydomain      #设置由本机寄出的邮件所使用的域名或主机名称 mydestination = $myhostname localhost localhost.$mydomain #设置可接收邮件的主机名称或域名 mynetworks = 10.10.119.0/24 127.0.0.0/8    #设置可转发哪些网络的邮件,不需要认证的网段 inet_interfaces = all      #设置postfix服务监听的网络接口 #relay_domains = $mydestination     #设置可转发哪些网域的邮件
  #=====================Vritual Mailbox settings========================= virtual_mailbox_base = /home/domains virtual_mailbox_maps = mysql:/etc/postfix/mysql/mysql_virtual_mailbox_maps.cf virtual_mailbox_domains = mysql:/etc/postfix/mysql/mysql_virtual_domains_maps.cf virtual_alias_domains = virtual_alias_maps = mysql:/etc/postfix/mysql/mysql_virtual_alias_maps.cf virtual_uid_maps = static:501 virtual_gid_maps = static:502 virtual_transport = virtual maildrop_destination_recipient_limit = 1 maildrop_destination_concurrency_limit = 1
  #====================QUOTA======================== message_size_limit = 5242880  #每个邮件最大尺寸5M mailbox_size_limit = 209715200  #邮箱大小限制200M virtual_mailbox_limit = 209715200 #虚拟邮箱大小限制200M virtual_create_maildirsize = yes virtual_mailbox_extended = yes virtual_mailbox_limit_maps = mysql:/etc/postfix/mysql/mysql_virtual_limit_maps.cf virtual_mailbox_limit_override = yes virtual_maildir_limit_message = Sorry, the user's maildir has overdrawn his diskspace quota, please try again later. virtual_overquota_bounce = yes
  #====================SASL======================== smtpd_sasl_type = dovecot    #使用dovecot进行验证 smtpd_sasl_path = /var/run/dovecot/auth-client  #与dovecot.conf中如下的的path一致 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
  
  # From: 本地域           To: 任何地址      必须认证且验证用户和From:必须一致 # From: 任何非本地地址   To: 本地地址     无需认证 # From: 任何非本地       To: 任何地址     拒绝
  #列出本地用户的列表,以便验证 From: 本地域 To: 本地域 #smtpd_sender_login_maps = #    mysql:/etc/postfix/mysql/mysql_virtual_sender_maps.cf, #    mysql:/etc/postfix/mysql/mysql_virtual_alias_maps.cf
  #smtpd_reject_unlisted_sender = yes
  #本地域向本地域发信也需要SMTP身份验证 #smtpd_sender_restrictions = #    reject_sender_login_mismatch, #    reject_authenticated_sender_login_mismatch, #    reject_unauthenticated_sender_login_mismatch
  #smtpd_error_sleep_time = 1s #smtpd_soft_error_limit = 10 #smtpd_hard_error_limit = 20
  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
  #====================SSL/TLS======================== 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
  生成证书 [iyunv@mailtest postfix]# mkdir /etc/ssl [iyunv@mailtest postfix]# cd /etc/ssl [iyunv@mailtest ssl]# openssl req -new -x509 -nodes -out smtpd.pem -keyout smtpd.pem -days 3650 Generating a 1024 bit RSA private key ..++++++ ..++++++ writing new private key to 'smtpd.pem' ----- You are about to be asked to enter information that will be incorporated into your certificate request. What you are about to enter is what is called a Distinguished Name or a DN. There are quite a few fields but you can leave some blank For some fields there will be a default value, If you enter '.', the field will be left blank. ----- Country Name (2 letter code) [GB]:CN State or Province Name (full name) [Berkshire]:GD Locality Name (eg, city) [Newbury]:DG Organization Name (eg, company) [My Company Ltd]:www.test.hk Organizational Unit Name (eg, section) []:PROC Common Name (eg, your name or your server's hostname) []:www.test.hk Email Address []:test1@test.hk
  4.2)配置Postfix虚拟用户的配置文件 [iyunv@mailtest mysql]# vi /etc/postfix/mysql/mysql_virtual_alias_maps.cf user = extmail password = extmail hosts = localhost dbname = extmail table = alias select_field = goto where_field = address additional_conditions = AND active = '1'
  [iyunv@mailtest mysql]# vi /etc/postfix/mysql/mysql_virtual_domains_maps.cf user = extmail password = extmail hosts = localhost dbname = extmail table = domain select_field = domain where_field = domain additional_conditions = AND active = '1'
  [iyunv@mailtest mysql]# vi /etc/postfix/mysql/mysql_virtual_limit_maps.cf user = extmail password = extmail hosts = localhost dbname = extmail table = mailbox select_field = quota where_field = username additional_conditions = AND active = '1'
  [iyunv@mailtest mysql]# vi /etc/postfix/mysql/mysql_virtual_mailbox_maps.cf user = extmail password = extmail hosts = localhost dbname = extmail table = mailbox select_field = maildir where_field = username additional_conditions = AND active = '1'
  
  5)配置dovecot 5.1)配置dovecot的主配置文件/etc/dovecot.conf [iyunv@mailtest /]# cp /etc/dovecot.conf /etc/dovecot.conf-orig #备份一份dovecot的原始配置文件 [iyunv@mailtest /]# vi /etc/dovecot.conf    #编辑dovecot配置文件 base_dir=/var/run/dovecot protocols=imap imaps pop3 pop3s listen=* mail_location = maildir:/vmail/domains/%d/%n/Maildir  #虚拟用户maildir形式的邮箱路径(和Extmail一致) auth default { mechanisms = plain login digest-md5 cram-md5 ntlm rpa apop anonymous gssapi  #认证方法(ldap认证不支持除plain login外的) passdb sql {       #去掉前面的注释 args = /etc/dovecot-sql.conf     #定义mysql文件路径 userdb sql {       #去掉前面的注释 args = /etc/dovecot-sql.conf     #定义mysql文件路径 socket listen { client { path = /var/run/dovecot/auth-client       mode = 0660       user = postfix      #添加       group = postfix      #添加     }        #去掉前面的注释   }        #去掉前面的注释 }
  5.2)配置dovecot的mysql认证配置文件 [iyunv@mailtest ~]# more /etc/dovecot-sql.conf driver = mysql connect = host=/var/lib/mysql/mysql.sock dbname=extmail user=extmail password=extmail default_pass_scheme = MD5 #password_query = select username as user,password from mailbox where substring(username,1,instr(username,'@')-1) = '%n' and active='1'  #这样些的话,不同的域有相同的用户的话会出现多个匹配导致认证失败 password_query = select username as user,password from mailbox where username = '%u' and active='1' user_query = select maildir as home,501 as uid ,502 as gid from mailbox where username='%u' and active='1'
  
  6)测试发信认证及收信 您可以通过登录postfixadmin新建虚拟域和虚拟用户,也可以直接在mysql中进行创建; 本示例中创建了一个虚拟域:test.hk,并创建了两个虚拟用户: test1@test.hk和test2@test1.hk,密码分别为test1和test2
  由于login认证采用Base64编码格式,故先将用户test1@test.hk的登录名和密码进行相应的编码: [iyunv@mailtest postfix]# perl -e 'use MIME::Base64; print encode_base64("test1@test.hk")' dGVzdDFAdGVzdC5oaw==
  [iyunv@mailtest postfix]# perl -e 'use MIME::Base64; print encode_base64("test1")' dGVzdDE=
  6.1)LOGIN登录测试: C:>telnet 10.10.119.204 25 220 mail.test.hk ESMTP "Version not Available" ehlo mail 250-mail.test.hk 250-PIPELINING 250-SIZE 5242880 250-VRFY 250-ETRN 250-STARTTLS 250-AUTH PLAIN LOGIN 250-AUTH=PLAIN LOGIN 250-ENHANCEDSTATUSCODES 250-8BITMIME 250 DSN AUTH LOGIN 334 VXNlcm5hbWU6 dGVzdDFAdGVzdC5oaw== 334 UGFzc3dvcmQ6 dGVzdDE= 235 2.0.0 Authentication successful mail from:test1@test.hk 250 2.1.0 Ok rcpt to:test2@test.hk 250 2.1.5 Ok data 354 Please start mail input. test send mail . quit 221 Closing connection. Good bye.
  Connection to host lost. C:>
  6.2)POP3收信测试 先对用户test2@test.hk进行Base64编码,而后认证登入,测试pop3收信 [iyunv@mailtest postfix]# perl -e 'use MIME::Base64; print encode_base64("test2@test.hk")' dGVzdDJAdGVzdC5oaw== [iyunv@mailtest postfix]# perl -e 'use MIME::Base64; print encode_base64("test2")' dGVzdDI=
  C:>telnet 10.10.119.204 110 +OK Dovecot ready. AUTH LOGIN + VXNlcm5hbWU6 dGVzdDJAdGVzdC5oaw== + UGFzc3dvcmQ6 dGVzdDI= +OK Logged in. LIST +OK 1 messages: 1 1410 . RETR 1 +OK 1410 octets Return-Path: <test1@test.hk> X-Original-To: test2@test.hk Delivered-To: test2@test.hk Received: from d2800js7mh1x (unknown [10.10.119.250])         by mail.test.hk (Postfix) with ESMTP id E8D9413B540         for <test2@test.hk>; Fri, 16 Nov 2007 08:23:43 +0800 (CST) Message-ID: <000801c827f4$d041b610$fa770a0a@d2800js7mh1x> From: "test1" <test1@test.hk> To: <test2@test.hk> Subject: test.hk Date: Fri, 16 Nov 2007 10:02:55 +0800 MIME-Version: 1.0 Content-Type: multipart/alternative;         boundary="----=_NextPart_000_0003_01C82837.DBACB3E0" X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2900.3138 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3198
  This is a multi-part message in MIME format.
  ------=_NextPart_000_0003_01C82837.DBACB3E0 Content-Type: text/plain;         charset="gb2312" Content-Transfer-Encoding: quoted-printable
  test.hk ------=_NextPart_000_0003_01C82837.DBACB3E0 Content-Type: text/html;         charset="gb2312" Content-Transfer-Encoding: quoted-printable
  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD> <META http-equiv=3DContent-Type content=3D"text/html; charset=3Dgb2312"> <META content=3D"MSHTML 6.00.2900.3199" name=3DGENERATOR> <STYLE></STYLE> </HEAD> <BODY bgColor=3D#ffffff> <DIV><FONT face=3DArial size=3D2>test.hk</FONT></DIV></BODY></HTML>
  ------=_NextPart_000_0003_01C82837.DBACB3E0--
  .
  7)安装Extmail-1.0.2 7.1)解压安装 # tar zxvf extmail-1.0.2.tar.gz # mkdir -pv /var/www/extsuite # mv extmail-1.0.2 /var/www/extsuite/extmail # cp /var/www/extsuite/extmail/webmail.cf.default  /var/www/extsuite/extmail/webmail.cf
  7.2)修改Extmail主配置文件 #vi /var/www/extsuite/webmail.cf 部分修改选项的说明:
  SYS_SESS_DIR = /tmp/ 临时目录选项,可改作: SYS_SESS_DIR = /tmp/extmail/
  然后建立目录并附权限 [iyunv@mailtest extmail]# mkdir /tmp/extmail [iyunv@mailtest extmail]# chown -R postfix.postfix /tmp/extmail/
  SYS_MESSAGE_SIZE_LIMIT = 5242880 用户可以发送的最大邮件
  SYS_USER_LANG = en_US 语言选项,可改作: SYS_USER_LANG = zh_CN
  SYS_LOG_TYPE = syslog LOG选项,如果用syslog,需要安装Unix:syslog模块,此处选择用ASCII文件作为日志 SYS_LOG_TYPE = file
  生成extmail日志文件并赋予权限 [iyunv@mailtest extmail]# touch /var/log/extmail.log [iyunv@mailtest extmail]# chown postfix.postfix /var/log/extmail.log
  SYS_MAILDIR_BASE = /home/domains
  SYS_MYSQL_USER = db_user SYS_MYSQL_PASS = db_pass SYS_MYSQL_DB = extmail 以上三句用来设置连接数据库服务器所使用用户名、密码和邮件服务器用到的数据库,这里修改为: SYS_MYSQL_USER = extmail SYS_MYSQL_PASS = extmail SYS_MYSQL_DB = extmail
  7.3)APACHE相关配置 由于extmail要进行本地邮件的投递操作,故必须将运行apache服务器用户的身份修改为您的邮件投递代理的用户;本例中打开了apache服务器的suexec功能,故使用以下方法来实现虚拟主机运行身份的指定。此例中的MDA为postfix自带,因此将指定为postfix用户:
  备份一份Apache的主配置文件 [iyunv@mailtest soft]# cp /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.conf-orig
  注释掉#DocumentRoot "/var/www/html"启用基于域名的虚拟主机 <VirtualHost mail.test.hk:80> ServerName mail.test.hk DocumentRoot /var/www/extsuite/extmail/html/ ScriptAlias /extmail/cgi /var/www/extsuite/extmail/cgi Alias /extmail /var/www/extsuite/extmail/html SuexecUserGroup postfix postfix </VirtualHost>
  修改 cgi执行文件属主为apache运行身份用户: [iyunv@mailtest soft]# chown -R postfix.postfix /var/www/extsuite/extmail/cgi/
  如果您没有打开apache服务器的suexec功能,也可以使用以下方法解决: [iyunv@mailtest soft]# vi /etc/httpd/config/httpd.conf User postfix Group postfix
  <VirtualHost mail.test.hk:80> ServerName mail.test.hk DocumentRoot /var/www/extsuite/extmail/html/ ScriptAlias /extmail/cgi /var/www/extsuite/extmail/cgi Alias /extmail /var/www/extsuite/extmail/html ScriptAlias /extman/cgi /var/www/extsuite/extman/cgi Alias /extman /var/www/extsuite/extman/html </VirtualHost>
  
  7.4)Extmail依赖关系的解决 extmail将会用到perl的DBD::Mysql和Unix::syslogd功能,对于第一个模块,我是安装OS自带的RPM包,第二个模块没有使用,前面有说明 perl-DBD-MySQL-3.0007-1.fc6
  下面是网上的方法解决依赖问题 extmail将会用到perl的DBD::Mysql和Unix::syslogd功能,您可以去http://search.cpan.org搜索下载原码包进行安装。 # tar zxvf Unix-Syslog-0.100.tar.gz # cd Unix-Syslog-0.100 # perl Makefile.PL # make # make install
  DBD-Mysql目前最新的版本为DBD-mysql-4.005,但它和系统中的perl结合使用时会造成extmail无法正常使用,因此我们采用3的版本: # tar zxvf DBD-mysql-3.0002_4.tar.gz  # cd cd DBD-mysql-3.0002_4 # perl Makefile.PL   (此步骤中如果出现类同Can't exec "mysql_config": No such file or directory at Makefile.PL line 76.的错误是因为您的mysql的bin目录没有输出至$PATH环境变量) # make # make install
  8)安装Extman-0.2.2 8.1)解压安装 [iyunv@mailtest soft]#  tar zxvf  extman-0.2.2.tar.gz [iyunv@mailtest soft]#  mv extman-0.2.2 /var/www/extsuite/extman
  8.2)修改Extman的主配置文件 [iyunv@mailtest soft]# vi /var/www/extsuite/extman/webman.cf
  SYS_SESS_DIR = /tmp/ 临时目录选项,可改作: SYS_SESS_DIR = /tmp/extman/
  然后建立目录并附权限 [iyunv@mailtest extmail]# mkdir -pv /tmp/extman [iyunv@mailtest extmail]# chown -R postfix.postfix /tmp/extman/
  修改cgi执行文件属主为apache运行身份用户 [iyunv@mailtest soft]#  chown -R postfix.postfix /var/www/extsuite/extman/cgi/
  8.3)APACHE相关配置 在apache的主配置文件中Extmail的虚拟主机部分,添加如下两行: ScriptAlias /extman/cgi /var/www/extsuite/extman/cgi Alias /extman /var/www/extsuite/extman/html
  最后虚拟主机的配置文件成为下面的这个样子 <VirtualHost mail.test.hk:80> ServerName mail.test.hk DocumentRoot /var/www/extsuite/extmail/html/ ScriptAlias /extmail/cgi /var/www/extsuite/extmail/cgi Alias /extmail /var/www/extsuite/extmail/html ScriptAlias /extman/cgi /var/www/extsuite/extman/cgi Alias /extman /var/www/extsuite/extman/html SuexecUserGroup postfix postfix </VirtualHost>
  配置Mailgraph_ext,使用Extman的图形日志: 接下来安装图形日志的运行所需要的软件包Time::HiRes、File::Tail和rrdtool,其中前两个包您可以去http://search.cpan.org搜索并下载获得,后一个包您可以到 http://oss.oetiker.ch/rrdtool/pub/?M=D下载获得; 注意安装顺序不能改换。
  安装Time::HiRes #tar zxvf Time-HiRes-1.9707.tar.gz #cd Time-HiRes-1.9707 #perl Makefile.PL #make #make test #make install
  安装File::Tail #tar zxvf File-Tail-0.99.3.tar.gz #cd File-Tail-0.99.3 #perl Makefile.PL #make #make test #make install
  安装rrdtool-1.2.26 #tar zxvf rrdtool-1.2.26.tar.gz #cd rrdtool-1.2.26 #./configure --prefix=/usr/local/rrdtool #make #make install
  创建必要的符号链接(Extman会到这些路径下找相关的库文件) #ln -sv /usr/local/rrdtool/lib/perl/5.8.8/i386-linux-thread-multi/auto/RRDs/RRDs.so   /usr/lib/perl5/5.8.8/i386-linux-thread-multi/ #ln -sv /usr/local/rrdtool/lib/perl/5.8.8/RRDp.pm   /usr/lib/perl5/5.8.8 #ln -sv /usr/local/rrdtool/lib/perl/5.8.8/i386-linux-thread-multi/RRDs.pm   /usr/lib/perl5/5.8.8
  复制mailgraph_ext到/usr/local,并启动之 # cp -r /var/www/extsuite/extman/addon/mailgraph_ext  /usr/local  # /usr/local/mailgraph_ext/mailgraph-init  start # /usr/local/mailgraph_ext/qmonitor-init  start
  添加到自动启动队列 echo "/usr/local/mailgraph_ext/mailgraph-init start" >> /etc/rc.local echo "/usr/local/mailgraph_ext/qmonitor-init start" >> /etc/rc.local
  注意:安装以上软件所之前,请确保您的系统已经安装了tcl、tcl-devel、freetype、freetype-devel、libart_lgpl和libart_lgpl-devel等相关的软件包
  
  9)开启Apache/Mysql/Bind,并让他们自启动 [iyunv@mailtest /]# chkconfig --level 2345 httpd on [iyunv@mailtest /]# chkconfig --level 2345 mysqld on [iyunv@mailtest /]# chkconfig --level 2345 named on [iyunv@mailtest /]# service httpd start [iyunv@mailtest /]# service mysqld start [iyunv@mailtest /]# service named start
  10)安装反垃圾SpamAssassin 安装系统自带的spamassassin包
  11)安装反病毒Clamav 从下面的网站下载clamav http://www.clamav.net/download
  [iyunv@mail ~]# groupadd clamav [iyunv@mail ~]# useradd -g clamav -s /bin/nologin -c "Clam AntiVirus" clamav [iyunv@mail ~]# mkdir /etc/clamav [iyunv@mail ~]# chown -R clamav.clamav  /etc/clamav
  [iyunv@mail ~]# tar zxvf clamav-0.91.2.tar.gz [iyunv@mail clamav-0.91.2]# cd clamav-0.91.2 [iyunv@mail clamav-0.91.2]# ./configure --sysconfdir=/etc/clamav [iyunv@mail clamav-0.91.2]# make [iyunv@mail clamav-0.91.2]# make install
  配置clamav的主配置文件 #vi /etc/clamav/clamd.conf 请先将文件中的 Example 这行删除掉或在其前面加上 # 注释掉 去掉注释或更改下面行的值 LogFile /var/log/clamav/clamd.log LogFileMaxSize 2M PidFile /home/clamav/clamd.pid DatabaseDirectory /usr/local/share/clamav LocalSocket /home/clamav/clamd.sock ScanMail yes ScanArchive yes ArchiveMaxFiles 1000 MaxThreads 200 MaxDirectoryRecursion 15 User clamav 这样 clamav 就基本可以工作了
  接下来要下载病毒资料库 首先编辑 /etc/clamav/freshclam.conf 文件 [iyunv@mail clamav-0.91.2]#  vi /etc/clamav/freshclam.conf 请先将文件中的 Example 这行删除掉或在其前面加上 # 注释掉 去掉次行注释并修改为  UpdateLogFile /var/log/clamav/freshclam.log
  在 DatabaseMirror database.clamav.net 行下面在加入几个地址,更多地址请参考文档 clamav.pdf DatabaseMirror clamav.inet6.fr DatabaseMirror clamav.netopia.pt DatabaseMirror clamav.sonic.net
  这样该文件就可以了。若升级数据库时无法连接就注释掉DatabaseMirror database.clamav.net 行,留下剩下的行. 下面生成/var/log/freshclam.log 文件 [iyunv@mail clamav-0.91.2]# mkdir /var/log/clamav touch /var/log/clamav/clamd.log touch /var/log/clamav/freshclam.log chmod 600 /var/log/clamav/freshclam.log chmod 600 /var/log/clamav/clamd.log chown clamav /var/log/clamav/clamd.log chown clamav /var/log/clamav/freshclam.log
  运行数据库的更新 [iyunv@mail clamav-0.91.2]#  freshclam -d -c 2   (-d 选项为该命令以 daemon 方式运行 -c 2 这个选项的意思是每天检查2次数据库更新) [iyunv@mail clamav-0.91.2]#  freshclam --quiet --stdout 手动更新数据库
  更新结束后请到 /usr/src/clamav-0.91.2/test 目录下检查数据库里所认知的病毒数量 执行 clamscan test
  建议用户做成启动脚本 /etc/rc3.d/S91clamav 内容如下: /usr/local/bin/freshclam -d -c 2 /usr/local/sbin/clamd
  
  12)安装MailScanner MailScanner-4.65.3-1.rpm.tar.gz tar -zvxf MailScanner-4.65.3-1.rpm.tar.gz cd ./install.sh
  可以将里面的src.rpm用rpmbuild --rebuild **.src.rpm 然后到/usr/src/redhat/RPMS/noarch去安装生成的rpm包
  
  建立Mailscanner支持spamassassin所需的目录: # mkdir /var/spool/MailScanner/spamassassin # chmod 700 /var/spool/MailScanner/spamassassin # chown postfix.postfix /var/spool/MailScanner/spamassassin
  修改spamassassin的配置文件 vi /etc/mail/spamassassin/local.cf # How many hits before a message is considered spam. required_hits           5.0 # Text to prepend to subject if rewrite_subject is used rewrite_header Subject             *****SPAM***** # Encapsulate spam in an attachment report_safe             1 # Enable the Bayes system use_bayes               1 # Enable or disable network checks skip_rbl_checks         1 use_razor2              0 use_pyzor               0 # Mail using locales used in these country codes will not be marked # as being possibly spam in a foreign language. ok_locales              all
  
  修改MailScanner.conf # vi /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 = clamav 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
  #我在最新的mailscanner上安装,需要将SpamAssassin Local Rules Dir = /etc/MailScanner设置为/etc/mail/spamassassin,否则maillog里面每5秒出现启动mailscanner的日志,所有的邮件都在队列里面
  修改 postfix支持mailscanner # vi /etc/postfix/main.cf 变更以下的值 header_checks = regexp:/etc/postfix/header_checks # vi /etc/postfix/header_checks /^Received:/ HOLD 注意, 在 / 之前不可以有空白!
  变更目录权限 # chown postfix.postfix /var/spool/MailScanner/incoming # chown postfix.postfix /var/spool/MailScanner/quarantine 停止postfix执行、启动MailScanner # service postfix stop # chkconfig postfix off # service MailScanner start 设定MailScanner,当MTA = postfix时,会自己启动postfix,如有设定启动postfix的请先将它停掉 定期更新病毒定义文件 # crontab -e 0 4 * * * /usr/local/bin/freshclam
  
  FAQ 1)进入postfixadmin的管理页面出现下面的警告提示 Warning: Magic Quotes: OFF (using internal function!) postfixadmin 2.1有这个警告 最新的版本2.2默认是要关闭这个的(也即默认是OK)
  要想2.1版本消除这个警告,修改/etc/php.ini文件 [iyunv@mailtest /]# vi /etc/php.ini ; Magic quotes for incoming GET/POST/Cookie data. #magic_quotes_gpc = Off magic_quotes_gpc = On 《==打开这一个就可以消除警告
  ; Magic quotes for runtime-generated data, e.g. data from SQL, from exec(), etc. magic_quotes_runtime = Off magic_quotes_runtime = On
  2)如何显示dovecot的所有配置 [iyunv@mailtest ~]# dovecot -a
  3)如何显示postfix的所有配置 [iyunv@mailtest ~]# postconf -n
  4)如何检查配置文件是否正确 [iyunv@mailtest ~]# postfix check 这个检查程序秉持“没有消息就是好消息”的Unix优良传统,如果你的系统一切无误,它不会出现任何信息;否则,它会将查出来的问题显示在屏幕上,并同时记录在日志文件里。
  5)检查日志 [iyunv@mailtest ~]# egrep '(reject|warning|error|fatal|panic):' /var/log/maillog
  
  6)/var/log/maillog出现下面的 Nov 19 12:06:00 mailtest postfix/smtpd[2055]: warning: dict_nis_init: NIS domain name not set - NIS lookups disabled
  修改alias_maps,去掉nis:mail.aliases [iyunv@mailtest postfix]# postconf -v |grep nis alias_maps = hash:/etc/aliases, nis:mail.aliases
  7)在postfix中配置RBL/CBL reject_rbl_client cbl.anti-spam.org.cn=127.0.8.2 reject_rbl_client cdl.anti-spam.org.cn=127.0.8.4 reject_rbl_client cblplus.anti-spam.org.cn=127.0.8.6 reject_rbl_client cblless.anti-spam.org.cn=127.0.8.5
  reject_rbl_client cbl.anti-spam.org.cn   #CBL 服务器 具体请看anti-spam.org.cn 可以用多个 reject_rbl_client  分隔依次使用多个RBL
  如果您想先测试一下RBL服务是否工作正常,可以在reject_maps_rbl指令和reject_rbl_client指令前加上warning_if_reject来改变默认的拒绝动作为警告(警告信息会在邮件日志中看到)。等确认工作正常后再去掉警告指令
  postfix 设置了RBL后无法收到邮件 退信内容 Non-authoritative answer Recursive queries supported by this server Query for 5.209.96.202.sbl.spamhaus.org type=255 class="1" 这是因为设置了RBL后没有加验证码需要修改 main.cf  在 cbl.anti-spam.org.cn后加入验证码         reject_rbl_client cbl.anti-spam.org.cn=127.0.8.2         reject_rbl_client cdl.anti-spam.org.cn=127.0.8.4         reject_rbl_client cblplus.anti-spam.org.cn=127.0.8.6         reject_rbl_client cblless.anti-spam.org.cn=127.0.8.5 然后重新加载服务 /etc/init.d/postfix reload
  
  加入 smtpd_client_restrictions = permit_sasl_authenticated,   reject_rbl_client cbl.abuseat.org,   reject_rbl_client bl.spamcop.net,   reject_rbl_client zen.spamhaus.org,   reject_rbl_client cblless.anti-spam.org.cn,   reject_rbl_client dsn.rfc-ignorant.org,   reject_rbl_client relays.ordb.org
  垃圾邮件就大大减少了。呵呵!
  
  CBL/CDL/CBL+/CBL-的配置参数
  名称   地址                            测试地址                              返回状态码 CBL  cbl.anti-spam.org.cn   2.0.0.127.cbl.anti-spam.org.cn.  127.0.8.2 CDL  cdl.anti-spam.org.cn   0.0.0.240.cdl.anti-spam.org.cn.  127.0.8.4 CBL+  cblplus.anti-spam.org.cn  2.0.0.127.cblplus.anti-spam.org.cn.  127.0.8.6 CBL-  cblless.anti-spam.org.cn  2.0.0.127.cblless.anti-spam.org.cn.  127.0.8.5
  CBL+ --是CBL和CDL的合集 CBL- --是CBL+中去掉了全部的CML BML    --大型邮件运营商列表会影响到我们的CBL/CBL+/CBL-等黑名单的IP地址的收录 TML  --可信邮件服务器地址,不属于主要邮件运营商,但在反垃圾邮件方面做过切实工作,并能积极响应垃圾邮件投诉的邮件服务器地址。加入TML可以邮件服务器不但可确保不会被加入到CBL-中,而且可以确保意外发生的一些垃圾邮件发送并不会导致您的邮件发送被阻
  
  8)如何让Postfix直接支持SpamAssassin 在/etc/postfix/master.cf中添加下面倒数3行 smtp      inet  n       -       n       -       -       smtpd  -o content_filter=spamassassin spamassassin unix  -       n       n       -       -       pipe  user=nobody argv=/usr/bin/spamc -f -e /usr/sbin/sendmail -oi -f ${sender} ${recipient}
  
  9)如何利用sendmail的mailer支持postfix smtp      inet  n       -       n       -       -       smtpd -o content_filter=clamav clamav    unix  -       n       n       -       -       pipe   flags=R user=clamav argv=/usr/local/bin/clamfilter -F postmaster@test.hk -f ${sender} -- ${recipient}
  10)如何用MySQL做postfix的后台 如本例
  11)如何用OpenLDAP做后台, 需下面的perl模块支持 perl-XML-NamespaceSupport-1.09-1.2.1.noarch.rpm perl-XML-SAX-0.14-5.noarch.rpm perl-Convert-ASN1-0.20-1.1.noarch.rpm perl-LDAP-0.33-3.fc6.noarch.rpm      
  [iyunv@mailtest ldap]# cat /etc/dovecot-ldap.conf hosts = 10.10.119.204:389 dn = cn=Manager,dc=extmail.org dnpass = 123456 ldap_version = 3 base =  o=extmailAccount,dc=extmail.org deref = never scope = subtree user_attrs = mail,homeDirectory,,,uidNumber,gidNumber user_filter = (&(objectClass=extmailUser)(mail=%u)(active=1)) pass_attrs = mail,userPassword pass_filter = (&(objectClass=extmailUser)(mail=%u)(active=1)) default_pass_scheme = CRYPT user_global_uid = postfix user_global_gid = postfix auth_bind = yes
  [iyunv@mailtest docs]# cat ldap_virtual_alias_maps.cf server_host = localhost search_base = o=extmailAlias,dc=extmail.org query_filter = (&(objectClass=extmailAlias)(mailLocalAddress=%s)(active=1)) result_attribute = mail cache = no bind = no scope = sub
  [iyunv@mailtest docs]# cat ldap_virtual_domains_maps.cf server_host = localhost search_base = o=extmailAccount,dc=extmail.org query_filter = (&(objectClass=extmailDomain)(virtualDomain=%s)(active=1)) result_attribute = virtualDomain cache = no bind = no scope = sub
  [iyunv@mailtest docs]# cat ldap_virtual_mailbox_maps.cf server_host = localhost search_base = o=extmailAccount,dc=extmail.org query_filter = (&(objectClass=extmailUser)(mail=%s)(active=1)) result_attribute = mailMessageStore cache = no bind = no scope = sub
  [iyunv@mailtest docs]# cat ldap_virtual_limit_maps.cf server_host = localhost search_base = o=extmailAccount,dc=extmail.org query_filter = (&(objectClass=extmailUser)(mail=%s)(active=1)) result_attribute = mailQuota cache = no bind = no scope = sub
  然后修改/etc/postfix/main.cf中相关的mysql为ldap 并配置ectmail/extman的配置参数文件webmail.cf为ldap认证和相关参数
  参数 sender_bcc_maps=hash:/etc/postfix/sender_maps recipient_bcc_maps=hash:/etc/postfix/recipient_maps
  
  参考文档 postfixadmin+on+debian+sarge with dovecot http://bliki.rimuhosting.com/space/knowledgebase/linux/mail/postfixadmin+on+debian+sarge
  postfix+with+amavis+and+mysql http://bliki.rimuhosting.com/space/knowledgebase/linux/mail/postfix+with+amavis+and+mysql
  http://bliki.rimuhosting.com/space/comment-knowledgebase/linux/mail/postfix+with+amavis+and+mysql-1 http://bliki.rimuhosting.com/space/knowledgebase/linux/mail/postfix+notes
  
  postfixadmin+on+RHEL4 http://bliki.rimuhosting.com/space/knowledgebase/linux/mail/postfixadmin+on+RHEL4
  完整强大的邮件系统就这样被我弄出来了 http://bbs.chinaunix.net/thread-982996-1-1.html
  变通实现dovecot + postfix + postfixadmin + mysql 虚拟用户认证服务器 http://bbs.chinaunix.net/thread-952938-1-1.html
  Postfix SMTP身份验证完整方案解析 http://www.5dmail.cn/html/2007-3-14/2007314200207.htm 原文:http://db.nipusa.net/mysql/a-2347.html
  
  
  
  
  

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.iyunv.com/thread-113814-1-1.html 上篇帖子: postfix邮件监控 下篇帖子: linux邮件服务器postfix配置实例
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表