【Linux】【sendmail】利用sendmail发送带附件的邮件及解决邮件中文标题乱码

#收件邮箱列表
TO_LIST=$1
#邮件标题
MAIL_TITLE=$2
#附件地址
LOG_PATH=$3

fromAdd="=?UTF-8?B?`echo $MAIL_TITLE | base64`?="   
tolist="$TO_LIST"
cclist=""
subject="=?UTF-8?B?`echo $MAIL_TITLE | base64`?="
attach="$LOG_PATH"
data=`cat $attach`
(
echo "From: $fromAdd"
echo "To: $tolist"
echo "Cc: $cclist"
echo "Subject: $subject"
echo "MIME-Version: 1.0"
echo 'Content-Type: multipart/mixed; boundary="GvXjxJ+pjyke8COw"'
#echo "Content-Disposition: inline"
echo
echo "--GvXjxJ+pjyke8COw"
echo "Content-Type: text/html; charset=US-ASCII"
echo "Content-Disposition: inline"
echo
echo "<h1>Please check the attachment log.</h1>"
echo
echo "--GvXjxJ+pjyke8COw"
echo "Content-Type: text/plain; charset=US-ASCII;"
echo "Content-Disposition: attachment;filename="build.log""
echo 
echo "$data"
echo
echo "--GvXjxJ+pjyke8COw"
) | /usr/lib/sendmail -t

 在中文的左边加    =?UTF-8?B?`echo  ,右边加  | base64`?=

posted @ 2019-09-27 10:42    阅读(1220)  评论(0编辑  收藏  举报