在linux發送郵件須要兩個程序,分別是mutt和smstp。前者是mail的客戶端User,後者則是個smtp的簡易服務器,要發郵件二者不可或缺(固然也能夠經過其餘工具來發送) html
能夠經過如下方式查看 linux
[root@localhost ~]# rpm -qa|grep mutt mutt-1.4.2.2-3.0.2.el5 [root@localhost ~]#
smstp通常去/usr/local/bin或者/usr/bin等路徑下find一把 服務器
[root@localhost bin]# ll total 240 -rwxr-xr-x 1 root root 237267 Apr 10 03:36 msmtp
若是沒有安裝,則能夠用rpm -ivh mutt-1.4.2.2-3.0.2.el5.x86_64.rpm 來安裝 工具
smstp則能夠在http://download.chinaunix.net/download/0008000/7048.shtml下載。 spa
系統這邊已經安裝了mutt,只須要下載個smstp而後安裝便可。 .net
安裝的步驟是 unix
[root@localhost ~]# cd msmtp-1.4.5 code
[root@localhost ~]# ./configure htm
[root@localhost ~]# make get
[root@localhost ~]# make install
本次安裝開始下載的是msmtp-1.4.27版本,可是編譯的時候報了一個錯誤:
[root@localhost msmtp-1.4.27]# make make all-recursive make[1]: Entering directory `/root/msmtp-1.4.27' Making all in src make[2]: Entering directory `/root/msmtp-1.4.27/src' CCLD msmtp tls.o: In function `tls_init':/root/msmtp-1.4.27/src/tls.c:1100: undefined reference to `gnutls_priority_set_direct' collect2: ld returned 1 exit status make[2]: *** [msmtp] Error 1 make[2]: Leaving directory `/root/msmtp-1.4.27/src' make[1]: *** [all-recursive] Error 1 make[1]: Leaving directory `/root/msmtp-1.4.27' make: *** [all] Error 2
無解,後來聽朋友說換一個低版本的安裝,結果未報錯。選擇了版本msmtp-1.4.5
郵件的發送:
[root@localhost ~]# echo "Believing the god with U"|mutt -s "keyon's mail" xxxxx@163.com [root@localhost ~]#
去指定的郵箱查看,收到了主題爲keyon's mail,內容爲Believing the god with U的郵件。
若要增長附件,則加上-a參數,如當前目錄:
[root@localhost ~]# ll total 584 -rw------- 1 root root 1464 Apr 9 05:55 anaconda-ks.cfg drwxr-xr-x 2 root root 4096 Apr 9 22:44 Desktop -rw-r--r-- 1 root root 52465 Apr 9 05:55 install.log -rw-r--r-- 1 root root 4728 Apr 9 05:55 install.log.syslog drwxrwxrwx 6 1000 1000 4096 Apr 10 03:36 msmtp-1.4.5-rw-r--r-- 1 root root 489336 Apr 9 19:37 msmtp-1.4.5.tar.bz2
發送install.log.syslog文件出去。
[root@localhost ~]# echo "Believing the god with U"|mutt -a install.log.syslog -s "keyon's mail" lqchenzjut@163.com [root@localhost ~]#
檢查,OK。
若要發送多人,則能夠在各個收件人郵箱之間以逗號區分便可。