安裝sendmail
執行:
[root@vps478753 ~]# yum -y install sendmail
程式會自動搜尋出sendmail安裝程式自動安裝。
安裝好sendmail以後執行以下命令啟動sendmail
[root@vps478753 ~]# service sendmail start
Starting sendmail: [ OK ]
Starting sm-client: [ OK ]
啟動以後我們可以執行mail命令測試一下是否能發送郵件
一、通過檔案內容發送郵件
首先建立一個body.txt
[root@vps478753 ~]# touch body.txt
寫入內容
[root@vps478753 ~]# echo 'This is test mail'>body.txt
發送郵件
[root@vps478753 ~]# mail -s 'Test mail' admin@vpsrr.com < body.txt不一會就收到郵件了
點擊開啟,本文內容就是body.txt的內容
This is test mail
二、使用管道符直接發送郵件內容
如果不想通過檔案發送郵件內容也可以這麼發送
[root@vps478753 ~]# echo "This is test mail" | mail -s 'Test mail' admin@vpsrr.com
以上效果同檔案發送郵件內容一樣
如果提示mail: command not found
[root@vps478753 ~]# mail -s 'Test mail' admin@vpsrr.com < body.txt
-bash: mail: command not found
那麼就是沒有安裝mail命令,此時需要安裝mail命令
[root@vps478753 ~]# yum install mailx -y
然後再重新發送以下郵件就好了!
特別注意,如果安裝了防火牆,請添加如下規則:
iptables設定
# iptables -A INPUT -p tcp –dport 25 -j ACCEPT
# iptables -A INPUT -p udp –dport 25 -j ACCEPT