Sending mail from HTML page with image in the body
Solution 1:
TL;DR: You cannot do this.
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
).
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.
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.
So if you use a URL encoded HTML as the body
parameter of a mailto:
URL, here is what happens:
<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: