標籤:linux 郵件系統 pop3 postfix dovecot
5. 通過yum安裝dovecot和配置dovecot
第4節中介紹了postfix的配置,並測試了postfix的發送郵件功能。你可以在伺服器上使用mail命令來接受發送到本機網域名稱使用者郵箱中的郵件。但是你如果想使用MUA遠程來內送郵件,那麼則需要使用一個支援POP3/IMAP的服務來協助MUA將郵箱中的郵件拉取到本地,比如dovecot。
[[email protected] ~]# yum install dovecot
編輯/etc/dovecot/dovecot.conf檔案,修改以下行:
[[email protected] ~]# vi /etc/dovecot/dovecot.confprotocols = pop3
如果想使用作業系統帳號對收件者進行驗證,則編輯/etc/dovecot/conf.d/10-auth.conf,修改以下行:
[[email protected] conf.d]# vi /etc/dovecot/conf.d/10-auth.confauth_mechanisms = plain login
如果需要遠程使用MUA(如Outlook,Foxmail)來測試dovecot的收件功能,則需要配置/etc/dovecot/conf.d/10-auth.conf的如下行:
[[email protected] conf.d]# vi /etc/dovecot/conf.d/10-auth.confdisable_plaintext_auth = no
否則,用遠程伺服器登入到內送郵件伺服器時,MUA會彈出如下錯誤:
登入到內送郵件伺服器(POP3): 由於其他電子郵件正被傳送到你的郵箱,或者其他郵件應用程式正在訪問它,你的郵箱暫時不可用。 響應伺服器: -ERR [IN-USE] Couldn‘t open INBOX: Internal error occurred. Refer to server log for more information. [2016-01-05 11:23:21]
同時還要注意/etc/dovecot/conf.d/10-mail.conf中mail_location所指的路徑對應的許可權問題,如果對於MUA所使用的使用者沒有許可權訪問或者修改該目錄內容的話,在使用MUA登入到內送郵件伺服器時,MUA也會彈出如下錯誤:
登入到內送郵件伺服器(POP3): 由於其他電子郵件正被傳送到你的郵箱,或者其他郵件應用程式正在訪問它,你的郵箱暫時不可用。 響應伺服器: -ERR [IN-USE] Couldn‘t open INBOX: Internal error occurred. Refer to server log for more information. [2016-01-05 11:23:21]
maillog中也會有如下錯誤列印:
[[email protected] ~]# tail -f /var/log/maillogJan 5 11:23:21 mail dovecot: pop3(mailtest): Error: mkdir(/home/mailtest/mail/.imap/INBOX) failed: Operation not permittedJan 5 11:23:21 mail dovecot: pop3(mailtest): Error: Couldn‘t open INBOX: Internal error occurred. Refer to server log for more information. [2016-01-05 11:23:21]Jan 5 11:23:21 mail dovecot: pop3(mailtest): Couldn‘t open INBOX top=0/0, retr=0/0, del=0/0, size=0
配置完成後,啟動dovecot,由於配置dovecot支援pop3協議,dovecot運行時將監聽在110(pop3)和 995(pop3s)連接埠:
[[email protected] conf.d]# service dovecot startStarting Dovecot Imap: [ OK ][[email protected] conf.d]# netstat -tunlp | grep dovecottcp 0 0 0.0.0.0:110 0.0.0.0:* LISTEN 21883/dovecot tcp 0 0 0.0.0.0:995 0.0.0.0:* LISTEN 21883/dovecot
使用telnet訪問110連接埠以及通過openssl訪問995連接埠來測試dovecot是否可以內送郵件:
[[email protected] ~]# telnet 127.0.0.1 110Trying 127.0.0.1...Connected to 127.0.0.1.Escape character is ‘^]‘.+OK Dovecot ready.USER mailtest+OKPASS mailtest+OK Logged in.LIST+OK 4 messages:1 6232 6233 6234 623.RETR 1+OK 623 octetsReturn-Path: <[email protected]>X-Original-To: [email protected]Delivered-To: [email protected]...QUIT +OK Logging out.Connection closed by foreign host.[[email protected] home]# openssl s_client -connect 127.0.0.1:995...+OK Dovecot ready.USER mailtest+OKPASS mailtest+OK Logged in.LIST+OK 4 messages:1 6232 6233 6234 623...
也可以通過MUA進行遠程收件測試。
6. 配置cyrus-sasl來支援對postfix的收件者驗證
第4節中通過對postfix配置實現了postfix的發件功能,但是此時postfix無法對收件者進行驗證,因此本文使用了cyrus-sasl來協助postfix實現對收件者的驗證。
RHEL6.5上預設安裝了cyrus-sasl,要啟用sasl對smtpd的支援,則要在/usr/lib64/sasl2/下建立smtpd.conf檔案,並進行如下編輯:
[[email protected] sasl2]# vi smtpd.confpwcheck_method: saslauthdmech_list: PLAIN LOGIN
編輯/etc/postfix/main.cf,加入如下配置參數:
[[email protected] postfix]# vi main.cfbroken_sasl_auth_clients = yessmtpd_recipient_restrictions = permit_mynetworks,permit_sasl_authenticated,reject_invalid_hostname,reject_non_fqdn_hostname, reject_unknown_sender_domain,reject_non_fqdn_sender,reject_non_fqdn_recipient,reject_unknown_recipient_domain,reject_unauth_pipelining,reject_unauth_destinationsmtpd_sasl_auth_enable = yessmtpd_sasl_local_domain = $myhostnamesmtpd_sasl_security_options = noanonymoussmtpd_sasl_path = smtpd
如果要使用驗證/etc/passwd和/etc/shadow的方式,即通過系統使用者的登入密碼來進行驗證,則要編輯/etc/sysconfig/saslauthd的MECH參數(註:原有的PAM演算法未驗證):
[[email protected] sysconfig]# vi saslauthdMECH=shadow
重啟postfix和cyrus-sasl,對postfix的收件進行驗證:
[[email protected] sysconfig]# service saslauthd restartStopping saslauthd: [ OK ]Starting saslauthd: [ OK ][[email protected] sysconfig]# postfix stoppostfix/postfix-script: stopping the Postfix mail system[[email protected] sysconfig]# postfix startpostfix/postfix-script: starting the Postfix mail system[[email protected] sysconfig]# telnet 127.0.0.1 25Trying 127.0.0.1...Connected to 127.0.0.1.Escape character is ‘^]‘.220 mail.asika.com ESMTP Postfixehlo localhost250-mail.asika.com250-PIPELINING250-SIZE 10240000250-VRFY250-ETRN250-AUTH LOGIN PLAIN250-AUTH=LOGIN PLAIN250-ENHANCEDSTATUSCODES250-8BITMIME250 DSNAUTH LOGIN334 VXNlcm5hbWU6 #Username base64位編碼bWFpbHRlc3Q= #mailtest base64位編碼334 UGFzc3dvcmQ6 #Password base64位編碼bWFpbHRlc3Q=235 2.7.0 Authentication successfulquit221 2.0.0 ByeConnection closed by foreign host.
下一篇文章將介紹通過mysql資料庫來實現postfix和dovecot對虛擬使用者的收發郵件驗證。
郵件系統伺服器搭建記錄(二)(Postfix+Cyrus-sasl+Courier-authlib+Dovecot+ExtMail+MySQL)