Board logo

标题: CentOS8_安装与配置邮件服务器(Postfix+Dovecot) [打印本页]

作者: admin    时间: 2020-3-10 22:38     标题: CentOS8_安装与配置邮件服务器(Postfix+Dovecot)

实验中,邮件服务器的信息: [root@redhat8 ~]# cat /etc/redhat-release CentOS Linux release 8.2.2004 (Core) [root@redhat8 ~]# uname -r 4.18.0-193.el8.x86_64 [root@redhat8 ~]# hostname redhat8.zhuohua.store [root@redhat8 ~]# cat /etc/hostname redhat8.zhuohua.store 查看本机的IP地址: [root@redhat8 ~]# yum -y install net-tools [root@redhat8 ~]# ifconfig ens160: flags=4163 mtu 1500 inet 192.168.168.155 netmask 255.255.255.0 broadcast 192.168.168.255 inet6 fe80::92ab:5fb4:5373:ad53 prefixlen 64 scopeid 0x20 ether 00:0c:29:15:ba:0c txqueuelen 1000 (Ethernet) RX packets 12189 bytes 15673380 (14.9 MiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 14328 bytes 15733315 (15.0 MiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 lo: flags=73 mtu 65536 inet 127.0.0.1 netmask 255.0.0.0 inet6 ::1 prefixlen 128 scopeid 0x10 loop txqueuelen 1000 (Local Loopback) RX packets 0 bytes 0 (0.0 B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 0 bytes 0 (0.0 B) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 [root@redhat8 ~]# 卸载Senmail: [root@redhat8 ~]# yum -y remove sendmail 设置默认MTA: [root@redhat8 ~]# alternatives --config mta 安装Postfix和Dovecot: [root@redhat8 ~]# yum -y install postfix dovecot 开机自动运行Postfix: [root@redhat8 ~]# systemctl enable postfix Created symlink /etc/systemd/system/multi-user.target.wants/postfix.service → /usr/lib/systemd/system/postfix.service. 开机自动运行Dovecot: [root@redhat8 ~]# systemctl enable dovecot Created symlink /etc/systemd/system/multi-user.target.wants/dovecot.service → /usr/lib/systemd/system/dovecot.service. 查看Postfix的版本: [root@redhat8 ~]# rpm -q postfix postfix-3.3.1-12.el8.x86_64 查看Dovecot的版本: [root@redhat8 ~]# rpm -q dovecot dovecot-2.3.8-2.el8.x86_64 建立用户模板下的邮箱目录,以便于建立新用户时,相应用户的邮箱目录自动被建立:(Postfix用户的邮件文件都会在自己家目录的Maildir文件夹里) [root@redhat8 ~]# mkdir -p /etc/skel/Maildir ###### 配置Postfix: [root@redhat8 ~]# vi /etc/postfix/main.cf #myhostname = host.domain.tld 修改为:(设置为系统的主机名) myhostname = redhat8.zhuohua.store #mydomain = domain.tld 修改为:(设置域名,此处设置将成为E-mail地址“@”后面的部分) mydomain = zhuohua.store #myorigin = $mydomain 修改为: myorigin = $mydomain inet_interfaces = localhost 修改为:(接受来自任意网络的请求) inet_interfaces = all mydestination = $myhostname, localhost.$mydomain, localhost 修改为:(指定发给本地邮件的域名) mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain #mynetworks = 168.100.189.0/28, 127.0.0.0/8 修改为: mynetworks = 127.0.0.0/8 #home_mailbox = Maildir/ 修改为:( 指定用户邮箱目录 ) home_mailbox = Maildir/ #relay_domains = $mydestination 修改为:( 定义允许转发的域名  ) relay_domains = $mydestination #smtpd_banner = $myhostname ESMTP $mail_name ($mail_version) 修改为:( 不显示SMTP服务器的相关信息 ) smtpd_banner = $myhostname ESMTP unknow 追加: smtpd_sasl_type = dovecot smtpd_sasl_path = private/auth smtpd_sasl_auth_enable = yes smtpd_sasl_local_domain = $myhostname smtpd_sasl_security_options = noanonymous smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination smtpd_sasl_security_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination #规定单封邮件的最大容量为15MB ,以字节为单位:(包括附件) message_size_limit = 15728640 保存文件退出后,重启Postfix: [root@redhat8 ~]# systemctl restart postfix ###### 配置Dovecot: [root@redhat8 ~]# vi /etc/dovecot/dovecot.conf #protocols = imap pop3 lmtp submission 修改为: protocols = imap pop3 lmtp #listen = *, :: 修改为: listen = *, :: ###### 配置认证方式: [root@redhat8 ~]# vi /etc/dovecot/conf.d/10-auth.conf #disable_plaintext_auth = yes 修改为: disable_plaintext_auth = no auth_mechanisms = plain 修改为: auth_mechanisms = plain login ###### 配置邮箱文件夹: [root@redhat8 ~]# vi /etc/dovecot/conf.d/10-mail.conf # mail_location = maildir:~/Maildir 修改为: mail_location = maildir:~/Maildir ###### 配置认证: [root@redhat8 ~]# vi /etc/dovecot/conf.d/10-master.conf unix_listener auth-userdb { #mode = 0600 #user = #group = } 修改为: #unix_listener auth-userdb { #mode = 0666 #user = #group = #} # Postfix smtp-auth #unix_listener /var/spool/postfix/private/auth { # mode = 0666 #} 修改为: # Postfix smtp-auth unix_listener /var/spool/postfix/private/auth { mode = 0666 user = postfix group = postfix } 禁用SSL: [root@redhat8 ~]# vi /etc/dovecot/conf.d/10-ssl.conf #ssl = required 修改为: ssl = no ###### 配置POP3: [root@redhat8 ~]# vi /etc/dovecot/conf.d/20-pop3.conf #pop3_uidl_format = %08Xu%08Xv 修改为: pop3_uidl_format = %08Xu%08Xv #pop3_client_workarounds = 修改为: pop3_client_workarounds = outlook-no-nuls oe-ns-eoh 保存文件退出后,重启Dovecot: [root@redhat8 ~]# systemctl restart dovecot ###### 查看Dovecot的进程: [root@redhat8 ~]# ps aux |grep dovecot |grep -v grep root 1236 0.0 0.3 65932 6388 ? Ss 15:35 0:00 /usr/sbin/dovecot -F dovecot 1533 0.0 0.1 22184 2224 ? S 15:35 0:00 dovecot/anvil root 1534 0.0 0.2 22316 3996 ? S 15:35 0:00 dovecot/log root 1535 0.0 0.3 34328 5944 ? S 15:35 0:00 dovecot/config dovecot 1663 0.0 0.2 24440 4060 ? S 15:41 0:00 dovecot/stats dovecot 1664 0.0 0.3 46352 6204 ? S 15:41 0:00 dovecot/auth [root@redhat8 ~]# [root@redhat8 ~]# echo $? 0 [root@redhat8 ~]# 查看Postfix的进程: [root@redhat8 ~]# ps aux |grep postfix |grep -v grep root 1438 0.0 0.3 121720 5848 ? Ss 15:35 0:00 /usr/libexec/postfix/master -w postfix 1440 0.0 0.5 147996 10324 ? S 15:35 0:00 qmgr -l -t unix -u postfix 1679 0.0 0.5 152104 10216 ? S 15:42 0:00 tlsmgr -l -t unix -u postfix 1680 0.0 0.5 147860 9660 ? S 15:42 0:00 anvil -l -t unix -u postfix 1763 0.0 0.5 147864 9632 ? S 15:43 0:00 pickup -l -t unix -u [root@redhat8 ~]# [root@redhat8 ~]# echo $? 0 [root@redhat8 ~]# ###### 插入防火墙规则:( 打开TCP 25、110、143端口 ) [root@redhat8 ~]# firewall-cmd --zone=public --add-port=25/tcp --permanent success [root@redhat8 ~]# firewall-cmd --zone=public --add-port={110/tcp,143/tcp} --permanent success 重新加载firewalld的配置: [root@redhat8 ~]# firewall-cmd --reload success 查看所有打开的防火墙端口: [root@redhat8 ~]# firewall-cmd --zone=public --list-ports 25/tcp 110/tcp 143/tcp 注释: Postfix使用TCP 25端口; Dovecot使用TCP 110、143端口; 查看firewalld的配置文件:(可以在这里修改,然后重新加载firewalld的配置) [root@redhat8 ~]# cat /etc/firewalld/zones/public.xml Public For use in public areas. You do not trust the other computers on networks to not harm your computer. Only selected incoming connections are accepted. ############ 创建Postfix用户:(其实就是系统用户,但不需要登录操作系统) 先创建Postfix用户组: groupadd mailusers 用户密码就是邮箱登录密码: adduser -g mailusers -s /sbin/nologin zhuohua echo '111' | passwd --stdin zhuohua 注释:邮箱帐号为zhuohua@zhuohua.store ### adduser -g mailusers -s /sbin/nologin happy echo '222' | passwd --stdin happy 注释:邮箱帐号为happy@zhuohua.store ###### 客户端使用Foxmail连接邮件服务器: 图片1.png 在Foxmail中创建邮箱帐号zhuohua@zhuohua.store: 图片2.png 笺注: 192.168.168.155 为邮件服务器的IP地址。 依此类推,再在Foxmail中创建邮箱帐号happy@zhuohua.store: 图片3.png 笺注: 要先在邮件服务器上创建Postfix用户。 实验中,zhuohua@zhuohua.store和happy@zhuohua.store可以互相发送、接收邮件,包括附件。 zhuohua@zhuohua.store给happy@zhuohua.store发送邮件: 图片4.png happy@zhuohua.store接收到邮件: 图片5.png ############ ############ 查看有关邮箱、邮件的限制: [root@redhat8 ~]# /usr/sbin/postconf |grep size_limit /usr/sbin/postconf: warning: /etc/postfix/main.cf: unused parameter: smtpd_sasl_security_restrictions=permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination body_checks_size_limit = 51200 bounce_size_limit = 50000 header_size_limit = 102400 mailbox_size_limit = 51200000 message_size_limit = 15728640 注释:由于Postfix版本的问题,所以有warning 解决方法: [root@redhat8 ~]# sed -i '/smtpd_sasl_security_restrictions/d' /etc/postfix/main.cf [root@redhat8 ~]# systemctl restart postfix 现在正常了: [root@redhat8 ~]# /usr/sbin/postconf |grep size_limit body_checks_size_limit = 51200 bounce_size_limit = 50000 header_size_limit = 102400 mailbox_size_limit = 51200000 message_size_limit = 15728640 注释: mailbox_size_limit: #规定单个用户邮箱的最大容量,以字节为单位。(实验中,单个用户邮箱的最大容量可以远远超过50MB) message_size_limit: #规定单封邮件的最大容量(包括附件),以字节为单位。 当mailbox_size_limit的值不为0时,要大于message_size_limit的值。 假如邮件(包括附件)过大,超过message_size_limit的值时,发送邮件会失败的: 图片1.png ###### 自定义Postfix的邮箱、邮件的最大容量: [root@redhat8 ~]# vi /etc/postfix/main.cf 代码有就修改,没有就追加: #不限制单个用户邮箱的大小 mailbox_size_limit = 0 代码有就修改,没有就追加: #规定单封邮件的最大容量大概为80MB message_size_limit = 80000000 保存文件退出后,重启Postfix: [root@redhat8 ~]# systemctl restart postfix 确认修改生效了: [root@redhat8 ~]# /usr/sbin/postconf |grep size_limit body_checks_size_limit = 51200 bounce_size_limit = 50000 header_size_limit = 102400 mailbox_size_limit = 0 message_size_limit = 80000000 ############ ############ 使用Foxmail客户端实现邮件转发: 给邮箱帐号happy@zhuohua.store新建“过滤器”: 选择对应邮箱帐号后,工具》过滤器: 图片2.png 图片3.png 原理:当happy@zhuohua.store使用Foxmail客户端收到zhuohua@zhuohua.store发送的邮件后,自动把邮件转发给j13680432782@126.com 图片4.png 备注: 过滤器名称是自定义的; 实验中,自动转发给QQ邮箱会失败; 过滤器创建成功: 图片5.png ###### 使用zhuohua@zhuohua.store给happy@zhuohua.store发送测试邮件: 图片6.png happy@zhuohua.store接收邮件正常,附件也正常: 图片7.png 备注: 当happy@zhuohua.store使用Foxmail客户端接收到来自zhuohua@zhuohua.store的邮件后,才会转发邮件。 126邮箱接收转发邮件正常,附件也正常: 图片8.png 相关文章: Zabbix使用Agent监控CentOS8/Redhat8 CentOS8_通过脚本发送Zabbix告警邮件(使用Postfix的25端口) CentOS8_Postfix+Dovecot+SquirrelMail CentOS6_安装与配置邮件服务器(Postfix+Dovecot+SquirrelMail)

