码迷,mamicode.com
首页 > 数据库 > 详细

邮件系统服务器搭建记录(二)(Postfix+Cyrus-sasl+Courier-authlib+Dovecot+ExtMail+MySQL)

时间:2016-01-05 19:01:14      阅读:886      评论:0      收藏:0      [点我收藏+]

标签:linux   邮件系统   pop3   postfix   dovecot   

5. 通过yum安装dovecot和配置dovecot

第4节中介绍了postfix的配置,并测试了postfix的发送邮件功能。你可以在服务器上使用mail命令来接受发送到本机域名用户邮箱中的邮件。但是你如果想使用MUA远程来接收邮件,那么则需要使用一个支持POP3/IMAP的服务来帮助MUA将邮箱中的邮件拉取到本地,比如dovecot。

[root@mail ~]# yum install dovecot

编辑/etc/dovecot/dovecot.conf文件,修改以下行:

[root@mail ~]# vi /etc/dovecot/dovecot.conf
protocols = pop3

如果想使用操作系统账号对收件人进行验证,则编辑/etc/dovecot/conf.d/10-auth.conf,修改以下行:

[root@mail conf.d]# vi /etc/dovecot/conf.d/10-auth.conf
auth_mechanisms = plain login

如果需要远程使用MUA(如Outlook,Foxmail)来测试dovecot的收件功能,则需要配置/etc/dovecot/conf.d/10-auth.conf的如下行:

[root@mail conf.d]# vi /etc/dovecot/conf.d/10-auth.conf
disable_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中也会有如下错误打印:

[root@mail ~]# tail -f /var/log/maillog
Jan  5 11:23:21 mail dovecot: pop3(mailtest): Error: mkdir(/home/mailtest/mail/.imap/INBOX) failed: Operation not permitted
Jan  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)端口:

[root@mail conf.d]# service dovecot start
Starting Dovecot Imap:                                     [  OK  ]
[root@mail conf.d]# netstat -tunlp | grep dovecot
tcp        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是否可以接收邮件:

[root@mail ~]# telnet 127.0.0.1 110
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is ‘^]‘.
+OK Dovecot ready.
USER mailtest
+OK
PASS mailtest
+OK Logged in.
LIST
+OK 4 messages:
1 623
2 623
3 623
4 623.
RETR 1
+OK 623 octets
Return-Path: <mailtest@asika.com>
X-Original-To: mailtest@asika.com
Delivered-To: mailtest@asika.com
...
QUIT 
+OK Logging out.
Connection closed by foreign host.
[root@mail 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 623
2 623
3 623
4 623
...

也可以通过MUA进行远程收件测试。


6. 配置cyrus-sasl来支持对postfix的收件人验证

第4节中通过对postfix配置实现了postfix的发件功能,但是此时postfix无法对收件人进行验证,因此本文使用了cyrus-sasl来帮助postfix实现对收件人的验证。

RHEL6.5上默认安装了cyrus-sasl,要启用sasl对smtpd的支持,则要在/usr/lib64/sasl2/下新建smtpd.conf文件,并进行如下编辑:

[root@mail sasl2]# vi smtpd.conf
pwcheck_method: saslauthd
mech_list: PLAIN LOGIN

编辑/etc/postfix/main.cf,加入如下配置参数:

[root@mail postfix]# vi main.cf
broken_sasl_auth_clients = yes
smtpd_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_destination
smtpd_sasl_auth_enable = yes
smtpd_sasl_local_domain = $myhostname
smtpd_sasl_security_options = noanonymous
smtpd_sasl_path = smtpd

如果要使用验证/etc/passwd和/etc/shadow的方式,即通过系统用户的登录密码来进行验证,则要编辑/etc/sysconfig/saslauthd的MECH参数(注:原有的PAM算法未验证):

[root@mail sysconfig]# vi saslauthd
MECH=shadow

重启postfix和cyrus-sasl,对postfix的收件进行验证:

[root@mail sysconfig]# service saslauthd restart
Stopping saslauthd:                                        [  OK  ]
Starting saslauthd:                                        [  OK  ]
[root@mail sysconfig]# postfix stop
postfix/postfix-script: stopping the Postfix mail system
[root@mail sysconfig]# postfix start
postfix/postfix-script: starting the Postfix mail system
[root@mail sysconfig]# telnet 127.0.0.1 25
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is ‘^]‘.
220 mail.asika.com ESMTP Postfix
ehlo localhost
250-mail.asika.com
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-AUTH LOGIN PLAIN
250-AUTH=LOGIN PLAIN
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
AUTH LOGIN
334 VXNlcm5hbWU6    #Username base64位编码
bWFpbHRlc3Q=    #mailtest base64位编码
334 UGFzc3dvcmQ6    #Password base64位编码
bWFpbHRlc3Q=
235 2.7.0 Authentication successful
quit
221 2.0.0 Bye
Connection closed by foreign host.

下一篇文章将介绍通过mysql数据库来实现postfix和dovecot对虚拟用户的收发邮件验证。

邮件系统服务器搭建记录(二)(Postfix+Cyrus-sasl+Courier-authlib+Dovecot+ExtMail+MySQL)

标签:linux   邮件系统   pop3   postfix   dovecot   

原文地址:http://itsukakotori.blog.51cto.com/4819846/1731817

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!