python - 只有 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}
解决方案
对于正文部分,您能否尝试通过从下面的代码中替换来添加 html 标签和相关消息,
echo "Content-Type: text/html; charset=ISO-8859-1"
echo "Content-Disposition: inline"
echo " <html> "
echo " <head> "
echo " <title> My email </title> "
echo " </head>"
echo " <body>"
echo " <h3>Here we have message-body</h3>"
echo " </body>"
echo " </html>"
推荐阅读
- java - sendKeys 不适用于带有 SLIDER 的输入文本框,但它适用于 CLEAR 输入字段(selenium java)
- session - 烧瓶会话不保存价值/跨请求持续存在
- react-native - 在嵌套导航器上反应导航重置
- svg - 有没有办法从一个 svg 中保存多个 svg?
- apache-spark - 避免广播嵌套循环连接
- html - 如何修复搜索图标更改为下拉菜单项的值?
- python - Python tkinter--ProgrammingError: 1064 (42000)
- macos - Kubernetes 无法删除 mac 上的图像/docker 无法删除图像
- python-3.x - OSError: [Errno 24] 多线程 pwntools 时
- python - How can I deploy a flask app on Lightsail with crash protection?