Unix的sendmail的 - HTML嵌入图像不工作 [英] Unix sendmail - html embed image not working

查看:239
本文介绍了Unix的sendmail的 - HTML嵌入图像不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

随着SO.com以前的帖子我已经尝试建立我的脚本来发送邮件到我的Outlook帐户的电子邮件正文中嵌入图像。但是HTML内容越来越显示而显示图像的HTML。请帮助。

With the prior posts in SO.com I have tried building my script to send email to my Outlook account with the Image inline in the email body. But the html contents are getting displayed in the html rather displaying the image. Please help.

下面是我的代码片段

{
echo "TO: XXX@YYY.com"
echo "FROM: TEST_IMAGE@YYY.com>"
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

电子邮件我收到包含以下,而显示图像,

Email I received contains the below rather displaying the image,

--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--

能否请你帮助我我失去了什么。

Can you please assist me in what am i missing

推荐答案

您使用的方式回声打印邮件标题它吃所有的双引号 - 你需要逃脱他们用一个反斜杠( \\),以使其工作。

The way you use echo to print the message headers it eats all double quotes - you need to escape them with a backslash (\") to make it work.

另外,你的边界是错误的。如果定义边界= - XYZ ,那么每个消息部分需要与开始---- XYZ (您需要的添加的两个破折号),否则你的边界应该只有 XYZ 。和MIME部分的标题必须从机构由一个空行分隔。

Also, your boundary is wrong. If you define boundary=--XYZ, then each message part needs to start with ----XYZ (you need to add two dashes), otherwise your boundary should be only XYZ. And the headers of the mime parts must be separated from the bodies by an empty line.

如果你真的需要生成一个shell脚本邮件,那么我的建议将摆脱所有的回声,并使用定界符来代替:

If you really need to generate a mail from a shell script, then my advise would be to get rid of all the echo and use a heredoc instead:

sendmail -t <<EOT
TO: XXX@YYY.com
FROM: <TEST_IMAGE@YYY.com>
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

这篇关于Unix的sendmail的 - HTML嵌入图像不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