javascript 从 HTML 页面发送邮件,正文中有图像
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26373737/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Sending mail from HTML page with image in the body
提问by Muthu
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.
当按下按钮时,我必须调出 Outlook 撰写框,并且正文应包含特定 DIV 的图像。我正在使用 html2canvas 来捕获图像,使用 mailto 我可以触发 Outlook 撰写邮件实例,但似乎 mailto 用于简单的纯文本并且不支持在邮箱中嵌入图像。
Any ideas, thoughts?
任何想法,想法?
回答by sampathsris
TL;DR:You cannot do this.
TL;DR:你不能这样做。
You can use Data URI Schemeto 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
).
您可以使用数据 URI 方案在 HTML 中嵌入图像。如果电子邮件 MIME 类型是text/html
您可以执行相同操作。您必须使用合适的编码(例如:)对图像进行编码base64
。
For example:
例如:
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUA
AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO
9TXL0Y4OHwAAAABJRU5ErkJggg==" alt="Red dot" />
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.
但是,您不能body
在mailto:
URL部分中包含 HTML。根据RFC 2368,body
参数的内容被视为纯文本。
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.
特殊的 hname "body" 表示关联的 hvalue 是消息的正文。“body” hname 应包含消息的第一个文本/纯正文部分的内容。mailto URL 主要用于生成实际上是自动处理内容的短文本消息(例如邮件列表的“订阅”消息),而不是一般的 MIME 正文。
So if you use a URL encoded HTML as the body
parameter of a mailto:
URL, here is what happens:
因此,如果您使用 URL 编码的 HTML 作为 URL 的body
参数mailto:
,则会发生以下情况:
<a href="mailto:[email protected]?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>
Result:
结果: