从 HTML 页面发送邮件,正文中有图像 [英] Sending mail from HTML page with image in the body

查看:33
本文介绍了从 HTML 页面发送邮件,正文中有图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须在按下按钮时调出 Outlook 撰写框,并且正文应包含特定 DIV 的图像.我正在使用 html2canvas 来捕获图像,使用 mailto 我可以触发 Outlook 撰写邮件实例,但似乎 mailto 用于简单的纯文本,不支持在邮箱中嵌入图像.

I have to bring up the outlook compose box when a button is pressed and the body should contain the image of a specific DIV. I am using html2canvas to capture the image, with mailto i am able to fire a outlook compose mail instance but seems mailto is for simple plain text and is not supporting to embed image in the mailbox.

有什么想法、想法吗?

推荐答案

TL;DR:你不能这样做.

您可以使用 Data URI Scheme 在 HTML 中嵌入图像.如果电子邮件 MIME 类型为 text/html,您也可以这样做.您必须使用合适的编码(例如:base64)对图像进行编码.

You can use Data URI Scheme to embed an image in HTML. If an emails MIME type is text/html you can do the same. You will have to encode your image with a suitable encoding (e.g.: base64).

例如:

<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUA
AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO
9TXL0Y4OHwAAAABJRU5ErkJggg==" alt="Red dot" />

但是您不能在 body<中包含 HTML/code> mailto: URL 的一部分.根据 RFC 2368<,body 参数的内容被视为纯文本/a>.

However, you cannot include HTML in the body part of the mailto: URL. The content of the body parameter is considered plain-text as per RFC 2368.

特殊的 hname "body" 表示关联的 hvalue 是消息的正文.body" hname 应包含消息的第一个文本/纯正文部分的内容.mailto URL 主要用于生成实际上是自动处理内容的短文本消息(例如邮件列表的订阅"消息),而不是一般的 MIME 正文.

The special hname "body" indicates that the associated hvalue is the body of the message. The "body" hname should contain the content for the first text/plain body part of the message. The mailto URL is primarily intended for generation of short text messages that are actually the content of automatic processing (such as "subscribe" messages for mailing lists), not general MIME bodies.

因此,如果您使用 URL 编码的 HTML 作为 mailto: URL 的 body 参数,则会发生以下情况:

So if you use a URL encoded HTML as the body parameter of a mailto: URL, here is what happens:

<a href="mailto:email@domain.com?subject=Check%20this%20out!&body=%3Cp%3EHi%3C%2Fp%3E%3Cimg%20src%3D%22data%3Aimage%2Fpng%3Bbase64%2CiVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4%2F%2F8%2Fw38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg%3D%3D%22%20alt%3D%22Red%20dot%22%20%2F%3E">Write Email!</a>

结果:

这篇关于从 HTML 页面发送邮件,正文中有图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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