CentOS 是一個非常不錯的免費開源 Linux 系統,許多站點首選的平臺。然而 CentOS 預設不能傳送郵件,需要傳送郵件的童鞋可以安裝一個 sendmail 程式。
安裝 sendmail
執行:
1
[root@vps478753 ~]# yum -y install sendmail
程式會自動搜尋出 sendmail 安裝程式自動安裝。
安裝好 sendmail 以後執行以下命令啟動 sendmail
1
2
3
[root@vps478753 ~]# service sendmail start
Starting sendmail: [ OK ]
Starting sm-client: [ OK ]
啟動以後我們可以執行 mail 命令測試一下是否能傳送郵件
一、透過檔案內容傳送郵件
首先建立一個 body.txt
1
[root@vps478753 ~]# touch body.txt
寫入內容
1
[root@vps478753 ~]# echo ‘This is test mail’>body.txt
傳送郵件
1
[root@vps478753 ~]# mail -s ‘Test mail’ mail@lizhong.me < body.txt
不一會就收到郵件了
CentOS 安裝 mail 命令
點選開啟,正文內容就是 body.txt 的內容
This is test mail
二、使用管道符直接傳送郵件內容
如果不想透過檔案傳送郵件內容也可以這麼傳送
1
[root@vps478753 ~]# echo “This is test mail” | mail -s ‘Test mail’ mail@lizhong.me
以上效果同檔案傳送郵件內容一樣
如果提示 mail: command not found
1
2
[root@vps478753 ~]# mail -s ‘Test mail’ mail@lizhong.me < body.txt
-bash: mail: command not found
那麼就是沒有安裝 mail 命令,此時需要安裝 mail 命令
1
[root@vps478753 ~]# yum install mailx -y
然後再重新傳送以下郵件就好了!