1.如果CentOS下已经安装sendmail,先将sendmail卸载
/etc/init.d/sendmail stop
rpm -qa | grep sendmail
rpm -e sendmail
2.安装postfix
yum -y install postfix//yum会自动将cyrus-sasl2安装上
vim /etc/postfix/main.cf
修改内容如下:
myhostname = mail.test.com
mydomain = test.com
myorigin = $mydomain
inet_interfaces = all
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain,
mail.$mydomain, www.$mydomain, ftp.$mydomain
mynetworks_style = subnet
mynetworks = 127.0.0.0/8, localhost, 10.0.0.0/8
relay_domains = $mydestination
home_mailbox = Maildir/ //如果采用系统帐号作为邮件用户名,该目录为帐号下的目录
最后面添加(sasl加密算法支持)
smtpd_sasl_auth_enable = yes
smtpd_sasl_security_options = noanonymous
broken_sasl_auth_clients = yes
smtpd_recipient_restrictions = permit_sasl_authenticated,reject_unauth_destination,permit_mynetworks
smtpd_client_restrictions = permit_sasl_authenticated
3.配置sasl
vi /usr/lib/sasl2/smtpd.conf
内容如下:
pwcheck_method: saslauthd
mech_list: PLAIN LOGIN
log_level:3
saslauthd_path: /var/run/saslauthd/mux
vi /etc/sysconfig/saslauthd
修改:
MECH=shadow //使用系统用户进行认证
4.设置开机启动postfix和sasl
chkconfig postfix on
chkconfig saslauthd on
5.启动postfix和sasl
service postfix start
service saslauthd start
6.验证postfix的认证
1. /usr/sbin/testsaslauthd -u root -p 123456 -s smtp
2.
[root@localhost ~]# telnet localhost 25
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
220 mail.test.com ESMTP Postfix
ehlo a
250-mail.test.com
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-AUTH LOGIN PLAIN
250-AUTH=LOGIN PLAIN
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
auth login
334 VXNlcm5hbWU6
cm9vdEB0ZXN0LmNvbQ== //root@test.com的base64编码
334 UGFzc3dvcmQ6
MTIzNDU2 //123456的base64编码
235 2.7.0 Authentication successful
quit
221 2.0.0 Bye
Connection closed by foreign host.
[root@localhost ~]#