在邮件中嵌入 HTML 图片?

Embedding an HTML Image in a mail?

我有一个要求,我必须在邮件中嵌入图像,当用户点击图像时,它会将他重定向到新站点。我真的不知道我应该在图像 src 中提供什么。是不是只能通过html。需要指导。谢谢

这是我的试用版HTML

<html>
<head>
</head>
<title>trial</title>
<body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<center>
<table width="900" border="0" cellpadding="0" cellspacing="0">
    <tr>
        <td><a href="siteAddr">
<img style="float:left;" src="myImage.jpg" width="900" height="356" alt="my image" border="0" /></a></td>
    </tr>

</table>
</center>
</body>
</html>

用绝对 url 替换 img src 就大功告成了 - 如果 reader 在阅读时连接到互联网,否则你的图片将不会被加载。

INLINE EMBEDDING (Base64 Encoding)

Inline embedding is much more simple, mostly because you don’t have to completely roll your own emails and dig around in MIME to use it.

Embedding an image in an email first requires that you have a version of said image as a base64 encoded string. There are lots of web based tools to do this, such as ImageToBase64Converter by Web Coder Tools.

Once your image is encoded, jump into your template, or whatever HTML you’re sending out, and embed it using a standard HTML image tag:

<img alt="My Image" src="data:image/jpeg;base64,/9j/4S/+RXhpZgAATU0AKgAAAAgACAESAAMAENkDZ5u8/61a+X...more encoding" />

Then you’re done! Send away.

Pros

Much simpler to achieve Much faster to do Requires much less deep dive into MIME and application code

Cons

Can really increase size of emails especially if you use more than one image Most likely blocked by default in many webmail services Blocked completely in Outlook

参考文献:"Sendgrid Blog - Embedding Images"


外部参考 LINK

link 图片来自其他网站。

<img src="http://this-is-a-url.com/this-is-an-image.jpg" />