使用sendmail發郵件的配置
yum -y install sendmail
service sendmail start
vim body.txt
test mail from linux.
mail -s "test mail from linux" yourname@163.com,yourname2@163.com <body.txt
mailq #查看郵件隊列
cat /var/log/maillog
【注意:】 多個郵件地址以西文,分割;
配置郵件發送顯示賬號
vim + /etc/mail.rc # For Linux and BSD, this should be set. set bsdcompat set from=devops #把devops換成自己想顯示的名稱
------------------------------------------------------------
郵件相關配置的文件
/etc/aliases
------------------------------------------------------------
如使用外部郵箱smtp方式發郵件,設置smtp的驗證規則配置,同時,在network中配hostname定義,sendmail發郵件只識別hostname.
配置時from和=間不要有空格,不然提示“ Non-null variable name required”。
vim /etc/mail.rc
set from=yourname@163.com smtp=smtp.163.com
set smtp-auth-user=yourname@163.com smtp-auth-password=yourpassword smtp-auth=login
vim /etc/sysconfig/network
hostname mail.163.com
---------------------------------
【測試過程問題記錄】
1、163的郵箱開啟smtp服務時必須設置授權碼,在/etc/mail.rc smtp-auth-password設置成授權碼,不然錯給你看
smtp-server: 535 Error: authentication failed
2、163郵箱不開啟smtp服務,換個錯誤給你看
smtp-server: 550 User has no permission
3、安裝后遇到 如下錯誤則安裝mailx
-bash: mail: command not found
yum install mailx
【總結】
用smtp發個郵件好糾結,各路神仙都要照顧到,不然哪哪都要罷個工。