最近要帮朋友配置一个SMTP服务器,需求就是每天需要向外发送上百万封邮件,google之,发现postfix邮件服务器比较靠谱, 能够发送外部邮件,于是就选它了
操作系统:CentOS 5 32bit
postfix安装
可以通过源码安装最新的版本,但是为了方便,我直接使用yum安装
sudo yum install postfix
配置文件路径:/etc/postfix/main.cf
postfix启动与停止命令:
sudo /etc/init.d/postfix start
sudo /etc/init.d/postfix stop
sudo /etc/init.d/postfix restart
postfix日志文件位置:/var/log/maillog
卸载sendmail
检查系统是否安装sendmail:
如果存在,卸载之
安装cyrus-sasl-2.1.23
由于在centos 源中不存在,直接通过源码安装cyrus-sasl-2.1.23.tar.gz
下载地址
./configure &&make &&make install
这个软件包的作用就是postfix邮件服务器的认证,因为如果转发外部的邮件,必须使用smtpd_recipient_restrictions选项的值check_relay_domains或者是reject_unauth_destination,二者必须选一个,而relay_damains手工来配置允许的邮件域太麻烦,所以就选用sasl认证
修改sasl配置:/etc/sysconfig/saslauthd为
# Directory in which to place saslauthd's listening socket, pid file, and so
# on. This directory must already exist.
START=yes
SOCKETDIR=/var/run/saslauthd
# Mechanism to use when checking passwords. Run "saslauthd -v" to get a list
# of which mechanism your installation was compiled with the ablity to use.
#MECH="pam"
MECHANISMS="pam" #使用linux自身的用户认证
# Additional flags to pass to saslauthd on the command line. See saslauthd(8)
# for the list of accepted flags.
#FLAGS=
然后重启saslauthd:
sudo /etc/init.d/saslauthd restart
测试saslauthd生效:
/usr/sbin/testsaslauthd -u liyg -p liyangguang
将sasl与postfix结合
在main.cf文件中加入:
#added by liyangguang
smtpd_recipient_restrictions = permit_mynetworks,permit_sasl_authenticated,reject_unauth_destination
#smtpd_client_restrictions = permit_sasl_authenticated
smtpd_sasl_auth_enable = yes
broken_sasl_auth_clients = yes
smtpd_sasl_security_options = noanonymous
重启postfix :sudo /etc/init.d/postfix restart。
然后通过foxmail客户端配置smtp服务器地址,测试发送邮件是否成功