图片附件: 图片1.png (2021-8-8 01:14, 25.73 KB) / 下载次数 114
http://blog.zhuohua.store/attachment.php?aid=18626&k=2615403cb3aacab3dbd12ca193c3a37a&t=1714624137&sid=uUB73B



图片附件: 图片2.png (2021-8-8 01:14, 81.51 KB) / 下载次数 122
http://blog.zhuohua.store/attachment.php?aid=18627&k=aed1c1fffbd57413e5986412ace35001&t=1714624137&sid=uUB73B



图片附件: 图片3.png (2021-8-8 01:15, 83.76 KB) / 下载次数 125
http://blog.zhuohua.store/attachment.php?aid=18628&k=78c13394e84b6899cc360bb312051d5f&t=1714624137&sid=uUB73B



图片附件: 图片4.png (2021-8-8 01:15, 45.39 KB) / 下载次数 121
http://blog.zhuohua.store/attachment.php?aid=18629&k=205da951f79f305298a1ccf45dde1b21&t=1714624137&sid=uUB73B



图片附件: 图片5.png (2021-8-8 01:16, 44.61 KB) / 下载次数 125
http://blog.zhuohua.store/attachment.php?aid=18630&k=932ec9fc10d342934842a136ab6afddc&t=1714624137&sid=uUB73B



