天天看點

centos下使用sendmial發送郵件

最近需要對伺服器狀态進行監測,發現異常郵件到運維人員,故記錄下建立sendmial發送郵件的操作過程。

一、安裝sendmail與mail

  1、安裝sendmail:

     1) centos下可以安裝指令:yum -y install sendmail

     2) 安裝完後啟動sendmail指令:service sendmail start

  2、安裝mail

     安裝指令:yum install -y mailx

二、設定發件人資訊

  上述發送郵件預設會使用linux目前登入使用者信,通常會被當成垃圾郵件,指定發件人郵箱資訊指令:vi /etc/mail.rc,編輯内容如:

set [email protected]
set smtp=smtp.qq.com
set smtp-auth-user=qq
set smtp-auth-password=password
set smtp-auth=login      

   注意配置中的smtp-auth-password不是郵箱登入密碼,是郵箱伺服器開啟smtp的授權碼

centos下使用sendmial發送郵件

三、發送郵件

    1、通過檔案内容發送

     發送指令:mail -s 'mail test' [email protected] < con.txt ("mail test"為郵件主題,[email protected]為收件人郵箱,con.txt儲存郵件内容)

  2、通過管道符直接發送

     發送指令:echo "this is my test mail" | mail -s 'mail test' [email protected]

繼續閱讀