该实验的作用:
- 实现邮件服务的快速配置,包括安装必要的软件、下载和配置 SSL 证书,以及设置 SMTP 邮件发送参数。
- 通过用户提供的 QQ 邮箱和授权码,配置
mailx 实现通过 QQ 邮箱发送邮件。 - 测试邮件发送功能,确认邮件配置是否成功。
1.配置 Postfix 和 mailx
yum安装邮件服务包,并配置 Postfix 和 mailx
yum -y install sendmail mailx postfix
启动并检查 Postfix 服务
systemctl start postfix
systemctl enable postfix
systemctl status postfix
配置邮件认证证书路径
mkdir -p /root/.certs
下载 QQ 邮箱 SSL 证书...
echo -n | openssl s_client -connect smtp.qq.com:465 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > /root/.certs/qq.crt
添加证书到 NSS 数据库
certutil -A -n "GeoTrust SSL CA" -t "C,," -d /root/.certs -i /root/.certs/qq.crt
certutil -A -n "GeoTrust Global CA" -t "C,," -d /root/.certs -i /root/.certs/qq.crt
certutil -A -n "GeoTrust SSL CA - G3" -t "Pu,Pu,Pu" -d /root/.certs -i /root/.certs/qq.crt
2.配置邮件发送相关设置,打开邮箱的smtp协议,这里以qq邮箱为例
1.打开qq邮箱,获取授权码

生成授权码并保存

修改 /etc/mail.rc 配置文件
echo "set from=这里输入你的qq号@qq.com" >> /etc/mail.rc
echo "set smtp-auth-user=这里输入你的qq号" >> /etc/mail.rc
echo "set smtp-auth-password=这里输入你的授权码" >> /etc/mail.rc
cat >> /etc/mail.rc << EOF
set smtp=smtp.qq.com
set smtp-use-starttls
set ssl-verify=ignore
set nss-config-dir=/root/.certs
EOF
配置成功后通过邮件发送成功通知
echo "邮件配置成功!" | mail -s "邮件服务配置成功" 这里输入你的qq号@qq.com
到这里就完成了
