postifix--benet3--编译安装dovecot


编译安装dovecot

添加账户

[root@mail benet]# useradd -M -s /sbin/nologin dovecot

解压缩

[root@mail benet]# tar zxf dovecot-1.1.4.tar.gz -C /usr/src
[root@mail benet]# cd /usr/src/dovecot-1.1.4/
[root@mail dovecot-1.1.4]#
[root@mail dovecot-1.1.4]# ./configure --sysconfdir=/etc --with-mysql

指定dovecot的配置文件在etc下,dovecot支持mysql

[root@mail dovecot-1.1.4]# ./configure --sysconfdir=/etc --with-mysql
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking whether to enable maintainer-specific portions of Makefiles... no
checking for style of include used by make... GNU
checking for gcc... gcc
checking for C compiler default output file name... a.out
checking whether the C compiler works... yes
checking whether we are cross compiling... no
...//省略
config.status: creating dovecot-config.in
config.status: creating config.h
config.status: executing depfiles commands
Install prefix ...................... : /usr/local
File offsets ........................ : 64bit
I/O loop method ..................... : epoll
File change notification method ..... : inotify
Building with SSL support ........... : yes (OpenSSL)
Building with IPv6 support .......... : yes
Building with pop3 server ........... : yes
Building with mail delivery agent .. : yes
Building with GSSAPI support ........ : no
Building with user database modules . : static prefetch passwd passwd-file sql nss
Building with password lookup modules : passwd passwd-file shadow pam checkpassword sql
Building with SQL drivers ............: mysql
[root@mail dovecot-1.1.4]#

make

[root@mail dovecot-1.1.4]# make
...//省略
make[3]: Entering directory `/usr/src/dovecot-1.1.4/doc'
make[3]: Nothing to be done for `all-am'.
make[3]: Leaving directory `/usr/src/dovecot-1.1.4/doc'
make[2]: Leaving directory `/usr/src/dovecot-1.1.4/doc'
make[2]: Entering directory `/usr/src/dovecot-1.1.4'
cat dovecot-config.in | sed \
 -e "s|^moduledir=|moduledir=/usr/local/lib/dovecot|" \
 -e "s|^dovecot_incdir=|dovecot_incdir=/usr/local/include/dovecot|" > dovecot-config
make[2]: Leaving directory `/usr/src/dovecot-1.1.4'
make[1]: Leaving directory `/usr/src/dovecot-1.1.4'
[root@mail dovecot-1.1.4]#

make install

[root@mail dovecot-1.1.4]# make install
...//省略
 /usr/bin/install -c -m 644 'auth-protocol.txt' '/usr/local/share/doc/dovecot/auth-protocol.txt'
 /usr/bin/install -c -m 644 'documentation.txt' '/usr/local/share/doc/dovecot/documentation.txt'
 /usr/bin/install -c -m 644 'securecoding.txt' '/usr/local/share/doc/dovecot/securecoding.txt'
make[3]: Leaving directory `/usr/src/dovecot-1.1.4/doc'
make[2]: Leaving directory `/usr/src/dovecot-1.1.4/doc'
make[1]: Leaving directory `/usr/src/dovecot-1.1.4/doc'
make[1]: Entering directory `/usr/src/dovecot-1.1.4'
make[2]: Entering directory `/usr/src/dovecot-1.1.4'
test -z "/usr/local/lib/dovecot" || /bin/mkdir -p "/usr/local/lib/dovecot"
test -z "/etc" || /bin/mkdir -p "/etc"
 /usr/bin/install -c -m 644 'dovecot-example.conf' '/etc/dovecot-example.conf'
test -z "/usr/local/include/dovecot" || /bin/mkdir -p "/usr/local/include/dovecot"
make[2]: Leaving directory `/usr/src/dovecot-1.1.4'
make[1]: Leaving directory `/usr/src/dovecot-1.1.4'
[root@mail dovecot-1.1.4]#

修改dovecot.conf的配置文件

[root@mail ~]# vim /etc/dovecot.conf
...
ssl_disable = yes
...
protocols = pop3 imap
...
disable_plaintext_auth = no
...
mail_location = maildir:~/Maildir
...

创建PAM认证文件

[root@mail ~]# vim /etc/pam.d/dovecot
#%PAM-1.0
auth required pam_nologin.so
auth include system-auth
account include system-auth
session include system-auth
~
~
...//省略波浪号
~
~
~
"/etc/pam.d/dovecot" 5L, 123C

启动dovecot服务

[root@mail ~]# /usr/local/sbin/dovecot -c /etc/dovecot.conf
[root@mail ~]# netstat -utpln | grep dovecot
tcp 0 0 0.0.0.0:110 0.0.0.0:* LISTEN 23557/dovecot
tcp 0 0 0.0.0.0:143 0.0.0.0:* LISTEN 23557/dovecot
[root@mail ~]#

pop3收信测试

[root@mail ~]# telnet localhost 110
Trying ::1...
telnet: connect to address ::1: Connection refused
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
+OK Dovecot ready.
USER lisi
+OK
PASS 123123
+OK Logged in.
-ERR [IN-USE] Couldn't open INBOX: Internal error occurred. Refer to server log for more information. [2016-07-23 00:20:32]
Connection closed by foreign host.
[root@mail ~]#
[root@mail ~]# getenforce
Enforcing
[root@mail ~]# setenforce 0
[root@mail ~]# chkconfig --list iptables
iptables 0:off 1:off 2:on 3:on 4:on 5:on 6:off
[root@mail ~]# chkconfig iptables off
[root@mail ~]# telnet localhost 110
Trying ::1...
telnet: connect to address ::1: Connection refused
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
+OK Dovecot ready.
USER lisi
+OK
PASS 123123
+OK Logged in.
-ERR [IN-USE] Couldn't open INBOX: Internal error occurred. Refer to server log for more information. [2016-07-23 00:28:35]
Connection closed by foreign host.
[root@mail ~]#
[root@mail ~]# tail /var/log/maillog
Jul 23 00:20:32 mail dovecot: POP3(lisi): Couldn't open INBOX: Internal error occurred. Refer to server log for more information. [2016-07-23 00:20:32]
Jul 23 00:20:32 mail dovecot: POP3(lisi): Couldn't open INBOX top=0/0, retr=0/0, del=0/0, size=0
Jul 23 00:24:50 mail dovecot: pop3-login: Login: user=<lisi>, method=PLAIN, rip=173.16.16.11, lip=173.16.16.11, secured
Jul 23 00:24:50 mail dovecot: POP3(lisi): mkdir(/Maildir/cur) failed: Permission denied
Jul 23 00:24:50 mail dovecot: POP3(lisi): Couldn't open INBOX: Internal error occurred. Refer to server log for more information. [2016-07-23 00:24:50]
Jul 23 00:24:50 mail dovecot: POP3(lisi): Couldn't open INBOX top=0/0, retr=0/0, del=0/0, size=0
Jul 23 00:28:35 mail dovecot: pop3-login: Login: user=<lisi>, method=PLAIN, rip=127.0.0.1, lip=127.0.0.1, secured
Jul 23 00:28:35 mail dovecot: POP3(lisi): mkdir(/Maildir/cur) failed: Permission denied
Jul 23 00:28:35 mail dovecot: POP3(lisi): Couldn't open INBOX: Internal error occurred. Refer to server log for more information. [2016-07-23 00:28:35]
Jul 23 00:28:35 mail dovecot: POP3(lisi): Couldn't open INBOX top=0/0, retr=0/0, del=0/0, size=0
[root@mail ~]#

更改权限

[root@mail ~]# locate /Maildir/cur
/home/lisi/Maildir/cur
[root@mail ~]# cd /home/lisi
[root@mail lisi]# ls -l
total 4
drwx------. 5 lisi lisi 4096 Jul 22 22:42 Maildir
[root@mail lisi]# chmod 777 -R Maildir
[root@mail lisi]# ls -l
total 4
drwxrwxrwx. 5 lisi lisi 4096 Jul 22 22:42 Maildir
[root@mail lisi]# cd Maildir/
[root@mail Maildir]# ls
cur new tmp
[root@mail Maildir]# ls -l
total 12
drwxrwxrwx. 2 lisi lisi 4096 Jul 22 22:42 cur
drwxrwxrwx. 2 lisi lisi 4096 Jul 22 22:42 new
drwxrwxrwx. 2 lisi lisi 4096 Jul 22 22:42 tmp

测试

[root@mail Maildir]# telnet localhost 110
Trying ::1...
telnet: connect to address ::1: Connection refused
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
+OK Dovecot ready.
USER lisi
+OK
PASS 123123
+OK Logged in.
-ERR [IN-USE] Couldn't open INBOX: Internal error occurred. Refer to server log for more information. [2016-07-23 00:45:40]
Connection closed by foreign host.

