前两年吃饱没事给公司装了个postfix当邮件服务器,设置了个all@company.com别名,可以给全体人员群发邮件。
现在老板要限制其他人对这个邮件地址发信,只允许几个特定账号如boss@company.com能给all@company.com发信。公司现成有网管不去找,把这事又派到我头上。记得这个教训吧,没事别揽事,帮忙总会帮出麻烦。
以前用Exchange的时候很容易设置的,改Postfix之后还没试过。
刚开始以为简单的设置一下header_checks就能搞定。
if /^to: *all@company\.com/
!/^From:.*boss\@company\.com/ reject user error
endif
测试了一下,一点作用都没有!
折腾了好一会才弄明白,header_checks压根就不支持多条复合规则。Google了一下,有鬼佬建议使用FILTER transport:destination转发到另一台邮件服务器处理,以后倒可试一试,不过这次懒得弄了。
把postfix的文档重新认真看了看,又Google了一下,搞明白该如何配置了。
1. 修改/etc/postfix/main.cf
添加:
smtpd_restriction_classes = send2all
send2all = check_sender_access hash:/etc/postfix/s2a_sender,reject
修改smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated,…………..加上check_recipient_access hash:/etc/postfix/send2allclass
即:
smtpd_recipient_restrictions = check_recipient_access hash:/etc/postfix/send2allclass,permit_mynetworks, permit_sasl_authenticated,。。。。。。。。。。(记得写在permit_mynetworks前面)
2. 创建send2allclass文件,设置收件人策略
#touch /etc/postfix/send2allclass
#vi /etc/postfix/send2allclass
文件内容如下:
all@company.com send2all
然后
#postmap send2allclass 生成hash
3.创建s2a_sender文件,设置发件人规则
#vi /etc/postfix/s2a_sender
文件内容如下:
boss@company.com ok
如有其它账号,一行行添加即可
然后
#postmap s2a_sender
4.重启postfix
#postfix reload
或
#service postfix restart
测试了一下,使用boss@company.com之外的账号对all@company.com发信会被拒绝,提示:554 5.7.1 Recipient address rejected: Access denied
然后又发现一个小问题,通过horde webmail还是可以继续用其他信箱发信给all@company.com,还得接着配置
5.配置horde webmail
以管理员账号登录到horde webmail中,修改Mailer配置,将默认的“Use the local sendmail binary”改成”Use a SMTP server”,然后在host和localhost参数中填上”localhost”,在auth参数中选择“Best available authentication”
然后点击“生成Horde配置文件”即可。
看了看horde/config/conf.php文件。
原来的:
$conf['mailer']['params']['sendmail_path'] = ‘/usr/lib/sendmail’;
$conf['mailer']['params']['sendmail_args'] = ‘-oi’;
$conf['mailer']['type'] = ’sendmail’;
已经被改为:
$conf['mailer']['params']['host'] = ‘localhost’;
$conf['mailer']['params']['localhost'] = ‘localhost’;
$conf['mailer']['params']['auth'] = true;
$conf['mailer']['type'] = ’smtp’;
测试了一下,现在使用webmail也可以限制对all@company.com发信了。
参考链接:
http://blog.csdn.net/chinalinuxzend/archive/2007/11/08/1872573.aspx
http://www.extmail.org/forum/viewthread.php?tid=4102
http://www.extmail.org/forum/viewthread.php?action=printable&tid=6447
http://www.postfix.org/header_checks.5.html
Update 2010-4-17:加上防止伪造发件人的配置,详见:Postfix防止伪造发件人