搭建支持Web客户端的邮件服务器(Postfix + OpenWebMail)
邮箱地址为:用户名@sziit2003010211.cn
Postfix的配置见上一篇笔记——支持邮件客户端的邮件服务器
OpenWebMail的配置可直接进入官网查看官方README配置文档https://openwebmail.org/openwebmail/download/centos/el8/
Shell
#/bin/bash
#配置DNS
dnf install bind -y
ip='192.168.11.100' # 部署的主机的IP
sed -i "s/listen-on port.*};/listen-on port 53 { ${ip}; };/" /etc/named.conf
sed -i 's/allow-query.*};/allow-query { any; };/' /etc/named.conf
domain='sziit2003010211.cn' # 配置的邮件服务器要使用的域名
sed -i '$a zone \'"\"${domain}\" IN {\n\ttype master;\n\tfile \"${domain}.zone\";\n};" /etc/named.rfc1912.zones
dns_conffile="/var/named/${domain}.zone"
cp -p /var/named/named.empty ${dns_conffile}
sed -i 's/rname.invalid/hczyyds@qq.com/' ${dns_conffile}
sed -i "s/127.0.0.1/${ip}/" ${dns_conffile}
sed -i '$a mail IN A '"${ip}" ${dns_conffile}
sed -i '$a '"${domain}. IN MX 10 mail.${domain}." ${dns_conffile}
systemctl restart named.service
if [ $? -ne 0 ]
then
echo '启动named失败'
exit
fi
#解决SMTP服务问题
dnf install postfix -y
conf_file='/etc/postfix/main.cf'
sed -i '$a '"myhostname = mail.${domain}" ${conf_file}
sed -i '$a '"mydomain = ${domain}" ${conf_file}
sed -i '$a myorigin = $mydomain' ${conf_file}
sed -i '$a inet_interfaces = all' ${conf_file}
sed -i '$a mydestination = $myhostname, $mydomain, localhost' ${conf_file}
systemctl restart postfix.service
if [ $? -ne 0 ]
then
echo '启动postfix失败'
exit
fi
#配置并启动Apache
dnf install httpd -y
systemctl start httpd.service
#安装配置OpenWebMail
#Install "Development Tools" group if not installed
dnf groupinstall 'Development Tools' -y
#Configure openwebmail repository for EL8
dnf install yum-utils -y
yum-config-manager --add-repo https://openwebmail.org/repo/el8/openwebmail-el8.repo
#Install openwebmail pkgs for EL8
yum install openwebmail -y
#Run openwebmail-tool to initialize
/usr/local/bin/openwebmail-tool --init
/usr/local/bin/openwebmail-tool --fix
#浏览器访问测试
#http://服务器地址/webmail
#完善工作
#1.创建初始页
cp /var/www/data/openwebmail/redirect.html /var/www/html/index.html
#2.更改为中文界面
sed -i 's/.*default_language .*/default_language zh_CN.UTF-8/' /var/www/cgi-bin/openwebmail/etc/openwebmail.conf
sed -i 's/.*default_iconset .*/default_iconset Cool3D.Chinese.Simplified/' /var/www/cgi-bin/openwebmail/etc/openwebmail.conf
#3.修改缺省域
sed -i 's/.*domainnames .*/domainnames sziit2003010211.cn/' /var/www/cgi-bin/openwebmail/etc/openwebmail.conf
#配置相关服务
systemctl enable named.service
systemctl enable postfix.service
systemctl enable httpd.service
systemctl restart named.service
systemctl restart postfix.service
systemctl restart httpd.service
#防火墙配置
firewall-cmd --add-service=dns --permanent
firewall-cmd --add-service=smtp --permanent
firewall-cmd --add-service=pop3s --permanent
firewall-cmd --add-service=http --permanent
firewall-cmd --reload
#SELinux配置
chcon -t httpd_unconfined_script_exec_t /var/www/cgi-bin/openwebmail/openwebmail*.pl