该功能在一些定时任务报警中经常会使用到,比较实用,类似的还有发送微信消息等方式,通知给运维人员一些信息。
本文以centos7.6为例
1、安装mail软件
CentOS/RHEL系统yum -y install mailx
Debian/Ubuntu系统:
apt install mailutils
2、配置mail文件
将以下内容添加在配置文件最下端
set [email protected] # 发送的源邮箱
set smtp=smtps://smtp.qq.com:465 # 要发送的邮箱服务器,可以百度搜到,以qq邮箱为例
set [email protected] # 发送的源邮箱
set smtp-auth-password= # 邮箱的授权码,可上百度搜每个邮箱的POP3/IMAP/SMTP授权码怎么开启
set smtp-auth=login # 设置SMTP服务器使用登录验证方式。
set ssl-verify=ignore # 设置忽略SSL证书验证。
set nss-config-dir=/etc/pki/nssdb/ # 设置NSS(Network Security Services)配置目录为/etc/pki/nssdb/。
3、测试邮箱功能
mail -s '测试标题' [email protected] < 1.txt
或
mail -s '测试标题' [email protected] << EOF
内容
EOF
4、可以结合需求,将发送邮箱功能写入脚本,再将脚本放入定时任务定时运行
标签:发邮件,set,mail,smtp,如何,Linux,邮箱,com,example From: https://www.cnblogs.com/qwsx/p/18203533/mail