首页 > 解决方案 > 只有 zip 在没有 HTML 部分的情况下被附加

问题描述

运行代码时,只有 zip 文件被附加,正文没有进入邮件(HTML 格式)如果代码有任何问题,请告知

    export to_email_id="abc@example.com"
    export MAILPART=`uuidgen` ## Generates Unique ID
    export MAILPART_BODY=`uuidgen` ## Generates Unique ID
    (
     echo "To: ${to_email_id}"
     echo "Subject: Subject here" ##Subject Here
     echo "MIME-Version: 1.0"
     echo "Content-Type: multipart/mixed; boundary=\"$MAILPART\""
     echo ""
     echo "--$MAILPART"         
     echo "Content-Type: multipart/alternative; boundary=\"$MAILPART_BODY\""
     echo ""
     echo "--$MAILPART_BODY"        
     echo "Content-Type: text/plain; charset=ISO-8859-1"
     echo "--$MAILPART_BODY"         
     echo "Content-Type: text/html; charset=ISO-8859-1"
     echo "Content-Disposition: inline"
     #filename - it should be attached in body 
     cat $filename          
     echo "--$MAILPART_BODY--"
     echo "--$MAILPART"         
     echo 'Content-Type: application/zip; name="'$(basename abc.zip)'"'
     echo "Content-Transfer-Encoding: base64"
     echo 'Content-Disposition: attachment; filename="'$(basename abc.zip)'"'
     echo ""         
     #abc is a zip name
     base64 $ATTACH $(basename abc.zip)
     echo "--$MAILPART--"
    ) | /usr/sbin/sendmail ${to_email_id}

标签: pythonshell

解决方案


对于正文部分,您能否尝试通过从下面的代码中替换来添加 html 标签和相关消息,

echo "Content-Type: text/html; charset=ISO-8859-1"
    echo "Content-Disposition: inline"
    echo " <html> " 
    echo " &lt;head> "
    echo " &lt;title> My email </title> "
    echo " &lt;/head>"
    echo " &lt;body>"
    echo " <h3>Here we have message-body</h3>"
    echo " </body>"
    echo " </html>"

推荐阅读