shell的傳送郵件

2021-08-29 22:10:42 字數 711 閱讀 8240

shell中的傳送郵件,可以做報警用

傳送郵件的配置檔案(mail.conf):

[email protected]

[email protected]

傳送郵件的主程式:

#傳送郵件shell指令碼,必須傳入兩個引數,第乙個為標題,第二個為郵件內容,

#必須要有mail.conf檔案,裡面是郵件列表,一行乙個郵件

mailfile="mail.conf"

if test $# -gt 1 && test -e $mailfile; then

subject=$1

content=$2

#組裝郵件的傳送位址

mailto=$(cat $mailfile |sed -n '1'p);

maillist=$(cat $mailfile |sed -n '2,$'p);

if [ -n "$maillist" ] ; then

for email in $maillist ;do

mailto=$mailto" -c "$email

done

#echo $mailto

fi#傳送郵件

echo $content|mail -s $subject $mailto

fi

Shell 傳送郵件

1.確認mail安裝 rpm qa grep mail 如未安裝 yum install mailx ll usr bin mail 2.配置郵箱設定項 引用外部smtp伺服器 etc mail.rc set from telent qq.com set smtp smtp.qq.com set s...

linux傳送郵件的shell指令碼

bin sh function echo help email to toaddress.emailname test mail messagebody tmp.tmp from from fromaddress.fromname mailreport subject mail report unt...

傳送統計郵件shell指令碼

user aaa port 3306 password aaa database aaa today date y m d yesterday date y m d date 1 day host aaa send mail name lipingchang pystandard.com weiji...