查看日志

[root@mail Maildir]# tail /var/log/maillog
Jul 23 00:28:35 mail dovecot: POP3(lisi): Couldn't open INBOX: Internal error occurred. Refer to server log for more information. [2016-07-23 00:28:35]
Jul 23 00:28:35 mail dovecot: POP3(lisi): Couldn't open INBOX top=0/0, retr=0/0, del=0/0, size=0
Jul 23 00:42:34 mail dovecot: pop3-login: Login: user=<lisi>, method=PLAIN, rip=127.0.0.1, lip=127.0.0.1, secured
Jul 23 00:42:34 mail dovecot: POP3(lisi): mkdir(/Maildir/cur) failed: Permission denied
Jul 23 00:42:34 mail dovecot: POP3(lisi): Couldn't open INBOX: Internal error occurred. Refer to server log for more information. [2016-07-23 00:42:34]
Jul 23 00:42:34 mail dovecot: POP3(lisi): Couldn't open INBOX top=0/0, retr=0/0, del=0/0, size=0
Jul 23 00:45:40 mail dovecot: pop3-login: Login: user=<lisi>, method=PLAIN, rip=127.0.0.1, lip=127.0.0.1, secured
Jul 23 00:45:40 mail dovecot: POP3(lisi): mkdir(/Maildir/cur) failed: Permission denied
Jul 23 00:45:40 mail dovecot: POP3(lisi): Couldn't open INBOX: Internal error occurred. Refer to server log for more information. [2016-07-23 00:45:40]
Jul 23 00:45:40 mail dovecot: POP3(lisi): Couldn't open INBOX top=0/0, retr=0/0, del=0/0, size=0
[root@mail Maildir]#

重新查看dovecot.conf

[root@mail Maildir]# vim /etc/dovecot.conf
# Location for users' mailboxes. This is the same as the old default_mail_env
# setting. The default is empty, which means that Dovecot tries to find the
# mailboxes automatically. This won't work if the user doesn't have any mail
# yet, so you should explicitly tell Dovecot the full location.
#
# If you're using mbox, giving a path to the INBOX file (eg. /var/mail/%u)
# isn't enough. You'll also need to tell Dovecot where the other mailboxes are
# kept. This is called the "root mail directory", and it must be the first
# path given in the mail_location setting.
#
# There are a few special variables you can use, eg.:
#
# %u - username
# %n - user part in user@domain, same as %u if there's no domain
# %d - domain part in user@domain, empty if there's no domain
# %h - home directory
#
# See doc/wiki/Variables.txt for full list. Some examples:
#
# mail_location = maildir:~/Maildir
# mail_location = mbox:~/mail:INBOX=/var/mail/%u
# mail_location = mbox:/var/mail/%d/%1n/%n:INDEX=/var/indexes/%d/%1n/%n
#
# <doc/wiki/MailLocation.txt>
#
mail_location = maildir:/Maildir

可以看到这里的配置文件有错误, mail_location = maildir:/Maildir 更改成 mail_location = maildir:~/Maildir

更改后重启,再次测试

[root@mail ~]# /etc/init.d/named start
Starting named: po [ OK ]
[root@mail ~]# postfix start
postfix/postfix-script: fatal: the Postfix mail system is already running
[root@mail ~]# /usr/local/sbin/dovecot -c /etc/dovecot.conf
[root@mail ~]# telnet localhost 110
Trying ::1...
telnet: connect to address ::1: Connection refused
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
+OK Dovecot ready.
USER lisi
+OK
PASS 123123
+OK Logged in.
LIST
+OK 1 messages:
1 475
.
RETR 1
+OK 475 octets
Return-Path: <[email protected]>
X-Original-To: [email protected]
Delivered-To: [email protected]
Received: from locahost (localhost [IPv6:::1])
 by benet.com (Postfix) with SMTP id 495271025B6
 for <[email protected]>; Fri, 22 Jul 2016 22:40:46 +0800 (CST)
subject: A test Mail
Message-Id: <[email protected]>
Date: Fri, 22 Jul 2016 22:40:46 +0800 (CST)
From: [email protected]
To: undisclosed-recipients:;
HELLO!
This is test mail to test postfix!
.

使用outlook测试

测试成功


results matching ""

    No results matching ""