最近在實施服務端日志監控腳本,需要對異常情況發送郵件通知相關責任人,記錄下centos通過sendmail發送郵件的配置過程。
一. 安裝sendmail和mailx
1、安裝sendmail:
?1): centos下可以安裝命令:
yum?install?-y?sendmail service?sendmail?start yum?install?mailx
二. 發送郵件
1、通過文件內容發送
發送命令如下: mail?-s?'mail?test'?yyy@xxx.com?<?mail.txt #?"mail?test"為郵箱主題,"yyy@xxx.com"為收件人郵箱,"mail.txt"為郵件內容
2、 通過管道符直接發送
發送命令如下: echo?"this?is?my?test?mail"|mail?-s?'mail?test'?xxx@yyy.com #?"mail?test"為郵箱主題,"yyy@xxx.com"為收件人郵箱
三. 設置發件人信息
上述發送郵件默認會使用linux當前登錄用戶信,通常會被當成垃圾郵件,指定發件人郵箱信息命令:vi /etc/mail.rc,編輯內容如:
set?from=username@163.com set?smtp=smtp.163.com set?smtp-auth-user=username set?smtp-auth-password=password set?smtp-auth=login
注意配置中的smtp-auth-password不是郵箱登錄密碼,是郵箱服務器開啟smtp的授權碼,每個郵箱開啟授權碼操作不同(網易163郵箱開啟菜單:設置-> 客戶端授權密碼)。
轉載于:https://blog.51cto.com/yasar/1956218