linux本地常見郵件服務有:
Centos5:默認使用sendmail郵件服務,開啟方式/etc/init.d/sedmail start
Centos6:默認使用postfix郵件服務,開啟方式/etc/init.d/postfix start
搭建郵件服務:
在/etc/mail.rc最后一行輸入一下內容即可
set from=123456@163.com smtp=smtp.163.com smtp-auth-user=123456@163.com smtp-auth-password=123456 smtp-auth=login
自動發送腳本(參考):
[root@backup ~]# cat /server/scripts/check_and_del.sh
Path=/backup
if [ $(date +%w) -eq 0 ]
then
Time="week_$(date +%F_%w -d "-1day")"
else
Time=$(date +%F -d "-1day")
fi
LANG=en
find /backup -type f -name "*${Time}*.log"|xargs md5sum -c >>$Path/${Time}_result.log 2>&1
mail -s "$Time bak result" 13128687003@163.com <$Path/${Time}_result.log
find $Path/ -type f -mtime +180 ! -name "*week*_6*" |xargs rm -f
[root@backup ~]#
其中分別表示:
郵件地址:set from=123456@163.com
郵件服務器:smtp=smtp.163.com
用戶名: smtp-auth-user=123456@163.com
密碼:smtp-auth-password=123456
認證方式:smtp-auth=login
MAIL參數詳情:
-i :忽略tty的終斷訊號。
-l :強迫設置成互動模式。
-v :列出發送的地點、狀態、信息
-n :不讀入/etc/mail.rc設定的文檔
-s :郵件標題
-c :cc抄送郵件地址
-b :bcc密送郵件地址(需要啟用其中服務,sendmail服務、qmail服務、posfix服務)
系統收到郵件都會默認保存在/var/spool/mail/目錄下,在命令行中輸入mail就會默認顯示郵件默認(20條),此時命令提示
符為"&":
unread :標記為未讀郵件
h(headers) :顯示當前的郵件列表
l(list) :顯示當前支持的命令列表
?(help) :顯示多個查看郵件列表的命令參數及用法
d(delete) :刪除當前郵件,指針並下移。 d 1-100刪除1到100封郵件
f(from) :值顯示當前郵件的簡易信息。f mum指針移動到該郵件並顯示該郵件的簡易信息
z :顯示剛進行收件箱時的后面二十封郵件列表
郵件發送語法:1、echo "Hello World" |mail -s test 123456@163.com #直接輸送過去
2、mail -s test 123456@163.com #回車后在里邊輸入相應的內容然后crtrl+d發送
3、mail -s test 123456@163.com <file #發送文本中的內容