Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2214892
  • 博文数量: 533
  • 博客积分: 8689
  • 博客等级: 中将
  • 技术积分: 7046
  • 用 户 组: 普通用户
  • 注册时间: 2010-11-26 10:00
文章分类

全部博文(533)

文章存档

2024年(2)

2023年(4)

2022年(16)

2014年(90)

2013年(76)

2012年(125)

2011年(184)

2010年(37)

分类: LINUX

2011-02-24 18:01:36




CentOS5 配置sendmail imap,pop3,smtp认证
2010-12-08 14:25

查看安装
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

第42行和43行,把最前面的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
添加域名如:dirtysea.com //每个域名一行

修改认证方式
vi /usr/lib/sasl2/Sendmail.conf 里面指明了:pwcheck_method=saslauthd,不做修改
vi /etc/sysconfig/saslauthd  找到第7行的:MECH=  改成:MECH=shadow
保存
如下示列:

[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:<>
250 2.1.0 <>... Sender ok
rcpt to:<>       (要测试向外发送邮件就填写网络上存在的邮件地址)
250 2.1.5 <>... 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

 

 

 

在linux下用sendmail构建邮件服务器中出现问题。在outlook express 给自己发收都没有问题,内网也没有问题,只是在发给外部的邮件中出现以下错误信息:

由于服务器拒绝收件人之一,无法发送邮件。被拒绝的电子邮件地址是。 主题 ' test', 帐户: 'ddd', 服务器: 'mail.cn', 协议: SMTP, 服务器响应: '550 5.7.1 ... Relaying denied. IP name lookup failed [202.222*.*.*]', 端口: 25, 安全(SSL): 否, 服务器错误: 550, 错误号: 0x800CCC79

经过多次摸索:原来是sendmail的配置文件中有问题,打开/etc/mail/access文件

加入以下语句

202. 222    OK
***
允许202.222通过sendmail收发邮件

或者
202.222 RELAY
***
允许202.222通过sendmail发邮件

或者
CONNECT: 202.222 RELAY
***
功能同上



阅读(4714) | 评论(4) | 转发(0) |
给主人留下些什么吧!~~

ehlopxp2012-11-28 18:32:34

这个东东。。 是N年以前的了。。 我最近不搞这个。。 可能是操作系统的版本不一样吧。

twinkleolive2012-11-26 16:55:38

/usr/lib/sasl2/此目录下没有Sendmail.conf和smtpd.conf.rpmsave这两个文件

chinaunix网友2011-03-05 17:51:24

很好的, 收藏了 推荐一个博客,提供很多免费软件编程电子书下载: http://free-ebooks.appspot.com