服務器維護CentOS 使用 MUTT發送郵件
2020-06-17 17:25 作者:艾銻無限 瀏覽量:
服務器維護小知識有些時候我們需要在
CentOS服務器上發送郵件,例如備份MySQL數據庫并發送到指定郵箱,這里我們就說下如何從CentOS的shell命令發送郵件。
服務器維護小知識檢查、安裝、啟動sendmail
//檢查
ps -ef | grep sendmail
//安裝
yum install sendmail
//啟動
service sendmail start
//開機啟動
chkconfig --level 2345 sendmail on
檢查并安裝mutt
//檢查mutt是否安裝, 已安裝會返回/usr/bin/mutt
# which mutt
//安裝mutt
# yum install mutt
服務器維護小知識配置mutt
1.配置全局mutt, 直接編輯 /etc/Muttrc 文件
2.配置用戶級mutt, 復制/etc/Muttrc 到 /當前用戶/.muttrc
//為root用戶復制.muttrc
# cp /etc/Muttrc /root/.muttrc
配置mutt, 上述兩種方法修改方式相同
#設置郵件編碼方式
set charset="utf-8"
#自定義發件人信息
set envelope_from=yes #這條默認沒有,請手動添加
set use_from=yes
set from=xxx.com@xx.com
set realname="Master Lee"
測試發送郵件
//語法
mutt [-hnpRvxz][-a<文件>][-b<地址>][-c<地址>][-f<郵件文 件>][-F<配置文件>][-H<郵件草稿>][-i<文件>][-m<類型>] [-s<主題>][郵件地址]
發送
mutt 1343652445@qq.com -s "測試mutt" -a test.txt < test.txt
echo "郵件正文" | mutt 1343652445@qq.com -s"xxxx" -a test.txt
如果郵件發送錯誤,查看日志(/var/log/maillog)
IT運維 我們選擇
北京艾銻無限
以上文章由北京艾銻無限科技發展有限公司整理