今天寫定時腳本時,用到監控服務器是否備份成功,配置sentmail和postfix總是出問題,原本想只是接受個信息,沒必要那么麻煩,直接配置mailx就能滿足了,具體配置如下:
1、安裝mailx
yum install mailx -y
2、編輯發送的配置文件(修改/etc/mail.rc)
vi /etc/mail.rc
#qq.com
set smtp=smtp.qq.com //郵箱所在服務器和端口地址
set from="1147076062@qq.com" //你的qq郵箱
set smtp-auth-user="1147076062@qq.com" smtp-auth-password="bqh***" //郵箱密碼
set smtp-auth=login //默認login即可
echo "郵件正文" | mail -s "郵件主題" 1147076062@qq.com
發送文件的另外幾種格式:
cat file.txt | mail -s "郵件主題" 1147076062@qq.com
mail -s "郵件主題" 1147076062@qq.com < file.txt
echo hello 錦衣衛 | mail -s "測試" 1147076062@qq.com
溫馨提醒:
①記得要進郵箱打開SMTP。
②關閉本機的sendmail服務或者postfix服務等。
③smtp-auth-password="bqh***" 此處是配置授權碼,而不是郵箱的獨立密碼。如果配置錯了會報錯
(smtp-server: 535 Error: ȫʹԃ˚ȨëµȂ¼¡£Ъȩȫ¿´: http://service.mail.qq.com/cgi-b
in/help?subtype=1&&id=28&&no=1001256"/root/dead.letter" 11/303
. . . message not sent.)
---------------------------------------------------------------------------------------------------------
想讓服務器自動發個郵件至163郵箱或者qq郵箱等,可以配置mailx使用外部smtp發送郵件,要是想做郵件服務器的話可以用sentmail和postfix等。