Centos 9 Stream配置QQ邮箱报警

一、开启QQ邮箱的POP3/SMTP服务,获取授权码

1、设置–>账户–>开启POP3/SMTP服务

2、发送短信验证码到1069 0700 69,获取授权码

二、安装邮件系统并配置

1、安装postfix,并启动

#yum -y install postfix
#service postfix start

2、安装sendmail-cf

yum -y install sendmail-cf

3、安装mailx

①下载解压包

wget http://ftp.debian.org/debian/pool/main/h/heirloom-mailx/heirloom-mailx_12.5.orig.tar.gz

②解压缩

tar zxvf heirloom-mailx_12.5.orig.tar.gz

③跳转到解压缩目录下

[root@localhost ~]# cd heirloom-mailx-12.5/

④编译安装

make && make install UCBINSTALL=/usr/bin/install

⑤编辑配置文件,配置发送邮件信息

vim /etc/nail.rc

在配置文件的最后添加如下代码:

set [email protected]            #和第三行邮箱地址保持一致
set smtp="smtp.qq.com"               #所使用的外部邮箱的smtp服务器地址
set smtp-auth-user="[email protected]"   #所使用的外部邮箱的用户名
set smtp-auth-password="cfgxxxxxxxxx"       #在QQ邮箱中获取的授权码
set smtp-auth="login"

⑥尝试发送邮件

echo "hello world" | mail -s "testmail" [email protected]

4、编写发邮件脚本

# cd /usr/lib/zabbix/alertscripts
# vim mailx.sh

在配置文件末尾增加如下代码:

#!/bin/bash
#send mail
messages=`echo $3 | tr '\r\n' '\n'`
subject=`echo $2  | tr '\r\n' '\n'`
echo "${messages}"| mail -s "${subject}" $1 >>/tmp/mailx.log 2>&1

5、赋予权限,并测试脚本

[root@localhost alertscripts]# touch /tmp/mailx.log
[root@localhost alertscripts]# chown -R zabbix.zabbix  /tmp/mailx.log
[root@localhost alertscripts]# chmod +x /usr/lib/zabbix/alertscripts/mailx.sh
[root@localhost alertscripts]# chown -R zabbix.zabbix /usr/lib/zabbix/

测试发邮件脚本是否可以正常工作

[root@localhost alertscripts]# ./mailx.sh [email protected] "mail" "zabbix service"

查看邮箱是否收到邮件

猜你喜欢

转载自blog.csdn.net/weixin_49001495/article/details/130153921