搭建支持Web客户端的邮件服务器(Postfix + OpenWebMail)

邮箱地址为:用户名@sziit2003010211.cn

Postfix的配置见上一篇笔记——支持邮件客户端的邮件服务器

OpenWebMail的配置可直接进入官网查看官方README配置文档https://openwebmail.org/openwebmail/download/centos/el8/

Shell

  1. #/bin/bash
  2. #配置DNS
  3. dnf install bind -y
  4. ip='192.168.11.100' # 部署的主机的IP
  5. sed -i "s/listen-on port.*};/listen-on port 53 { ${ip}; };/" /etc/named.conf
  6. sed -i 's/allow-query.*};/allow-query { any; };/' /etc/named.conf
  7. domain='sziit2003010211.cn' # 配置的邮件服务器要使用的域名
  8. sed -i '$a zone \'"\"${domain}\" IN {\n\ttype master;\n\tfile \"${domain}.zone\";\n};" /etc/named.rfc1912.zones
  9. dns_conffile="/var/named/${domain}.zone"
  10. cp -p /var/named/named.empty ${dns_conffile}
  11. sed -i 's/rname.invalid/hczyyds@qq.com/' ${dns_conffile}
  12. sed -i "s/127.0.0.1/${ip}/" ${dns_conffile}
  13. sed -i '$a mail IN A '"${ip}" ${dns_conffile}
  14. sed -i '$a '"${domain}. IN MX 10 mail.${domain}." ${dns_conffile}
  15. systemctl restart named.service
  16. if [ $? -ne 0 ]
  17. then
  18. echo '启动named失败'
  19. exit
  20. fi
  21. #解决SMTP服务问题
  22. dnf install postfix -y
  23. conf_file='/etc/postfix/main.cf'
  24. sed -i '$a '"myhostname = mail.${domain}" ${conf_file}
  25. sed -i '$a '"mydomain = ${domain}" ${conf_file}
  26. sed -i '$a myorigin = $mydomain' ${conf_file}
  27. sed -i '$a inet_interfaces = all' ${conf_file}
  28. sed -i '$a mydestination = $myhostname, $mydomain, localhost' ${conf_file}
  29. systemctl restart postfix.service
  30. if [ $? -ne 0 ]
  31. then
  32. echo '启动postfix失败'
  33. exit
  34. fi
  35. #配置并启动Apache
  36. dnf install httpd -y
  37. systemctl start httpd.service
  38. #安装配置OpenWebMail
  39. #Install "Development Tools" group if not installed
  40. dnf groupinstall 'Development Tools' -y
  41. #Configure openwebmail repository for EL8
  42. dnf install yum-utils -y
  43. yum-config-manager --add-repo https://openwebmail.org/repo/el8/openwebmail-el8.repo
  44. #Install openwebmail pkgs for EL8
  45. yum install openwebmail -y
  46. #Run openwebmail-tool to initialize
  47. /usr/local/bin/openwebmail-tool --init
  48. /usr/local/bin/openwebmail-tool --fix
  49. #浏览器访问测试
  50. #http://服务器地址/webmail
  51. #完善工作
  52. #1.创建初始页
  53. cp /var/www/data/openwebmail/redirect.html /var/www/html/index.html
  54. #2.更改为中文界面
  55. sed -i 's/.*default_language .*/default_language zh_CN.UTF-8/' /var/www/cgi-bin/openwebmail/etc/openwebmail.conf
  56. sed -i 's/.*default_iconset .*/default_iconset Cool3D.Chinese.Simplified/' /var/www/cgi-bin/openwebmail/etc/openwebmail.conf
  57. #3.修改缺省域
  58. sed -i 's/.*domainnames .*/domainnames sziit2003010211.cn/' /var/www/cgi-bin/openwebmail/etc/openwebmail.conf
  59. #配置相关服务
  60. systemctl enable named.service
  61. systemctl enable postfix.service
  62. systemctl enable httpd.service
  63. systemctl restart named.service
  64. systemctl restart postfix.service
  65. systemctl restart httpd.service
  66. #防火墙配置
  67. firewall-cmd --add-service=dns --permanent
  68. firewall-cmd --add-service=smtp --permanent
  69. firewall-cmd --add-service=pop3s --permanent
  70. firewall-cmd --add-service=http --permanent
  71. firewall-cmd --reload
  72. #SELinux配置
  73. chcon -t httpd_unconfined_script_exec_t /var/www/cgi-bin/openwebmail/openwebmail*.pl