Postfix+Dovecot+Roundcube开源邮件系统搭建系列4:Dovecot安装配置

1. Dovecot安装

安装Dovecot:

yum -y install dovecot dovecot-mysql

启动服务并设置开机自启动:

systemctl start dovecot
systemctl enable dovecot

2. Dovecot配置

Dovecot配置文件目录:/etc/dovecot,在该目录中dovecot.conf和conf.d目录下的配置文件很重要,下面分别做配置介绍。

2.1 /etc/dovecot/dovecot.conf 配置文件:

该配置文件是dovecot的主配置,去掉注释,相对简单。主要内容如下:

# 启动imap、pop3、lmtp协议
protocols = imap lmtp pop3
# 监听所有地址,包含ipv4和ipv6
listen = *, ::
# 最大连接数限制
mail_max_userip_connections = 50
# 包含conf.d目录下所有的.conf配置文件
!include conf.d/*.conf
!include_try local.conf

2.2 /etc/dovecot/conf.d/10-mail.conf  配置文件:

增加或修改如下配置:

# 邮件存储位置,%d表示域名,%n表示用户名
mail_location = maildir:/var/mail/vhosts/%d/%n
# /var/mail的权限组设置为mail
mail_privileged_group = mail

2.3 用户及目录配置

添加用户和组:

groupadd -g 5000 vmail
useradd -g vmail -u 5000 vmail -d /var/mail

创建域名目录:

# 域名需要根据实际更换
mkdir -p /var/mail/mailabc.cn

设置目录所有者和所有组:

chown -R vmail:vmail /var/mail/mailabc.cn
chown -R vmail:dovecot /etc/dovecot
chmod -R o-rwx /etc/dovecot

2.4 /etc/dovecot/conf.d/10-auth.conf 配置文件:

添加或修改如下配置:

# 禁用明文密码
disable_plaintext_auth = yes
# 密码授权机制设置为明文,即密码本身不做加密,我们已经启用了TLS传输加密
auth_mechanisms = plain login
# 引用该配置文件启用MySQL授权
!include auth-sql.conf.ext
# 屏蔽系统授权的配置
#!include auth-system.conf.ext

2.5 /etc/dovecot/conf.d/auth-sql.conf.ext 配置文件:

修改如下配置段内容:

passdb {
  driver = sql
  # 这里引入下面的配置文件作为mysql的相关参数
  args = /etc/dovecot/dovecot-sql.conf.ext
}
userdb {
  # 用户数据采用static (静态) 方式,通常,SQL数据库也可以做这件事,也可以通过它得到用户的UID,GID和主目录。但此处如果我们仅使用静态UID和GID,并且可以使用模板指定主目录,它会比SQL方式略快一些。
  driver = static
  args = uid=vmail gid=vmail home=/var/mail/vhosts/%d/%n
}

2.6 /etc/dovecot/dovecot-sql.conf.ext 配置文件:

/etc/dovecot/conf.d/auth-sql.conf.ext 引用了该配置文件,用于查询用户和密码。具体内容如下(其中的数据库名称、授权用户及密码需要根据实际情况修改):

driver = mysql
connect = host=127.0.0.1 dbname=maildb user=mailuser password=admin@123
default_pass_scheme = SHA512-CRYPT
password_query = SELECT email as user, password FROM vt_user WHERE email='%u';

附件说明:查询必须返回用户名和密码,并且 Dovecot 必须在 user 和 password 变量中使用这些值。因此,如果数据库使用不同的列名称,请使用 AS SQL 命令重命名结果中的列。

2.7 /etc/dovecot/conf.d/10-master.conf 配置文件:

这个文件主要作用是为了打通dovecot和postfix的关联,授权postfix通过lmtp协议访问属于dovecot的地盘,访问权限是0600,表示有读写权限,但无执行权限。这个文件的源文件也比较庞杂,里面对多个协议都有设定,但是如果你全部把它们删了也没关系,等于采用默认设置。

参考内容如下:

service lmtp {
  unix_listener /var/spool/postfix/private/dovecot-lmtp {
   mode = 0600
   user = postfix
   group = postfix
  }
}

service auth {
  unix_listener /var/spool/postfix/private/auth {
    mode = 0666
    user = postfix
    group = postfix
  }

  unix_listener auth-userdb {
   mode = 0600
   user = vmail
  }
  user = dovecot
}

service auth-worker {
  user = vmail
}

2.8 /etc/dovecot/conf.d/10-ssl.conf 配置文件:

该配置文件主要用来配置ssl协议及相关证书。

ssl = required
# 指定证书位置,和Postfix采用相同的证书
ssl_cert = </var/sslcert/www.mailabc.cn.pem
ssl_key = </var/sslcert/www.mailabc.cn.key
ssl_cipher_list = PROFILE=SYSTEM

2.9 /etc/dovecot/conf.d/15-mailboxes.conf 配置文件:

这个文件是用来指定收件箱的命名空间的,auto = create表示当这些邮箱都没有的时候,就自动创建它,这里指定的都是常规的,比如收件箱,已发送,垃圾箱,已删除等等,如果需要别的种类,请自行研究。

namespace inbox {
  # inbox = yes配置是增加的,据说不加会有问题
  inbox = yes
  mailbox Drafts {
    auto = create
    special_use = \Drafts
  }
  mailbox Junk {
    auto = create
    special_use = \Junk
  }
  mailbox Trash {
    auto = create
    special_use = \Trash
  }

  mailbox Sent {
    auto = create
    special_use = \Sent
  }
  mailbox "Sent Messages" {
    auto = create
    special_use = \Sent
  }
}

3. 测试验证

至此,Dovecot 配置已完毕,可以重启服务进行测试验证。

stystemctl restart postfix dovecot

3.1 端口监听检查

通过netstat命令查看,可以看到110、143、993、995、587、25、465端口监听均正常。

[root@localhost ~]# netstat -tuanp | grep -i listen
tcp        0      0 0.0.0.0:993             0.0.0.0:*               LISTEN      2331/dovecot        
tcp        0      0 0.0.0.0:995             0.0.0.0:*               LISTEN      2331/dovecot             
tcp        0      0 0.0.0.0:3306            0.0.0.0:*               LISTEN      795/mariadbd        
tcp        0      0 0.0.0.0:587             0.0.0.0:*               LISTEN      1692/master         
tcp        0      0 0.0.0.0:110             0.0.0.0:*               LISTEN      2331/dovecot        
tcp        0      0 0.0.0.0:143             0.0.0.0:*               LISTEN      2331/dovecot            
tcp6       0      0 :::25                   :::*                    LISTEN      1692/master         
tcp6       0      0 :::993                  :::*                    LISTEN      2331/dovecot        
tcp6       0      0 :::995                  :::*                    LISTEN      2331/dovecot              
tcp6       0      0 :::3306                 :::*                    LISTEN      795/mariadbd        
tcp6       0      0 :::587                  :::*                    LISTEN      1692/master         
tcp6       0      0 :::110                  :::*                    LISTEN      2331/dovecot        
tcp6       0      0 :::143                  :::*                    LISTEN      2331/dovecot        
tcp6       0      0 :::465                  :::*                    LISTEN      1692/master

3.2 服务连通性检查

smtp服务:

[root@localhost ~]# telnet 0 25
Trying 0.0.0.0...
Connected to 0.
Escape character is '^]'.
220 mail.mailabc.cn ESMTP Postfix

pop3服务:

[root@localhost ~]# telnet 0 110
Trying 0.0.0.0...
Connected to 0.
Escape character is '^]'.
+OK Dovecot ready.

imap服务:

[root@localhost ~]# telnet 0 143
Trying 0.0.0.0...
Connected to 0.
Escape character is '^]'.
* OK [CAPABILITY IMAP4rev1 SASL-IR LOGIN-REFERRALS ID ENABLE IDLE LITERAL+ STARTTLS AUTH=PLAIN AUTH=LOGIN] Dovecot ready.

3.3 客户配置测试

Foxmail配置imap协议,并进行收发测试。

Foxmail客户端配置

至此,Dovecot配置完毕。

其他配置请参考本系列其他文章。

参考来源:Postfix+Dovecot+Roundcube开源邮件系统搭建系列4:Dovecot安装配置 | MailABC邮件知识百科

  • 12
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
CentOS+Postfix+Dovecot+Postfixadmin+Roundcube邮件服务器的搭建步骤如下: 1. 安装 CentOS 操作系统,并更新至最新版。 2. 安装 Postfix 邮件服务器,并进行基本配置。 3. 安装 Dovecot IMAP/POP3 服务器,并进行基本配置。 4. 安装 Postfixadmin 邮箱管理系统,并进行基本配置。 5. 安装 Roundcube Webmail 邮件客户端,并进行基本配置。 具体步骤如下: 1. 安装 CentOS 操作系统,并更新至最新版。 在安装 CentOS 操作系统时,选择最小化安装,并根据实际情况进行分区和网络配置安装完成后,使用以下命令更新系统: ``` yum update ``` 2. 安装 Postfix 邮件服务器,并进行基本配置。 使用以下命令安装 Postfix: ``` yum install postfix ``` 安装完成后,修改 /etc/postfix/main.cf 文件,使其支持 TLS 和 SASL 认证: ``` smtpd_tls_cert_file = /etc/pki/tls/certs/server.crt smtpd_tls_key_file = /etc/pki/tls/private/server.key smtpd_tls_security_level = may smtp_tls_security_level = may smtpd_sasl_type = dovecot smtpd_sasl_path = private/auth smtpd_sasl_auth_enable = yes smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination ``` 然后重启 Postfix 服务: ``` systemctl restart postfix ``` 3. 安装 Dovecot IMAP/POP3 服务器,并进行基本配置。 使用以下命令安装 Dovecot: ``` yum install dovecot ``` 安装完成后,修改 /etc/dovecot/dovecot.conf 文件,使其支持 TLS 和 SASL 认证: ``` ssl_cert = </etc/pki/tls/certs/server.crt ssl_key = </etc/pki/tls/private/server.key auth_mechanisms = plain login ``` 然后重启 Dovecot 服务: ``` systemctl restart dovecot ``` 4. 安装 Postfixadmin 邮箱管理系统,并进行基本配置。 使用以下命令安装 Postfixadmin: ``` yum install postfixadmin ``` 安装完成后,修改 /etc/httpd/conf.d/postfixadmin.conf 文件,使其支持 SSL: ``` SSLEngine on SSLCertificateFile /etc/pki/tls/certs/server.crt SSLCertificateKeyFile /etc/pki/tls/private/server.key ``` 然后重启 Apache 服务: ``` systemctl restart httpd ``` 访问 https://your-domain.com/postfixadmin,使用管理员账号登录,创建邮箱账号和域名等相关配置。 5. 安装 Roundcube Webmail 邮件客户端,并进行基本配置。 使用以下命令安装 Roundcube: ``` yum install roundcubemail ``` 安装完成后,修改 /etc/httpd/conf.d/roundcubemail.conf 文件,使其支持 SSL: ``` SSLEngine on SSLCertificateFile /etc/pki/tls/certs/server.crt SSLCertificateKeyFile /etc/pki/tls/private/server.key ``` 然后重启 Apache 服务: ``` systemctl restart httpd ``` 访问 https://your-domain.com/roundcubemail,使用邮箱账号登录,即可使用 Roundcube 邮件客户端。 以上就是 CentOS+Postfix+Dovecot+Postfixadmin+Roundcube邮件服务器的搭建步骤,如有问题可以参考相关文档或者咨询技术人员。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值