yum install mailx
配置文件: /etc/mail.rc
vi /etc/mail.rc
set [email protected] # 發送的郵件地址
set smtp=smtp.126.com # 發送郵件服務器
set [email protected] # 發件人賬號,一般情況下爲郵件地址
set smtp-auth-password=xxx # 發件人密碼
set smtp-auth=login # 郵件認證方式
配置成功後,就可以使用外部 smtp 服務器發送郵件了。
發送郵件方式:
1、在標準輸入中輸入郵件內容:
mail -s 'mail test' [email protected]
this is test mail.
輸入完成後成按Ctrl+D結束併發送郵件。
2、通過管道傳送郵件正文
echo 'test mail' | mail -s 'mail test' [email protected]
3、使用輸入重定向
mail -s 'mail test' [email protected] < /etc/fstab
注意:如果需要發送給多個收件人,收件人之間用逗號隔開。
mail -s 'mail test' [email protected],[email protected] < /etc/fstab