Sendmail邮件服务器搭建与配置CentOS


查看安装
rpm -qa | grep sendmail
rpm -qa | grep dovecot
rpm -qa | grep cyrus
安装邮件服务器
yum install sendmail sendmail-cf
安装pop3/imap服务
yum install dovecot安装用户认证
yum install cyrus-sasl
yum install cyrus-sasl-md5
yum install cyrus-sasl-plain
yum install cyrus-sasl-lib

修改sendmail配置
vi /etc/mail/sendmail.mc
第52行和53行,把最前面的dnl删除,变成:
TRUST_AUTH_MECH(`EXTERNAL DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl 
define(`confAUTH_MECHANISMS',`EXTERNAL GSSAPI DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl
修改SMTP的监听IP为 0.0.0.0 
DAEMON_OPTIONS(`Port=smtp,Addr=0.0.0.0, Name=MTA')dnl
生成配置
m4 /etc/mail/sendmail.mc > /etc/sendmail.cf
***************************
如果出现:sendmail.mc:10: m4: cannot open `/usr/share/sendmail-cf/m4/cf.m4': No such file or directory
说明需要安装sendmail-cf
yum install sendmail-cf
***************************
修改dovecot配置
vi /etc/dovecot.conf
去掉下面一行前面的#
#protocols =imap imaps pop3 pop3s
添加域名
vi /etc/mail/local-host-names
添加域名如:ompchina.com //每个域名一行
修改认证方式
vi /usr/lib/sasl2/Sendmail.conf 里面指明了:pwcheck_method:saslauthd,不做修改
vi /etc/sysconfig/saslauthd  找到第7行的:MECH=  改成:MECH=shadow
\\MECH = shadow 或PAM 。shadow 表示用linux系统的认证机制,而PAM表示用PAM模组来认证
保存
如下示列:
[root@mail]# cat /usr/lib/sasl2/Sendmail.conf
pwcheck_method:saslauthd
[root@mail]# cat /usr/lib/sasl2/smtpd.conf.rpmsave
log_level: 3 
pwcheck_method: saslauthd
mech_list: PLAIN LOGIN
[root@mail]# cat   /etc/sysconfig/saslauthd
# Directory in which to place saslauthd's listening socket, pid file, and so
# on.  This directory must already exist.
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=shadow
# Additional flags to pass to saslauthd on the command line.  See saslauthd(8)
# for the list of accepted flags.
FLAGS=
[root@mail]#testsaslauthd -u test -p 123456   (验证smtp)
0: OK "Success."
添加邮件用户
[root@localhost named]# groupadd mailuser
[root@localhost named]# adduser -g mailuser -s /sbin/nologin test
这样添加的用户名就没有了shell,只能收发信而不能登录到服务器运行其他程序
设置开机启动
chkconfig sendmail on
chkconfig dovecot on
chkconfig saslauthd on
重启
service sendmail restart
service dovecot restart
service saslauthd restart
验证Sendmail服务
telnet localhost 25 //输入helo localhost 此时应该有LOGIN PLAIN的字样,即表示SMTP认证设置成功。
[root@centos5 mail]# telnet localhost 25
Trying 127.0.0.1...
Connected to localhost.localdomain (127.0.0.1).
Escape character is '^]'.
220 centos5 ESMTP Sendmail 8.13.8/8.13.8; Thu, 6 May 2010 06:21:29 +0800
helo localhost
250 centos5 Hello localhost.localdomain [127.0.0.1], pleased to meet you
mail from:<[email protected]>
250 2.1.0 <[email protected]>... Sender ok
rcpt to:[email protected]       (要测试向外发送邮件就填写网络上存在的邮件地址)
250 2.1.5 <[email protected]>... Recipient ok
data
354 Enter mail, end with "." on a line by itself
From: alin
To: alin
Subject: Hello
test
.
250 2.0.0 o45MLTcH005157 Message accepted for delivery
quit
221 2.0.0 centos5 closing connection
Connection closed by foreign host.
ok,可以使用outlook或foxmail进行测试收发了。
注意:为什么没有设定foxmail中的smtp服务器需要验证,也可以发送E-mail?
要用OUTLOOK来测试,Foxmail似乎可以自动地进行smtp认证。OUTLOOK在smtp服务器验证失败后,有拒绝提示
工具->;帐户->;邮件->;属性->;服务器->;我的服务器要求身份验证(选上)->;设置->;(选择)登录方式->;帐户名:(用saslpasswd2建立的),密码(用saslpasswd2建立的)->;确定.
另外:接收邮件服务器的帐户名与密码应该是系统里的用户名与密码.
saslauthd -v 看结果支不支持 pam或shadow
smtp验证测试: testsaslauthd -u test -p 123456
sasldblistusers2 检查已经增加的smtp验证用户
saslpasswd2增加smtp验证用户:saslpasswd2 -u cencn.com -c test
查看sendmail队列:mailq
立即发送队列里的邮件:  sendmail –oQ/var/spool/mqueue.stop -q
察看邮件系统的状态:mailstats
查看暂时存储邮件:ls -l /var/spool/mail |more

原文地址:http://help.lampok.net/log/?p=304

猜你喜欢

转载自mushme.iteye.com/blog/1001532