Centos7+Postfix+Dovecot实现内网邮件收发

1. 前期准备:

主机:CentOS release 7.6.1810 (Core)     #安装时选择邮件服务器

IP:192.168.71.108   #示例

本地yum源 #因为是内网,所以建议用镜像搭建本地yum源

2. 基础环境配置

关闭selinux

sed –I ‘s/enforcing/disabled/g’  /etc/selinux/config

Centos7+Postfix+Dovecot实现内网邮件收发

防火墙等配置:

firewall-cmd –add-port=’110/tcp’ –permanent

firewall-cmd –add-port=’25/tcp’ –permanent

Centos7+Postfix+Dovecot实现内网邮件收发

或直接关闭防火墙,因为是内网,也不会有安全问题

systemctl start firewalld.service

主机名配置:

Centos7+Postfix+Dovecot实现内网邮件收发

重启系统以使上述配置生效

shutdown  -r now

3. Postfix安装与配置

3.1. 安装postfix

因为安装centos时选择的是邮件系统,所以检查是否自带postfix服务,如果没带则可通过本地yum源安装:yum -y insatll postfix --nogpgcheck

Centos7+Postfix+Dovecot实现内网邮件收发

3.2. 配置postfix

[root@mail ~]# vim /etc/postfix/main.cf

Centos7+Postfix+Dovecot实现内网邮件收发

Centos7+Postfix+Dovecot实现内网邮件收发

  • myhostname =mail.yzp.com  #定义主机名
  • mydomain =yzp.com   #定义域名
  • myorigin =$mydomain  #定义组织域
  • 我们需要在mydestination的值后面添加 $mydomain ,
  • 如果不添加的话,收件人的地址会有问题,如果添加后,用户发送邮件直接会是xx@yzp.com
  • 取消注释 #local_recipient_maps =

3.3. 启动和检查postfix

[root@mail ~]# systemctl start postfix.service

[root@mail ~]# systemctl enable postfix.service

[root@mail ~]# netstat -nltp

Centos7+Postfix+Dovecot实现内网邮件收发

4. dovecot安装与配置

4.1. 安装dovecot

[root@mail ~]#  yum -y  install dovecot --nogpgcheck

Centos7+Postfix+Dovecot实现内网邮件收发

4.2. 配置dovecot

接下来我们查看dovecot的默认配置文件

[root@mail ~]# cat /etc/dovecot/dovecot.conf

我们看见以下include可以包含的配置文件路径,在该路径下的*.conf文件都会生效

Centos7+Postfix+Dovecot实现内网邮件收发

4.2.1. vim /etc/dovecot/dovecot.conf启用协议以下协议及监听

protocols = imap pop3 lmtp

#启用端口监听

listen = *,::

4.2.2. vim /etc/dovecot/conf.d/10-auth.conf设置如下参数

Centos7+Postfix+Dovecot实现内网邮件收发

Centos7+Postfix+Dovecot实现内网邮件收发

vim /etc/dovecot/conf.d/10-auth.conf

disable_plaintext_auth = no

auth_mechanisms = plain login

!include auth-system.conf.ext

4.2.3. vim /etc/dovecot/conf.d/10-ssl.conf禁用ssl认证

Centos7+Postfix+Dovecot实现内网邮件收发

vim /etc/dovecot/conf.d/10-ssl.conf

ssl = no

4.2.4. vim /etc/dovecot/conf.d/10-logging.conf启用dovecot的日志

Centos7+Postfix+Dovecot实现内网邮件收发

vim /etc/dovecot/conf.d/10-logging.conf

添加

info_log_path = /var/log/dovecot_info.log

debug_log_path = /var/log/dovecot_debug.log

4.3. 启动和检查dovecot

Centos7+Postfix+Dovecot实现内网邮件收发

[root@mail ~]# systemctl start dovecot.service

[root@mail ~]# systemctl enable dovecot.service

[root@mail ~]# netstat -nltp | grep dovecot

5. 创建测试账户与测试邮件收发通信

5.1. 创建两个测试账户

Centos7+Postfix+Dovecot实现内网邮件收发

[root@mail ~]# useradd test1

[root@mail ~]# passwd test1

[root@mail ~]# useradd test2

[root@mail ~]# passwd test2

5.2. 测试110端口:收邮件端口

[root@mail ~]# telnet 192.168.71.108 110

Trying 192.168.71.108...

Connected to 192.168.71.108.

Escape character is '^]'.

+OK [XCLIENT] Dovecot ready.

user test1

+OK

pass 111111

+OK Logged in.

-ERR [SYS/PERM] Permission denied

Connection closed by foreign host.

我们查看log

[root@mail ~]# cd /var/log/

[root@mail log]# tailf maillog

Centos7+Postfix+Dovecot实现内网邮件收发

我们切换到刚才的用户:

[test1@mail ~]$ su - test1

密码:

[test2@mail ~]$  mkdir -p ~/mail/.imap/INBOX

[test1@mail ~]$ su - test2

密码:

[test2@mail ~]$  mkdir -p ~/mail/.imap/INBOX

Centos7+Postfix+Dovecot实现内网邮件收发

再次测试110端口,发现测试通过了

[root@mail ~]# telnet 192.168.71.108 110

Trying 192.168.71.108...

Connected to 192.168.71.108.

Escape character is '^]'.

+OK [XCLIENT] Dovecot ready.

user test1

+OK

pass 111111

+OK Logged in.

quit

+OK Logging out.

Connection closed by foreign host.

5.3. 测试25端口:发邮件端口

[root@mail ~]# telnet 192.168.71.108 25

Trying 192.168.71.108...

Connected to 192.168.71.108.

Escape character is '^]'.

220 mail.yzp.com ESMTP unkown

mail from:test1@yzp.com

250 2.1.0 Ok

rcpt to:test2@yzp.com

250 2.1.5 Ok

data

354 End data with <CR><LF>.<CR><LF>

.

250 2.0.0 Ok: queued as 338CE61533C9

quit

221 2.0.0 Bye

Connection closed by foreign host.

5.4. 测试上述查收上述test1发给test2的邮件

Centos7+Postfix+Dovecot实现内网邮件收发

6. 同局域网内的windows电脑配置foxmail测试邮件收发

6.1. 配置新建账号

Centos7+Postfix+Dovecot实现内网邮件收发

Centos7+Postfix+Dovecot实现内网邮件收发

6.2. 互相收发邮件

Centos7+Postfix+Dovecot实现内网邮件收发

Centos7+Postfix+Dovecot实现内网邮件收发

收发测试通过,至此,环境搭建通过。

7. 检查邮件存储位置

[root@mail postfix]# cat /etc/dovecot/conf.d/10-mail.conf | grep mail_location

# path given in the mail_location setting.

#   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

#mail_location =

# mail_location, which is also the default for it.

Centos7+Postfix+Dovecot实现内网邮件收发

[root@mail postfix]# cd /var/mail/

Centos7+Postfix+Dovecot实现内网邮件收发

上一篇:java邮件收发


下一篇:Java实现邮件收发