在要發送郵件的郵箱裏設置POP3/IMAP/SMTP/Exchange/CardDAV/CalDAV服務
往下滑,找到POP3服務,點擊生成授權碼
在家目錄裏創建一個 .mailrc
這裏from、smtp-auth-user屬性的值是要發送郵件的地址。smtp-auth-password屬性的值是上一步的授權碼
set from=[email protected]
set smtp=smtp.qq.com
set smtp-auth-user=[email protected]
set smtp-auth-password=pixaajxcnyfrhbxi
set smtp-auth=login
set ssl-verify=ignore
成功後,就可以發送郵件了
方式一:
[root@centos7: ~]#mail -s test [email protected]
你好啊,我這是測試
EOT
[root@centos7: ~]#
方式二:這裏使用的交互式。可以使用標準輸入來發送郵件
[root@centos7: ~]echo "test mail command" | mail -s subject [email protected]
mail 幫助文檔
[root@centos7: ~]#mail -h
mail: option requires an argument -- h
Usage: mail -eiIUdEFntBDNHRVv~ -T FILE -u USER -h hops -r address -s SUBJECT -a FILE -q FILE -f FILE -A ACCOUNT -b USERS -c USERS -S OPTION users
[root@centos7: ~]#main 1 mail
小Demo
每60秒檢查下磁盤利用率是否達到80%,達到了就發送郵件
#!/bin/bash
EMAIL=[email protected]
TIME=60
WARNING=80
df | sed -nr "/^\/dev\/sd/s#^([^ ]+) .* ([0-9]+)%.*#\1 \2#p" | while read DEVICE use;
do
if [ ${use} -gt ${WARNING} ]; then
echo "${DEVICE} while be full,use:${use}" | mail -s "DISK WARNING" ${EMAIL}
fi
sleep ${TIME}
done