天天看點

Linux 使用mailx發送郵件

一、安裝

yum  install  mailx -y
           

二、修改配置: /etc/mail.rc

# 在配置檔案最後添加以下資訊
set from=[email protected]  # 發送的郵件位址
set smtp=smtp.qq.com  # 發送郵件伺服器
set smtp-auth-user=[email protected]  # 發件人賬号,一般情況下為郵件位址
set smtp-auth-password=xxx  # 發件人密碼
set smtp-auth=login    # 郵件認證方式
           

三、發送郵件

3.1 在标準輸入中輸入郵件内容

mail -s 'mail test' [email protected]
           
輸入完成後成按Ctrl+D結束并發送郵件。

3.2 通過管道傳送郵件正文

echo 'test mail' | mail -s 'mail test' [email protected]
           

3.2 檔案内容作為郵件内容

mail -s 'mail test' [email protected] < /etc/fstab 
           

繼續閱讀