Dovecot配置
Dovecot在本例中充当IMAP、POP服务器的角色,同时它也将负责用户登录时用户身份的验证「Dovecot会将真正的验证工作交给MySQL处理」。因为使用SSL,Dovecot将会使用993「IMAP协议」及995「POP协议」与外界交流,若服务器有iptable之类的玩意儿,请开放相关端口。
这部分的内容配置起来相对简单,但是需要配置的文件繁多。大体上,我们需要配置如下的信息:
开启Dovecot的IMAP、POP3、LMTP协议
告知Dovecot本地邮件的投档路径
连接Dovecot和MySQL数据库以验证用户身份
配置SSL加密相关信息
Dovecot的配置
需要修改的配置文件有:
/etc/dovecot/dovecot.confDovecot的主配置文件
/etc/dovecot/conf.d/10-mail.confDovecot将要操作的磁盘路径相关配置信息
/etc/dovecot/conf.d/10-auth.conf用户验证相关配置信息
/etc/dovecot/conf.d/auth-sql.conf.extSQL-Type验证相关配置信息
/etc/dovecot/dovecot-sql.conf.extDovecot与数据库连接相关配置信息
/etc/dovecot/conf.d/10-master.confDovecot本地socket相关配置信息
/etc/dovecot/conf.d/10-ssl.conf关于SSL的相关配置信息
请注意:
在修改上述文件之前,请一定先做好备份以方便恢复
修改/etc/dovecot/dovecot.conf文件
使用vi编辑器打开/etc/dovecot/dovecot.conf文件并在文件种加入如下内容:
!include conf.d/*.conf# Enable installed protocols!include_try /usr/share/dovecot/protocols.d/*.protocol protocols = imap pop3 lmtp
如果以上内容已经存在,只需要把该行的#号去掉即可
上述内容大致的意思是:告诉Dovecot启用所有.conf文件;并开启Dovecot的imap、pop3、lmtp等相关协议使之正常工作
修改/etc/dovecot/conf.d/10-mail.conf文件
打开文件并找到mail_location相关信息,将其指定到本地磁盘的某个路径,这个路径将来会存放收到的邮件,如下所示:
mail_location = maildir:/var/mail/vhosts/%d/%n
同时,找到文件中mail_privileged_group相关信息并将起修改为:
mail_privileged_group = mail
保存文件并退出
在命令行种输入如下内容以查看/var/mail路径的权限:
ls -ld /var/mail
显示的内容大致应该是:
drwxrwsr-x 2 root mail 4096 May 11 15:08 /var/mail
创建/var/mail/vhosts/文件夹给每个需要启用的域名:
mkdir -p /var/mail/vhosts/mydomain.com
输入如下命令以新建vmail用户组及用户并赋权限
groupadd -g 5000 vmail useradd -g vmail -u 5000 vmail -d /var/mail
接下来修改一下/var/mail/目录的权限,使vmail能够访问:
chown -R vmail:vmail /var/mail
修改/etc/dovecot/conf.d/10-auth.conf文件
找到文件中disable_plaintext_auth并取消注释
disable_plaintext_auth = yes
找到文件中auth_mechanisms并将其修改为如下值:
auth_mechanisms = plain login
默认情况下,Dovecot是允许Ubuntu系统用户登录使用的,我们需要将其禁用。找到文件种如下内容并将其注释:
#!include auth-system.conf.ext
开启Dovecot的MySQL支持,取消!include auth-sql.conf.ext的注释符号:
#!include auth-system.conf.ext !include auth-sql.conf.ext #!include auth-ldap.conf.ext #!include auth-passwdfile.conf.ext #!include auth-checkpassword.conf.ext #!include auth-vpopmail.conf.ext #!include auth-static.conf.ext
修改/etc/dovecot/conf.d/auth-sql.conf.ext文件
在文件中加入如下内容:
passdb { driver = sql args = /etc/dovecot/dovecot-sql.conf.ext } userdb { driver = static args = uid=vmail gid=vmail home=/var/mail/vhosts/%d/%n }
修改/etc/dovecot/dovecot-sql.conf.ext文件
取消文件中driver行的注释,并将其修改为如下:
driver = mysql
取消文件中connect行的注释,并将其修改为如下:
connect = host=127.0.0.1 dbname=mailserver user=mailserver password=mailserver123
取消文件中default_pass_scheme行的注释,并将其修改为如下:
default_pass_scheme = SHA512-CRYPT
取消文件中password_query行的注释,并将起修改为如下:
password_query = SELECT email as user, password FROM virtual_users WHERE email='%u';
保存退出
在命令行种输入如下内容以修改目录权限:
chown -R vmail:dovecot /etc/dovecotchmod -R o-rwx /etc/dovecot
修改/etc/dovecot/conf.d/10-master.conf文件
打开文件做如下修改「通过将端口设置为0,以禁用非SSL加密的IMAP和POP3协议」:
service imap-login { inet_listener imap { port = 0 } ... } service pop3-login { inet_listener pop3 { port = 0 } ... }
找到文件中的service lmtp并将其修改如下:
service lmtp { unix_listener /var/spool/postfix/private/dovecot-lmtp { mode = 0600 user = postfix group = postfix } # Create inet listener only if you can't use the above UNIX socket #inet_listener lmtp { #Avoid making LMTP visible for the entire internet #address = #port = #} }
找到文件中service auth并将其内容修改如下:
service auth { # auth_socket_path points to this userdb socket by default. It's typically # used by dovecot-lda, doveadm, possibly imap process, etc. Its default # permissions make it readable only by root, but you may need to relax these # permissions. Users that have access to this socket are able to get a list # of all usernames and get results of everyone's userdb lookups. unix_listener /var/spool/postfix/private/auth { mode = 0666 user = postfix group = postfix } unix_listener auth-userdb { mode = 0600 user = vmail #group = } # Postfix smtp-auth #unix_listener /var/spool/postfix/private/auth { # mode = 0666 #} # Auth process is run as this user. user = dovecot }
找到文件中service auth-worker内容并修改如下:
service auth-worker { # Auth worker process is run as root by default, so that it can access # /etc/shadow. If this isn't necessary, the user should be changed to # $default_internal_user. user = vmail }
修改/etc/dovecot/conf.d/10-ssl.conf文件
找到文件中ssl_cert并修改内容如下「请确保dovecot的pem文件已经存在,如果大家使用了自己的SSL文件,请将如下内容修改为相应的路径」:
ssl_cert = </etc/dovecot/dovecot.pem ssl_key = </etc/dovecot/private/dovecot.pem
强制用户使用SSL加密:
ssl = required
重新启动Dovecot服务:
service dovecot restart
接下来,会有几处报错,本文最重要的就是把这些记录下来。
(tried to use disabled plaintext auth)
还是dovecot的问题,找到/etc/dovecot/dovecot.conf 文档,编辑里面的内容
protocols = imap pop3 lmtp
disable_plaintext_auth=no
ssl_disable = no
#ssl_disble 改成了 ssl
(Permission denied (euid=5000(vmail) egid=5000(vmail) missing +w perm: /var/mail, euid is not dir own)
收件人邮件地址(XXXX@XXXX.com)不存在,邮件无法送达。
host mail.XXXX.com[218.xxx.xxx.xxx] said: 550 5.1.1 : Recipient address rejected: User unknown in local recipient table (in reply to RCPT TO command)
注释了 mydestination = ..这行 重启postfix
Postfix/Dovecot - lost connection with [private/dovecot-lmtp]
https://ubuntuforums.org/showthread.php?t=2216486
I set a value for the ‘postmaster_address’ setting within the ’15-lda.conf’ file and restarted DoveCot, then went on to send yet another email to my server using Gmail. I waited about 5 seconds and BOOM! my email client started to go crazy by spitting out all of the email messages that I had sent to my server whilst debugging things
忘记/etc/dovecot/conf.d/15-lda.conf中设置管理员邮箱了
https://projectnotedump.wordpress.com/2013/09/08/our-email-server-is-online/
dovecot-lmtp does not exist
https://serverfault.com/questions/512219/dovecot-lmtp-does-not-exist
设置用户和用户组 postfix还有mode0666,如果设置了话,创建一个软连接
ls -l /var/spool/postfix/private/dovecot-lmtp
If you're specifying the dovecot-lmtp socket name as above, it should now exist, check with ls -l /var/spool/postfix/private/dovecot-lmtpThis should now play nicely with Postfix.
Error: Postfix/Dovecot - warning: SASL: Connect to private/auth failed: No such file or directory
不用看楼主发的,因为我试过了没用,看下面的回复。
I had exactly the same problem and the instructions on this page did not help at all. In fact, the instructions on postfix site did not help either.On our system, here's what helped - chown postfix:postfix /var/spool/postfix/private/auth chmod 666 /var/spool/postfix/private/auth And, in /etc/dovecot/conf.d/10-master.conf (or /usr/local/etc/dovecot/conf.d/10-master.conf) set the config like this - unix_listener auth-userdb { mode = 0666 user = postfix group = postfix } # Postfix smtp-auth unix_listener /var/spool/postfix/private/auth { mode = 0666 } Lastly, /etc/init.d/dovecot restart
好了,至此基本上可以了。
后面还有一些别的要改的这几天也没有时间管,开放给用户使用是没大问题了。