CentOS5 配置sendmail imap,pop3,smtp認證[轉]

查看安裝
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
相關文章
相關標籤/搜索