图片附件: 图片1.png (2022-12-17 08:39, 17.2 KB) / 下载次数 37
http://blog.zhuohua.store/attachment.php?aid=22091&k=0c083afd610422756f452397899da170&t=1714624137&sid=uUB73B



图片附件: 图片2.png (2022-12-17 08:40, 49.09 KB) / 下载次数 40
http://blog.zhuohua.store/attachment.php?aid=22092&k=0ff83505bc93f9aac1cb107ba74b067f&t=1714624137&sid=uUB73B



图片附件: 图片3.png (2022-12-17 08:41, 22.77 KB) / 下载次数 37
http://blog.zhuohua.store/attachment.php?aid=22093&k=4700289b569d268fe8625cb5b4d6d8fe&t=1714624137&sid=uUB73B



图片附件: 图片4.png (2022-12-17 08:41, 41.53 KB) / 下载次数 34
http://blog.zhuohua.store/attachment.php?aid=22094&k=227aa383f99c781b305950b5c5cb65aa&t=1714624137&sid=uUB73B



图片附件: 图片5.png (2022-12-17 08:41, 51.07 KB) / 下载次数 19
http://blog.zhuohua.store/attachment.php?aid=22095&k=37020de05820f419e840efa85a3c39e8&t=1714624137&sid=uUB73B



图片附件: 图片6.png (2022-12-17 08:42, 25.81 KB) / 下载次数 18
http://blog.zhuohua.store/attachment.php?aid=22096&k=e22c8fc2f12bef73856a08850d6f31f6&t=1714624137&sid=uUB73B



图片附件: 图片7.png (2022-12-17 08:42, 37.28 KB) / 下载次数 28
http://blog.zhuohua.store/attachment.php?aid=22097&k=0a5f459f0e32170400e0d325ac38adf7&t=1714624137&sid=uUB73B



图片附件: 图片8.png (2022-12-17 08:43, 25.8 KB) / 下载次数 19
http://blog.zhuohua.store/attachment.php?aid=22098&k=0361f7812ff325f0b2eaeb6a3f2a6f33&t=1714624137&sid=uUB73B






欢迎光临 blog.zhuohua.store (http://blog.zhuohua.store/) Powered by Discuz! 7.2