在 SO.com 之前的帖子中,我尝试构建脚本来将电子邮件发送到我的 Outlook 帐户,并将图像内嵌在电子邮件正文中。但 html 内容显示在 html 中,而不是显示图像。请帮忙。
这是我的片段
{
echo "TO: [email protected] /cdn-cgi/l/email-protection"
echo "FROM: [email protected] /cdn-cgi/l/email-protection>"
echo "SUBJECT: Embed image test"
echo "MIME-Version: 1.0"
echo "Content-Type: multipart/related;boundary="--XYZ""
echo "--XYZ"
echo "Content-Type: text/html; charset=ISO-8859-15"
echo "Content-Transfer-Encoding: 7bit"
echo "<html>"
echo "<head>"
echo "<meta http-equiv="content-type" content="text/html; charset=ISO-8859-15">"
echo "</head>"
echo "<body bgcolor="#ffffff" text="#000000">"
echo "<img src="cid:part1.06090408.01060107" alt="">"
echo "</body>"
echo "</html>"
echo "--XYZ"
echo "Content-Type: image/jpeg;name="sathy.jpg""
echo "Content-Transfer-Encoding: base64"
echo "Content-ID: <part1.06090408.01060107>"
echo "Content-Disposition: inline; filename="sathy.jpg""
echo $(base64 sathy.jpg)
echo "' />"
echo "--XYZ--"
}| /usr/lib/sendmail -t
我收到的电子邮件包含以下内容而不是显示图像,
--XYZ
Content-Type: text/html; charset=ISO-8859-15
Content-Transfer-Encoding: 7bit
<html>
<head>
<meta http-equiv=content-type content=text/html
</head>
<body bgcolor=#ffffff text=#000000>
<img src=cid:part1.06090408.01060107 alt=>
</body>
</html>
--XYZ
Content-Type: image/jpeg;name=sathy.jpg
Content-Transfer-Encoding: base64
Content-ID: <part1.06090408.01060107>
Content-Disposition: inline; filename=sathy.jpg
/9j/4QAYRXhpZgAASUkqAAgAAAAAAAAAAAAAAP/sABFEdWNreQABAAQAAAAoAAD/4QNxaHR0cDov
....base64 values.....
/>
--XYZ--
----XYZ--
你能帮我解决我缺少的东西吗
你使用的方式echo
要打印消息标题,它会吃掉所有双引号 - 您需要用反斜杠转义它们(\"
)使其发挥作用。
另外,你的边界是错误的。如果你定义boundary=--XYZ
,那么每个消息部分需要以----XYZ
(你需要add两个破折号),否则你的边界应该只是XYZ
。哑剧部分的标题必须与正文之间用空行分隔。
如果您确实需要从 shell 脚本生成邮件,那么我的建议是摆脱所有 echo 并使用 Heredoc 代替:
sendmail -t <<EOT
TO: [email protected] /cdn-cgi/l/email-protection
FROM: <[email protected] /cdn-cgi/l/email-protection>
SUBJECT: Embed image test
MIME-Version: 1.0
Content-Type: multipart/related;boundary="XYZ"
--XYZ
Content-Type: text/html; charset=ISO-8859-15
Content-Transfer-Encoding: 7bit
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-15">
</head>
<body bgcolor="#ffffff" text="#000000">
<img src="cid:part1.06090408.01060107" alt="">
</body>
</html>
--XYZ
Content-Type: image/jpeg;name="sathy.jpg"
Content-Transfer-Encoding: base64
Content-ID: <part1.06090408.01060107>
Content-Disposition: inline; filename="sathy.jpg"
$(base64 sathy.jpg)
--XYZ--
EOT
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)