1、启动sasl

  安装全部的cyrus-sasl包,否则可能报错。

  /etc/init.d/saslauthd 

   配置文件/etc/sysconfig/saslauthd

 saslauthd -v :可以显示当前sasl主机所支持的认证机制,默认pam。

           改为shadow,测试:testsaslauthd -u user -p password

2.验证postfix是否支持sasl

 postconf -a

3、编辑/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
smtpd_sasl_application_name = smtpd

smtpd_sasl_path = smtpd (新版语法)   

#vi /usr/local/lib/sasl2/smtpd.conf
添加如下内容:
pwcheck_method: saslauthd
mech_list: PLAIN LOGIN

  postfix基于客户端的访问控制

postfix内置了反垃圾邮件的机制,其中包括客户端发送邮件限制,客户端判别机制可以设定一系列客户信息的判别条件:

 smtpd_client_restrictions

 smtpd_helo_restrictions

 smtpd_data_restrictions

 smtpd_recipient_restrictions = permit_mynetworks , reject unauth_destination

 smtpd_sender_restrictions

上面每一项参数分别检查smtp会话的特定阶段,客户端发起连接请求时,用client检查客户端ip的权限;

根据客户端helo中的信息,判断其访问能力;data进行内容检查。

postfix提供了多种限制条件,管理员也可以使用访问表。自定义访问表的的条件通常使用:

          check_client_access,check_helo_access,check_sender_access,check_recipient_access,它的后面通常跟上type:map_name形式的访问表类型和名称,可以使用完整的邮件地址,

                                                                                          或@domain或user@

例如:

     禁止172.16.100.1通过172.16.0.1的postfix服务器发送邮件,访问表控制

     1  /etc/postfix/access  添加一行

         172.16.100.1  REJECT

      2  将次文件转为hash格式

          postmap  /etc/postfix/access

      3 配置postfix使用此文件对客户端进行检查

          smtpd_client_restrictions =  check_client_access hash:/etc/postfix/access(不得加.db扩展名)

                                                                                         mysql:database.table

                                                                                         mysql:/etc/mysql/conf

      4 postfix重新载入配置文件  


     禁止想microsoft.com发送邮件

     1   /etc/postfix/dest

           microsoft.com  REJECT

      2  postmap   /etc/postfix/dest

      3  smtpd_recipient_restrictions =  check_recipient_access  hash:/etc/postfix/dest

      4   postfix重新载入配置文件


检查表格式:

       hash:  pattern   action


注意:

    如postfix选择mbox,/var/spool/mail/文件的权限,必须跟dovecot/conf.d/master/service  auth定义的                                        权限一致,10-mail文件中定义邮件队列的保存目录/var/spoo/mail

   如postfix选择maildir,则无上述权限要求,修改10-mail中邮件的保存位置为maildir:~/Maidir,尽管postfix                                        的邮件保存位置是/var/spool/mail/.