標籤:cccccc linux
原來使用Linux的sendmail 發郵件,後來做安全的時候把一sendmail服務給關了,導致一直不能發送郵件了。現在我就來配置使用外部SMTP發郵件,這樣就不用sendmail了。
原來系統內建有mailx程式,因為我是redhat5的系統所以不能直接用外部smtp發送郵件,只能升級mailx程式才可以用。所以首先下載mailx包。
mailx-12.4.tar.bz2
解壓該檔案並進行編譯安裝:
[[email protected] ~]# tar jxvf mailx-12.4.tar.bz2 mailx-12.4/mailx.specmailx-12.4/nail.rcmailx-12.4/v7.local.cmailx-12.4/rcv.hmailx-12.4/md5.hmailx-12.4/glob.hmailx-12.4/extern.hmailx-12.4/def.hmailx-12.4/version.cmailx-12.4/vars.c ... [[email protected] ~]# cd mailx-12.4 [[email protected] mailx-12.4]# make /bin/sh ./makeconfig checking if a hello world program can be built ... okay checking for <alloca.h> ... okay checking for alloca() ... okay ... [[email protected] mailx-12.4]# make install UCBINSTALL=/usr/bin/install test -d /usr/local/bin || mkdir -p /usr/local/bin /usr/bin/install -c mailx /usr/local/bin/mailx strip /usr/local/bin/mailx test -d /usr/local/share/man/man1 || mkdir -p /usr/local/share/man/man1 /usr/bin/install -c -m 644 mailx.1 /usr/local/share/man/man1/mailx.1 test -d /etc || mkdir -p /etc test -f /etc/nail.rc || \ /usr/bin/install -c -m 644 nail.rc /etc/nail.rc
[[email protected] mailx-12.4]# whereis mailx mailx: /bin/mailx /usr/local/bin/mailx /usr/share/man/man1p/mailx.1p.gz
在上面我用whereis 命令查看mailx命令的路徑,發現第一個還是原來mailx命令的路徑,所以直接執行mailx命令的時候還是使用原來的mailx,所以不能發送郵件。
所以我把新的mailx直接替換老的mailx,在這裡我先刪除原來的,再建一個軟連結。
[[email protected] bin]# cd /bin
[[email protected] bin]# rm -rf mailx [[email protected] bin]# ln -s /usr/local/bin/mailx mailx [[email protected] bin]# mailx -V 12.4 7/29/08 [[email protected] bin]# cd [[email protected] ~]# chkconfig --list |grep sendmail sendmail 0:off 1:off 2:off 3:on 4:off 5:on 6:off [[email protected] ~]# chkconfig --level 35 sendmail off
上面的步驟是安裝軟體的步驟,下面我們開始配置使能夠通過外部SMTP發送郵件。
[[email protected] ~]$ vi /etc/nail.rc---在檔案的最下面添加下面內容。set from=123456789@qq.comset smtp=smtp.qq.comset smtp-auth-user=123456789set smtp-auth-password=youpasswordset smtp-auth=login
然後通過命令發送郵件:
echo hello word | mailx -v -s " title" 123456789@qq.com
---在這裡郵件地址和上面設定的郵件地址是一樣的,這樣相當於自已給自已發送郵件.
LINUX下配置使用外部SMTP發郵件