#发送多媒体附件的HTML格式正文的函数 (多媒体附件指非txt或者cvs格式的文件,例如excel的xls)
#$1: mail_from
#$2: mail_to
#$3: subject
#$4: content mimetype, such as "text/plain"
#$5: content
#$6: attach mimetype, such as "text/csv"
#$7: attach display name
#$8: attach file path
function SendMailMultiMediaAttach(){
local MSG_FILE="/tmp/mail.tmp"
echo "From: $1" > $MSG_FILE
echo "To: $2" >> $MSG_FILE
echo "Subject: $3" >> $MSG_FILE
echo "Mime-Version: 1.0" >> $MSG_FILE
echo 'Content-Type: multipart/mixed; boundary="GvXjxJ+pjyke8COw"' >> $MSG_FILE
echo "Content-Disposition: inline" >> $MSG_FILE
echo "" >> $MSG_FILE
echo "--GvXjxJ+pjyke8COw" >> $MSG_FILE
echo "Content-Type: $4" >> $MSG_FILE
echo "Content-Disposition: inline" >> $MSG_FILE
echo "" >> $MSG_FILE
echo "$5" >> $MSG_FILE
echo "" >> $MSG_FILE
echo "" >> $MSG_FILE
echo "--GvXjxJ+pjyke8COw" >> $MSG_FILE
echo "Content-Type: $6" >> $MSG_FILE
echo "Content-Transfer-Encoding: base64" >> $MSG_FILE
echo "Content-Disposition: attachement; filename=$7" >> $MSG_FILE
echo "" >> $MSG_FILE
echo "" >> $MSG_FILE
${BIN_PATH}/base64 -e $8 >> $MSG_FILE
cat $MSG_FILE | /usr/lib/sendmail -t
}
##! @TODO: 发送邮件
##! @AUTHOR: zhangxu
##! @VERSION: 1.0
##! @IN:
##! @OUT:
function sendMail()
{
echo "Sending $Subject mail from $From to $To"
from="from@123.com"
to="receiver@123.com"
subject="${Subject}"
content_type="text/html"
body=`cat $MAIL_HTML`
attach_type="application/vnd.ms-excel"
attach_name="${file_title}.xls"
attach_path="${TEMP_DIR}/${file_title}.xls"
SendMailMultiMediaAttach "$from" "$to" "$subject" "$content_type" "$body" "$attach_type" "$attach_name" "$attach_path"
echo "Send mail done."
}